FA-79831 / Barcode symbology encoding / Open access
Pharmacode bars are printed in generation order · case 01
Codes are mirrored, so asymmetric patterns scan as other values.
ROOT CAUSE
Bars are emitted least significant first instead of reversed.
VERIFIED REPAIR
Reverse the generated bars so the most significant bar comes first.
Unsuccessful approach: Rotating one bar to the front is not a reversal.
Case contract
Encode an integer 3..131070 as a one-track Pharmacode: repeatedly, an even value adds a wide bar and becomes (n - 2) / 2, an odd value adds a narrow bar and becomes (n - 1) / 2, until zero; bars are read in the reverse order of generation (left to right). Width: narrow 1, wide 3, spaces 2 between bars. Return [pattern, width] or None outside the range.
Why this case matters
Retail, logistics, pharmacy and document workflows depend on encoders that produce exactly the module pattern, code-set switches, separators and quiet zones scanners expect; one misplaced module or separator makes a label unreadable or, worse, scan as different data.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(n):
if not isinstance(n, int) or n < 3 or n > 131070:
return None
bars = []
while n > 0:
if n % 2 == 0:
bars.append('w')
n = (n - 2) // 2
else:
bars.append('n')
n = (n - 1) // 2
pass
width = sum(3 if b == 'w' else 1 for b in bars) + 2 * (len(bars) - 1)
return [''.join(bars), width]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[34, ['nnnww', 17]], [120, ['wwwnnw', 24]], [7, ['nnn', 7]], [30, ['wwww', 18]], [127, ['nnnnnnn', 19]], [1, None], [2, None], [306, ['nnwwnnww', 30]]], [[85, ['nwnwwn', 22]], [353, ['nwwnnnwn', 28]], [31, ['nnnnn', 13]], [126, ['wwwwww', 28]], [127, ['nnnnnnn', 19]], [1022, ['wwwwwwwww', 43]], [1, None], [306, ['nnwwnnww', 30]]], [[142, ['nnnwwww', 27]], [274, ['nnnwnnww', 28]], [15, ['nnnn', 10]], [63, ['nnnnnn', 16]], [255, ['nnnnnnnn', 22]], [14, ['www', 13]], [1, None], [396, ['wnnnwwnw', 30]]], [[157, ['nnwwwwn', 27]], [19, ['nwnn', 12]], [240, ['wwwnnnw', 27]], [3, ['nn', 4]], [254, ['wwwwwww', 33]], [127, ['nnnnnnn', 19]], [1, None], [143, ['nnwnnnn', 21]]], [[157, ['nnwwwwn', 27]], [228, ['wwnnwnw', 27]], [158, ['nnwwwww', 29]], [30, ['wwww', 18]], [6, ['ww', 8]], [1, None], [2, None], [225, ['wwnnnwn', 25]]]]
labels = ["regression: reading order of bars", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
check("%s %d" % (labels[i % len(labels)], i), 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: reading order of bars 0 | ['wwnnn', 17] | ['nnnww', 17] | Failed |
| repair trap 1 | ['wnnwww', 24] | ['wwwnnw', 24] | Failed |
| combined fault 2 | ['nnn', 7] | ['nnn', 7] | Passed |
| control 3 | ['wwww', 18] | ['wwww', 18] | Passed |
| control 4 | ['nnnnnnn', 19] | ['nnnnnnn', 19] | Passed |
| boundary 5 | None | None | Passed |
| boundary 6 | None | None | Passed |
| control 7 | ['wwnnwwnn', 30] | ['nnwwnnww', 30] | Failed |
SHA-256 / 89fec83ae13f90b8d4ccb3a43b5bab8e68874edcdc61c8247ef45a29b3f2f727
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(n):
if not isinstance(n, int) or n < 3 or n > 131070:
return None
bars = []
while n > 0:
if n % 2 == 0:
bars.append('w')
n = (n - 2) // 2
else:
bars.append('n')
n = (n - 1) // 2
bars.insert(0, bars.pop())
width = sum(3 if b == 'w' else 1 for b in bars) + 2 * (len(bars) - 1)
return [''.join(bars), width]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[34, ['nnnww', 17]], [120, ['wwwnnw', 24]], [7, ['nnn', 7]], [30, ['wwww', 18]], [127, ['nnnnnnn', 19]], [1, None], [2, None], [306, ['nnwwnnww', 30]]], [[85, ['nwnwwn', 22]], [353, ['nwwnnnwn', 28]], [31, ['nnnnn', 13]], [126, ['wwwwww', 28]], [127, ['nnnnnnn', 19]], [1022, ['wwwwwwwww', 43]], [1, None], [306, ['nnwwnnww', 30]]], [[142, ['nnnwwww', 27]], [274, ['nnnwnnww', 28]], [15, ['nnnn', 10]], [63, ['nnnnnn', 16]], [255, ['nnnnnnnn', 22]], [14, ['www', 13]], [1, None], [396, ['wnnnwwnw', 30]]], [[157, ['nnwwwwn', 27]], [19, ['nwnn', 12]], [240, ['wwwnnnw', 27]], [3, ['nn', 4]], [254, ['wwwwwww', 33]], [127, ['nnnnnnn', 19]], [1, None], [143, ['nnwnnnn', 21]]], [[157, ['nnwwwwn', 27]], [228, ['wwnnwnw', 27]], [158, ['nnwwwww', 29]], [30, ['wwww', 18]], [6, ['ww', 8]], [1, None], [2, None], [225, ['wwnnnwn', 25]]]]
labels = ["regression: reading order of bars", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
check("%s %d" % (labels[i % len(labels)], i), 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: reading order of bars 0 | ['nwwnn', 17] | ['nnnww', 17] | Failed |
| repair trap 1 | ['wwnnww', 24] | ['wwwnnw', 24] | Failed |
| combined fault 2 | ['nnn', 7] | ['nnn', 7] | Passed |
| control 3 | ['wwww', 18] | ['wwww', 18] | Passed |
| control 4 | ['nnnnnnn', 19] | ['nnnnnnn', 19] | Passed |
| boundary 5 | None | None | Passed |
| boundary 6 | None | None | Passed |
| control 7 | ['nwwnnwwn', 30] | ['nnwwnnww', 30] | Failed |
SHA-256 / 92dcdc96e17cbb514f121f97e8e0f6590837a0a410daa2bd5d8cd257fbe6a777
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(n):
if not isinstance(n, int) or n < 3 or n > 131070:
return None
bars = []
while n > 0:
if n % 2 == 0:
bars.append('w')
n = (n - 2) // 2
else:
bars.append('n')
n = (n - 1) // 2
bars.reverse()
width = sum(3 if b == 'w' else 1 for b in bars) + 2 * (len(bars) - 1)
return [''.join(bars), width]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[34, ['nnnww', 17]], [120, ['wwwnnw', 24]], [7, ['nnn', 7]], [30, ['wwww', 18]], [127, ['nnnnnnn', 19]], [1, None], [2, None], [306, ['nnwwnnww', 30]]], [[85, ['nwnwwn', 22]], [353, ['nwwnnnwn', 28]], [31, ['nnnnn', 13]], [126, ['wwwwww', 28]], [127, ['nnnnnnn', 19]], [1022, ['wwwwwwwww', 43]], [1, None], [306, ['nnwwnnww', 30]]], [[142, ['nnnwwww', 27]], [274, ['nnnwnnww', 28]], [15, ['nnnn', 10]], [63, ['nnnnnn', 16]], [255, ['nnnnnnnn', 22]], [14, ['www', 13]], [1, None], [396, ['wnnnwwnw', 30]]], [[157, ['nnwwwwn', 27]], [19, ['nwnn', 12]], [240, ['wwwnnnw', 27]], [3, ['nn', 4]], [254, ['wwwwwww', 33]], [127, ['nnnnnnn', 19]], [1, None], [143, ['nnwnnnn', 21]]], [[157, ['nnwwwwn', 27]], [228, ['wwnnwnw', 27]], [158, ['nnwwwww', 29]], [30, ['wwww', 18]], [6, ['ww', 8]], [1, None], [2, None], [225, ['wwnnnwn', 25]]]]
labels = ["regression: reading order of bars", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
check("%s %d" % (labels[i % len(labels)], i), 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: reading order of bars 0 | ['nnnww', 17] | ['nnnww', 17] | Passed |
| repair trap 1 | ['wwwnnw', 24] | ['wwwnnw', 24] | Passed |
| combined fault 2 | ['nnn', 7] | ['nnn', 7] | Passed |
| control 3 | ['wwww', 18] | ['wwww', 18] | Passed |
| control 4 | ['nnnnnnn', 19] | ['nnnnnnn', 19] | Passed |
| boundary 5 | None | None | Passed |
| boundary 6 | None | None | Passed |
| control 7 | ['nnwwnnww', 30] | ['nnwwnnww', 30] | Passed |
SHA-256 / 1618f7da0c8df944f3ba406720708313a37cf96e5ca619e314406f5f97c7dfc0
Verification & scope
A deterministic bounded teaching model with a stipulated contract; it makes no claim of conformance to any published specification. 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:49:48.212374+00:00.
Case digest / cc497b3a3dd30cfab52f07ebbeb1170976b55a3b3c98689786d1a4568cc01f3e