FAILURE MAP
← Case archive

FA-72801 / Check-digit algorithms / Open access

Missing-digit recovery measures the unknown from the left · case 01

Recovery succeeds only when the number length makes left and right parity agree.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The unknown index k is taken from the left (s.index("?")), but Luhn parity counts from the right.

VERIFIED REPAIR

Compute k = len(s) - 1 - s.index("?").

Unsuccessful approach: Using len(s) - s.index("?") is off by one and flips the parity.

Case contract

Recover the single unknown digit (marked "?") in a Luhn-protected number: input must be at least two characters, ASCII digits and exactly one "?" (else None). Return the digit 0-9 that makes the whole number Luhn-valid; when the unknown sits in a doubled position the needed contribution must be mapped back through the doubling map.

Why this case matters

Customer-service tools reconstruct a smudged or misheard digit of an account number.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(s):
    if len(s) < 2 or s.count('?') != 1 or not s.isascii() or not all(c.isdigit() or c == '?' for c in s):
        return None
    k = s.index('?')
    total = 0
    for i, ch in enumerate(reversed(s)):
        if ch == '?':
            continue
        d = int(ch)
        if i % 2 == 1:
            d = d * 2 - 9 if d > 4 else d * 2
        total += d
    need = (10 - total % 10) % 10
    if k % 2 == 1:
        need = need // 2 if need % 2 == 0 else (need + 9) // 2
    return need
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression ["766?9906"]', ['766?9906'], 2], ['regression ["?929942967"]', ['?929942967'], 1], ['partial-repair ["7?850"]', ['7?850'], 2], ['control ["475646793469?297"]', ['475646793469?297'], 0], ['control ["405529124?1"]', ['405529124?1'], 9], ['control ["??"]', ['??'], None], ['control ["1"]', ['1'], None], ['control ["12a?"]', ['12a?'], None]], [['regression ["3077312?96877436"]', ['3077312?96877436'], 1], ['regression ["3102377592002?64"]', ['3102377592002?64'], 6], ['partial-repair ["1519774?1518"]', ['1519774?1518'], 5], ['partial-repair ["049785409775?16"]', ['049785409775?16'], 5], ['control ["?"]', ['?'], None], ['control ["?0"]', ['?0'], 0], ['control ["0?"]', ['0?'], 0], ['control ["475646793469?297"]', ['475646793469?297'], 0]], [['regression ["1507302?557627"]', ['1507302?557627'], 8], ['regression ["4111111111?11111"]', ['4111111111?11111'], 1], ['partial-repair ["6?0334555"]', ['6?0334555'], 3], ['partial-repair ["033?959838019"]', ['033?959838019'], 2], ['control ["??"]', ['??'], None], ['control ["1"]', ['1'], None], ['control ["12a?"]', ['12a?'], None], ['control ["?"]', ['?'], None]], [['regression ["?929942967"]', ['?929942967'], 1], ['regression ["1519774?1518"]', ['1519774?1518'], 5], ['partial-repair ["08?8016"]', ['08?8016'], 8], ['partial-repair ["2288?7"]', ['2288?7'], 1], ['control ["0?"]', ['0?'], 0], ['control ["475646793469?297"]', ['475646793469?297'], 0], ['control ["405529124?1"]', ['405529124?1'], 9], ['control ["??"]', ['??'], None]], [['regression ["3102377592002?64"]', ['3102377592002?64'], 6], ['regression ["2288?7"]', ['2288?7'], 1], ['partial-repair ["7992739871?"]', ['7992739871?'], 3], ['partial-repair ["?9927398713"]', ['?9927398713'], 7], ['control ["12a?"]', ['12a?'], None], ['control ["?"]', ['?'], None], ['control ["?0"]', ['?0'], 0], ['control ["0?"]', ['0?'], 0]]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
regression ["766?9906"]12Failed
regression ["?929942967"]21Failed
partial-repair ["7?850"]22Passed
control ["475646793469?297"]00Passed
control ["405529124?1"]99Passed
control ["??"]NoneNonePassed
control ["1"]NoneNonePassed
control ["12a?"]NoneNonePassed

