Chapter 02 of 22 Part I: Digital Foundations

The Secret Mathematics of Everyday Numbers

Each project below is tailored to a specific algorithm and scientific question from Chapter 02, with concrete inputs, verifiable numerical outputs, boundary cases, and links to the related lab and pioneer.

Project 1 of 3 · v1-c02-p01 Foundational · ~25 min

Luhn Algorithm Step-by-Step Verifier

Lab activity: A. Luhn number detective · Related code: block-01.js · Pioneer: View profile

Real-World Problem: Checkout forms and banking terminals need instant offline checks for mistyped account numbers.
Scientific Question: How does doubling every second digit and subtracting 9 above 9 detect both single-digit and most transposition errors?

Objective: Implement the Luhn check-digit transformation and test single-digit typos plus adjacent digit swaps.

Hypothesis to Test: Luhn detects 100% of single-digit substitutions and almost all adjacent swaps except 09 <-> 90.

Step-by-Step Implementation

  1. Parse digits from right to left, doubling every second digit (positions 2, 4, 6... from right).
  2. Whenever a doubled digit exceeds 9, subtract 9 (e.g., 2×7 = 14 -> 14 − 9 = 5).
  3. Sum all transformed digits and check whether total mod 10 === 0.
  4. Test swapping adjacent digits 27 <-> 72 (caught) vs. 09 <-> 90 (missed).
Concrete Input: Fictional test number: 79927398713 (valid) vs. 79927398714 (invalid).
Expected Output: 79927398713 -> transformed sum = 70 (70 mod 10 = 0, VALID); 79927398714 -> sum = 71 (INVALID).

Test Cases: 79927398713 -> true; 79927398714 -> false; 1090 and 1900 -> identical Luhn residue.

Boundary Condition: Strings with non-digit separators (spaces/hyphens) must be sanitized; empty or 1-digit strings are invalid.

Common Mistake to Avoid: Doubling from the left instead of from the right, which fails for odd-length numbers.

Interpreting Results: Luhn is a non-linear digit transformation (not a plain weighted sum) optimized for human typing errors, not security.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 02 before testing the boundary case: Strings with non-digit separators (spaces/hyphens) must be sanitized; empty or 1-digit strings are invalid.

Extension Challenge: Write a function that computes the missing check digit for any fictional 15-digit prefix.

Reflection Question: Why does passing Luhn never prove a payment card is authentic or has funds?

Project 2 of 3 · v1-c02-p02 Foundational · ~25 min

ISBN-10 Modulo-11 Weighted Validator

Lab activity: B. Weighted-sum checker · Related code: block-02.js · Pioneer: View profile

Real-World Problem: Book publishers needed a code that catches every adjacent digit swap without any 09/90 blind spot.
Scientific Question: Why does using a prime modulus (11) with weights 10 down to 1 eliminate transposition blind spots?

Objective: Compute and validate ISBN-10 numbers including the special check symbol X representing 10.

Hypothesis to Test: Because 11 is prime, swapping any two distinct digits changes the weighted sum by a nonzero multiple modulo 11.

Step-by-Step Implementation

  1. Strip hyphens and validate 9 digits plus a 10th character in 0–9 or X.
  2. Multiply position i (1 to 10) by weight (11 − i), treating X as 10.
  3. Check whether the weighted sum modulo 11 equals 0.
  4. Swap every adjacent pair in 0306406152 and verify 100% detection.
Concrete Input: ISBN-10: 0-306-40615-2 and 0-8044-2957-X.
Expected Output: 0306406152 -> weighted sum = 132 (132 mod 11 = 0, VALID); 080442957X -> VALID (check digit = 10 -> X).

Test Cases: 0306406152 -> true; 0306406512 (swapped 1,5) -> false; 080442957X -> true.

Boundary Condition: Letter X is valid ONLY in the 10th position, never in positions 1–9.

Common Mistake to Avoid: Forgetting to accept lowercase "x" or allowing X in data positions.

Interpreting Results: Prime moduli give stronger error-detection algebra at the cost of needing an 11th symbol (X).

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 02 before testing the boundary case: Letter X is valid ONLY in the 10th position, never in positions 1–9.

Extension Challenge: Compare ISBN-10 (mod 11) with ISBN-13 (mod 10, weights 1 and 3) on all 90 distinct adjacent digit pairs.

Reflection Question: Why did the publishing industry move to ISBN-13 even though mod 10 misses some transpositions where |a − b| = 5?

Project 3 of 3 · v1-c02-p03 Intermediate · ~30 min

Custom Lab-Label Checksum Designer

Lab activity: C. Invent a lab label · Related code: block-03.js · Pioneer: View profile

Real-World Problem: A school science lab wants short 6-character equipment tags that detect both typos and swaps.
Scientific Question: What happens when a weight shares a common factor with the modulus (such as weight 2 or 5 modulo 10)?

Objective: Design a custom check-digit scheme, test all single-digit and transposition errors, and measure its blind spots.

Hypothesis to Test: Weights coprime to the modulus catch 100% of single-digit errors, whereas weights sharing a factor miss pairs.

Step-by-Step Implementation

  1. Choose a modulus (10 or 11) and 5 position weights in Activity C.
  2. Generate the 6th check digit so the weighted sum equals 0 modulo m.
  3. Exhaustively mutate each digit (5 × 9 = 45 single-digit tests) and count undetected errors.
  4. Exhaustively swap adjacent digits and log any missed pairs.
Concrete Input: 5-digit base ID 48219 with weights [1, 3, 7, 9, 1] mod 10 vs. [2, 4, 2, 4, 2] mod 10.
Expected Output: Coprime weights -> 100% single-digit detection; even weights -> misses changes of ±5.

Test Cases: Mod 10 with weight 2: changing 1 to 6 changes sum by 2×5 = 10 ≡ 0 (missed).

Boundary Condition: Adjacent equal weights (e.g., [3, 3]) miss ALL swaps between those two positions.

Common Mistake to Avoid: Using identical weights in adjacent positions.

Interpreting Results: Number theory (greatest common divisor gcd(w, m) = 1) directly determines engineering reliability.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 02 before testing the boundary case: Adjacent equal weights (e.g., [3, 3]) miss ALL swaps between those two positions.

Extension Challenge: Prove why gcd(w_i − w_{i+1}, m) = 1 guarantees 100% adjacent transposition detection.

Reflection Question: Where else in daily life (IBAN, routing numbers, student IDs) do check digits silently prevent costly mistakes?