Each project below is tailored to a specific algorithm and scientific question from Chapter 03, with concrete inputs, verifiable numerical outputs, boundary cases, and links to the related lab and pioneer.
Project 1 of 3 · v1-c03-p01Foundational · ~30 min
EAN-13 95-Module Barcode Encoder
Lab activity: A · Build a barcode · Related code: block-01.js, block-04.js · Pioneer: View profile
Real-World Problem: Retail scanners must read 13-digit product IDs reliably from printed packaging at any checkout speed.
Scientific Question: How do 7-module L, G, and R encodings pack 13 decimal digits into 95 black-and-white modules?
Objective: Encode any 12-digit prefix into its 13th check digit and full 95-bit EAN-13 bar pattern.
Hypothesis to Test: Every EAN-13 digit occupies 7 modules containing exactly two black bars and two white spaces.
Step-by-Step Implementation
Compute the 13th check digit using alternating weights 1 and 3 modulo 10.
Look up the 6-character L/G parity pattern determined by the leading digit (4 -> LGLGGL).
Emit Left Guard (101), 6 left digits (42 modules), Center Guard (01010), 6 right R-digits (42 modules), Right Guard (101).
Expected Output: Check digit = 1; full code = 4006381333931; 95-bit pattern starting 101 and ending 101.
Test Cases: 400638133393 -> check 1; 978030640615 -> check 7; total length always 95 bits.
Boundary Condition: Leading digit 0 uses LLLLLL (backward-compatible with 12-digit UPC-A).
Common Mistake to Avoid: Using 1-based vs. 0-based index backwards when applying weights 1 and 3.
Interpreting Results: Encoding the first digit in the parity of the next six digits added global country prefixes without widening existing barcodes.
Show Hint, Extension Challenge & Reflection
Hint: Review the worked example and equation in Chapter 03 before testing the boundary case: Leading digit 0 uses LLLLLL (backward-compatible with 12-digit UPC-A).
Extension Challenge: Verify that every L-code has an odd number of 1s while every G-code and R-code has an even number of 1s.
Reflection Question: How did George Laurer's rectangular UPC/EAN geometry balance printing tolerances with laser optics?
Lab activity: B · Become the scanner · Related code: block-02.js, block-05.js · Pioneer: View profile
Real-World Problem: Cashiers swipe items left-to-right, right-to-left, and upside-down without aligning them.
Scientific Question: How does a scanner know immediately whether it scanned a barcode forward or backward?
Objective: Decode a 95-module bitstring in either orientation by inspecting guard bars and L/G/R parity signatures.
Hypothesis to Test: Because R-codes always start with a 1 (dark bar) and L/G-codes always start with a 0 (space), reversing a scan produces invalid L/G patterns on the left.
Step-by-Step Implementation
Verify start (101), center (01010), and end (101) guard bars at fixed module offsets.
Attempt decoding the left six 7-bit chunks against L/G tables and right six against R table.
If forward decoding fails, reverse the entire 95-bit array and decode again.
Recover the leading digit from the 6-bit L/G sequence and verify the 13th check digit.
Concrete Input: Reversed 95-bit string of 4006381333931.
Boundary Condition: Missing quiet zones around the barcode cause real optical scanners to miss the start guard.
Common Mistake to Avoid: Reversing each digit individually instead of reversing the full 95-module scan.
Interpreting Results: Asymmetric parity sets make orientation self-describing without wasting extra bars.
Show Hint, Extension Challenge & Reflection
Hint: Review the worked example and equation in Chapter 03 before testing the boundary case: Missing quiet zones around the barcode cause real optical scanners to miss the start guard.
Extension Challenge: Simulate a 1-module smudge and show how the scanner detects an invalid 7-module codeword.
Reflection Question: Why do barcodes fail cleanly (refuse to scan) instead of ringing up a wrong product?
Common Mistake to Avoid: Treating a valid check digit as proof that the product exists in inventory.
Interpreting Results: Barcodes are foreign keys into a database, not self-contained price tags.
Show Hint, Extension Challenge & Reflection
Hint: Review the worked example and equation in Chapter 03 before testing the boundary case: Empty cart outputs $0.00; integer cents prevent floating-point rounding drift.
Extension Challenge: Add a quantity counter and 5% fictional discount rule while keeping all math in integer cents.
Reflection Question: How does separating identifiers from data make global supply chains scalable?