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-p01Foundational · ~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
Parse digits from right to left, doubling every second digit (positions 2, 4, 6... from right).
Sum all transformed digits and check whether total mod 10 === 0.
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?
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?
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
Choose a modulus (10 or 11) and 5 position weights in Activity C.
Generate the 6th check digit so the weighted sum equals 0 modulo m.
Exhaustively mutate each digit (5 × 9 = 45 single-digit tests) and count undetected errors.
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.