SHA-256 / ac6706ce557ecaff89753cae29d44e4834325c712a92091dcfb4ca4005c28745

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(s):
    if len(s) < 2 or s.count('?') != 1 or not s.isascii() or not all(c.isdigit() or c == '?' for c in s):
        return None
    k = len(s) - s.index('?')
    total = 0
    for i, ch in enumerate(reversed(s)):
        if ch == '?':
            continue
        d = int(ch)
        if i % 2 == 1:
            d = d * 2 - 9 if d > 4 else d * 2
        total += d
    need = (10 - total % 10) % 10
    if k % 2 == 1:
        need = need // 2 if need % 2 == 0 else (need + 9) // 2
    return need
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression ["766?9906"]', ['766?9906'], 2], ['regression ["?929942967"]', ['?929942967'], 1], ['partial-repair ["7?850"]', ['7?850'], 2], ['control ["475646793469?297"]', ['475646793469?297'], 0], ['control ["405529124?1"]', ['405529124?1'], 9], ['control ["??"]', ['??'], None], ['control ["1"]', ['1'], None], ['control ["12a?"]', ['12a?'], None]], [['regression ["3077312?96877436"]', ['3077312?96877436'], 1], ['regression ["3102377592002?64"]', ['3102377592002?64'], 6], ['partial-repair ["1519774?1518"]', ['1519774?1518'], 5], ['partial-repair ["049785409775?16"]', ['049785409775?16'], 5], ['control ["?"]', ['?'], None], ['control ["?0"]', ['?0'], 0], ['control ["0?"]', ['0?'], 0], ['control ["475646793469?297"]', ['475646793469?297'], 0]], [['regression ["1507302?557627"]', ['1507302?557627'], 8], ['regression ["4111111111?11111"]', ['4111111111?11111'], 1], ['partial-repair ["6?0334555"]', ['6?0334555'], 3], ['partial-repair ["033?959838019"]', ['033?959838019'], 2], ['control ["??"]', ['??'], None], ['control ["1"]', ['1'], None], ['control ["12a?"]', ['12a?'], None], ['control ["?"]', ['?'], None]], [['regression ["?929942967"]', ['?929942967'], 1], ['regression ["1519774?1518"]', ['1519774?1518'], 5], ['partial-repair ["08?8016"]', ['08?8016'], 8], ['partial-repair ["2288?7"]', ['2288?7'], 1], ['control ["0?"]', ['0?'], 0], ['control ["475646793469?297"]', ['475646793469?297'], 0], ['control ["405529124?1"]', ['405529124?1'], 9], ['control ["??"]', ['??'], None]], [['regression ["3102377592002?64"]', ['3102377592002?64'], 6], ['regression ["2288?7"]', ['2288?7'], 1], ['partial-repair ["7992739871?"]', ['7992739871?'], 3], ['partial-repair ["?9927398713"]', ['?9927398713'], 7], ['control ["12a?"]', ['12a?'], None], ['control ["?"]', ['?'], None], ['control ["?0"]', ['?0'], 0], ['control ["0?"]', ['0?'], 0]]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
regression ["766?9906"]12Failed
regression ["?929942967"]21Failed
partial-repair ["7?850"]42Failed
control ["475646793469?297"]00Passed
control ["405529124?1"]99Passed
control ["??"]NoneNonePassed
control ["1"]NoneNonePassed
control ["12a?"]NoneNonePassed

SHA-256 / 8c27f52d524c595be8b1c3e16568fdf57d99994a7a4508088f3252a97f12cd4f

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(s):
    if len(s) < 2 or s.count('?') != 1 or not s.isascii() or not all(c.isdigit() or c == '?' for c in s):
        return None
    k = len(s) - 1 - s.index('?')
    total = 0
    for i, ch in enumerate(reversed(s)):
        if ch == '?':
            continue
        d = int(ch)
        if i % 2 == 1:
            d = d * 2 - 9 if d > 4 else d * 2
        total += d
    need = (10 - total % 10) % 10
    if k % 2 == 1:
        need = need // 2 if need % 2 == 0 else (need + 9) // 2
    return need
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression ["766?9906"]', ['766?9906'], 2], ['regression ["?929942967"]', ['?929942967'], 1], ['partial-repair ["7?850"]', ['7?850'], 2], ['control ["475646793469?297"]', ['475646793469?297'], 0], ['control ["405529124?1"]', ['405529124?1'], 9], ['control ["??"]', ['??'], None], ['control ["1"]', ['1'], None], ['control ["12a?"]', ['12a?'], None]], [['regression ["3077312?96877436"]', ['3077312?96877436'], 1], ['regression ["3102377592002?64"]', ['3102377592002?64'], 6], ['partial-repair ["1519774?1518"]', ['1519774?1518'], 5], ['partial-repair ["049785409775?16"]', ['049785409775?16'], 5], ['control ["?"]', ['?'], None], ['control ["?0"]', ['?0'], 0], ['control ["0?"]', ['0?'], 0], ['control ["475646793469?297"]', ['475646793469?297'], 0]], [['regression ["1507302?557627"]', ['1507302?557627'], 8], ['regression ["4111111111?11111"]', ['4111111111?11111'], 1], ['partial-repair ["6?0334555"]', ['6?0334555'], 3], ['partial-repair ["033?959838019"]', ['033?959838019'], 2], ['control ["??"]', ['??'], None], ['control ["1"]', ['1'], None], ['control ["12a?"]', ['12a?'], None], ['control ["?"]', ['?'], None]], [['regression ["?929942967"]', ['?929942967'], 1], ['regression ["1519774?1518"]', ['1519774?1518'], 5], ['partial-repair ["08?8016"]', ['08?8016'], 8], ['partial-repair ["2288?7"]', ['2288?7'], 1], ['control ["0?"]', ['0?'], 0], ['control ["475646793469?297"]', ['475646793469?297'], 0], ['control ["405529124?1"]', ['405529124?1'], 9], ['control ["??"]', ['??'], None]], [['regression ["3102377592002?64"]', ['3102377592002?64'], 6], ['regression ["2288?7"]', ['2288?7'], 1], ['partial-repair ["7992739871?"]', ['7992739871?'], 3], ['partial-repair ["?9927398713"]', ['?9927398713'], 7], ['control ["12a?"]', ['12a?'], None], ['control ["?"]', ['?'], None], ['control ["?0"]', ['?0'], 0], ['control ["0?"]', ['0?'], 0]]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
regression ["766?9906"]22Passed
regression ["?929942967"]11Passed
partial-repair ["7?850"]22Passed
control ["475646793469?297"]00Passed
control ["405529124?1"]99Passed
control ["??"]NoneNonePassed
control ["1"]NoneNonePassed
control ["12a?"]NoneNonePassed

SHA-256 / df20740c374a72f2abf4722dd7d76485cd522227ace0bf3980f813745e730ce3

Verification & scope

A deterministic, bounded teaching model of the named scheme under the stated contract; not a certified validator. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:48:41.639904+00:00.

Case digest / 316994d713afa9f4915e86db8df75bda5f3d3ae3464468b17ea1a9af1bee6816