broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(text, mode, ratio):
    std = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%'
    if ratio not in (2, 3):
        return {'error': 'ratio'}
    if mode == 'standard':
        for ch in text:
            if ch not in std:
                return {'error': 'char', 'char': ch}
        enc = text
    else:
        punct = {'$': '/D', '%': '/E', '+': '/K', '/': '/O', '!': '/A', '"': '/B', '#': '/C', '&': '/F', "'": '/G',
                 '(': '/H', ')': '/I', '*': '/J', ',': '/L', ':': '/Z', ';': '%F', '<': '%G', '=': '%H', '>': '%I',
                 '?': '%J', '@': '%V', '[': '%K', '\\': '%L', ']': '%M', '^': '%N', '_': '%O', '`': '%W',
                 '{': '%P', '|': '%Q', '}': '%R', '~': '%S'}
        enc = ''
        for ch in text:
            o = ord(ch)
            if o > 127:
                return {'error': 'char', 'char': ch}
            if ch in punct:
                enc += punct[ch]
            elif 'a' <= ch <= 'z':
                enc += '+' + ch.upper()
            elif 1 <= o <= 26:
                enc += '$' + chr(o + 65)
            elif o == 0:
                enc += '%U'
            elif 27 <= o <= 31:
                enc += '%' + chr(o - 27 + 65)
            elif o == 127:
                enc += '%T'
            else:
                enc += ch
    count = len(enc) + 2
    return {'data': '*' + enc + '*', 'modules': count * (6 + 3 * ratio) + (count - 1)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('AB\t', 'full', 2), {'data': '*AB$I*', 'modules': 77}], [('Z-9x\t', 'full', 2), {'data': '*Z-9+X$I*', 'modules': 116}], [('café', 'standard', 4), {'error': 'ratio'}], [('ABPN/7PN/7', 'full', 1), {'error': 'ratio'}], [('a+ba+b', 'full', 4), {'error': 'ratio'}], [('Z-9a+blot', 'standard', 2), {'error': 'char', 'char': 'a'}], [('café\t', 'full', 4), {'error': 'ratio'}], [('\t$5', 'full', 2), {'data': '*$I/D5*', 'modules': 90}]], [[('\t#1', 'full', 2), {'data': '*$I/C1*', 'modules': 90}], [('\t\x1b', 'full', 2), {'data': '*$I%A*', 'modules': 77}], [('', 'standard', 1), {'error': 'ratio'}], [('\x1blotlot', 'full', 2), {'data': '*%A+L+O+T+L+O+T*', 'modules': 207}], [('#1', 'full', 2), {'data': '*/C1*', 'modules': 64}], [('ABa+b', 'full', 2), {'data': '*AB+A/K+B*', 'modules': 129}], [('', 'full', 3), {'data': '**', 'modules': 31}], [('\t', 'full', 3), {'data': '*$I*', 'modules': 63}]], [[('\t#1*', 'full', 3), {'data': '*$I/C1/J*', 'modules': 143}], [('\x7fq\t', 'full', 3), {'data': '*%T+Q$I*', 'modules': 127}], [('a+bAB', 'full', 2), {'data': '*+A/K+BAB*', 'modules': 129}], [('#1café', 'standard', 4), {'error': 'ratio'}], [('ABPN/7Z-9', 'full', 2), {'data': '*ABPN/O7Z-9*', 'modules': 155}], [(' ', 'full', 1), {'error': 'ratio'}], [('$5 \x00', 'full', 2), {'data': '*/D5 %U*', 'modules': 103}], [('\x00\t50%', 'full', 2), {'data': '*%U$I50/E*', 'modules': 129}]], [[('\t*q', 'full', 3), {'data': '*$I/J+Q*', 'modules': 127}], [('qPN/7café', 'full', 2), {'error': 'char', 'char': 'é'}], [('AB\x00 ', 'full', 1), {'error': 'ratio'}], [('*', 'full', 2), {'data': '*/J*', 'modules': 51}], [('AB12', 'standard', 2), {'data': '*AB12*', 'modules': 77}], [('#1café', 'full', 2), {'error': 'char', 'char': 'é'}], [(' ABPN/7', 'full', 1), {'error': 'ratio'}], [('\t\x7f', 'full', 3), {'data': '*$I%T*', 'modules': 95}]], [[('\t\t', 'full', 3), {'data': '*$I$I*', 'modules': 95}], [('  \t', 'full', 2), {'data': '*  $I*', 'modules': 77}], [('\x00', 'full', 1), {'error': 'ratio'}], [('', 'standard', 2), {'data': '**', 'modules': 25}], [('', 'standard', 1), {'error': 'ratio'}], [('\x7f\x00', 'full', 4), {'error': 'ratio'}], [('$5a+bAB', 'full', 3), {'data': '*/D5+A/K+BAB*', 'modules': 207}], [('50% \t', 'full', 3), {'data': '*50/E $I*', 'modules': 143}]]]
labels = ["regression: control character escape letter", "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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(text, mode, ratio):
    std = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%'
    if ratio not in (2, 3):
        return {'error': 'ratio'}
    if mode == 'standard':
        for ch in text:
            if ch not in std:
                return {'error': 'char', 'char': ch}
        enc = text
    else:
        punct = {'$': '/D', '%': '/E', '+': '/K', '/': '/O', '!': '/A', '"': '/B', '#': '/C', '&': '/F', "'": '/G',
                 '(': '/H', ')': '/I', '*': '/J', ',': '/L', ':': '/Z', ';': '%F', '<': '%G', '=': '%H', '>': '%I',
                 '?': '%J', '@': '%V', '[': '%K', '\\': '%L', ']': '%M', '^': '%N', '_': '%O', '`': '%W',
                 '{': '%P', '|': '%Q', '}': '%R', '~': '%S'}
        enc = ''
        for ch in text:
            o = ord(ch)
            if o > 127:
                return {'error': 'char', 'char': ch}
            if ch in punct:
                enc += punct[ch]
            elif 'a' <= ch <= 'z':
                enc += '+' + ch.upper()
            elif 1 <= o <= 26:
                enc += '$' + chr(o + 96)
            elif o == 0:
                enc += '%U'
            elif 27 <= o <= 31:
                enc += '%' + chr(o - 27 + 65)
            elif o == 127:
                enc += '%T'
            else:
                enc += ch
    count = len(enc) + 2
    return {'data': '*' + enc + '*', 'modules': count * (6 + 3 * ratio) + (count - 1)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('AB\t', 'full', 2), {'data': '*AB$I*', 'modules': 77}], [('Z-9x\t', 'full', 2), {'data': '*Z-9+X$I*', 'modules': 116}], [('café', 'standard', 4), {'error': 'ratio'}], [('ABPN/7PN/7', 'full', 1), {'error': 'ratio'}], [('a+ba+b', 'full', 4), {'error': 'ratio'}], [('Z-9a+blot', 'standard', 2), {'error': 'char', 'char': 'a'}], [('café\t', 'full', 4), {'error': 'ratio'}], [('\t$5', 'full', 2), {'data': '*$I/D5*', 'modules': 90}]], [[('\t#1', 'full', 2), {'data': '*$I/C1*', 'modules': 90}], [('\t\x1b', 'full', 2), {'data': '*$I%A*', 'modules': 77}], [('', 'standard', 1), {'error': 'ratio'}], [('\x1blotlot', 'full', 2), {'data': '*%A+L+O+T+L+O+T*', 'modules': 207}], [('#1', 'full', 2), {'data': '*/C1*', 'modules': 64}], [('ABa+b', 'full', 2), {'data': '*AB+A/K+B*', 'modules': 129}], [('', 'full', 3), {'data': '**', 'modules': 31}], [('\t', 'full', 3), {'data': '*$I*', 'modules': 63}]], [[('\t#1*', 'full', 3), {'data': '*$I/C1/J*', 'modules': 143}], [('\x7fq\t', 'full', 3), {'data': '*%T+Q$I*', 'modules': 127}], [('a+bAB', 'full', 2), {'data': '*+A/K+BAB*', 'modules': 129}], [('#1café', 'standard', 4), {'error': 'ratio'}], [('ABPN/7Z-9', 'full', 2), {'data': '*ABPN/O7Z-9*', 'modules': 155}], [(' ', 'full', 1), {'error': 'ratio'}], [('$5 \x00', 'full', 2), {'data': '*/D5 %U*', 'modules': 103}], [('\x00\t50%', 'full', 2), {'data': '*%U$I50/E*', 'modules': 129}]], [[('\t*q', 'full', 3), {'data': '*$I/J+Q*', 'modules': 127}], [('qPN/7café', 'full', 2), {'error': 'char', 'char': 'é'}], [('AB\x00 ', 'full', 1), {'error': 'ratio'}], [('*', 'full', 2), {'data': '*/J*', 'modules': 51}], [('AB12', 'standard', 2), {'data': '*AB12*', 'modules': 77}], [('#1café', 'full', 2), {'error': 'char', 'char': 'é'}], [(' ABPN/7', 'full', 1), {'error': 'ratio'}], [('\t\x7f', 'full', 3), {'data': '*$I%T*', 'modules': 95}]], [[('\t\t', 'full', 3), {'data': '*$I$I*', 'modules': 95}], [('  \t', 'full', 2), {'data': '*  $I*', 'modules': 77}], [('\x00', 'full', 1), {'error': 'ratio'}], [('', 'standard', 2), {'data': '**', 'modules': 25}], [('', 'standard', 1), {'error': 'ratio'}], [('\x7f\x00', 'full', 4), {'error': 'ratio'}], [('$5a+bAB', 'full', 3), {'data': '*/D5+A/K+BAB*', 'modules': 207}], [('50% \t', 'full', 3), {'data': '*50/E $I*', 'modules': 143}]]]
labels = ["regression: control character escape letter", "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)

prompt:
A tab encodes as $J (line feed) and data separators become the wrong control codes.

Encode text for Code 39 with a wide:narrow ratio of 2 or 3. Standard mode accepts only the 43 characters 0-9 A-Z - . space $ / + %. Full ASCII mode maps lowercase to "+" plus the capital, controls 1..26 to "$" plus A..Z, NUL to %U, 27..31 to %A..%E, DEL to %T, and punctuation (including the four standard shift characters $ % + /) to its two-character escape. Every symbol character, including the start/stop "*", has 6 narrow and 3 wide elements, and one narrow gap separates adjacent characters. Return the framed data and the total width in narrow modules.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(text, mode, ratio):
    std = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%'
    if ratio < 2:
        return {'error': 'ratio'}
    if mode == 'standard':
        for ch in text:
            if ch not in std:
                return {'error': 'char', 'char': ch}
        enc = text
    else:
        punct = {'$': '/D', '%': '/E', '+': '/K', '/': '/O', '!': '/A', '"': '/B', '#': '/C', '&': '/F', "'": '/G',
                 '(': '/H', ')': '/I', '*': '/J', ',': '/L', ':': '/Z', ';': '%F', '<': '%G', '=': '%H', '>': '%I',
                 '?': '%J', '@': '%V', '[': '%K', '\\': '%L', ']': '%M', '^': '%N', '_': '%O', '`': '%W',
                 '{': '%P', '|': '%Q', '}': '%R', '~': '%S'}
        enc = ''
        for ch in text:
            o = ord(ch)
            if o > 127:
                return {'error': 'char', 'char': ch}
            if ch in punct:
                enc += punct[ch]
            elif 'a' <= ch <= 'z':
                enc += '+' + ch.upper()
            elif 1 <= o <= 26:
                enc += '$' + chr(o + 64)
            elif o == 0:
                enc += '%U'
            elif 27 <= o <= 31:
                enc += '%' + chr(o - 27 + 65)
            elif o == 127:
                enc += '%T'
            else:
                enc += ch
    count = len(enc) + 2
    return {'data': '*' + enc + '*', 'modules': count * (6 + 3 * ratio) + (count - 1)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('café', 'standard', 4), {'error': 'ratio'}], [('ABPN/7PN/7', 'full', 1), {'error': 'ratio'}], [('Z-9a+blot', 'standard', 2), {'error': 'char', 'char': 'a'}], [('PN/7PN/7$5', 'full', 3), {'data': '*PN/O7PN/O7/D5*', 'modules': 239}], [('\x1b', 'full', 2), {'data': '*%A*', 'modules': 51}], [('', 'full', 3), {'data': '**', 'modules': 31}], [('café', 'standard', 3), {'error': 'char', 'char': 'c'}], [('a+ba+b', 'full', 4), {'error': 'ratio'}]], [[('\x00caféq', 'full', 4), {'error': 'ratio'}], [('', 'standard', 1), {'error': 'ratio'}], [('\x1blotlot', 'full', 2), {'data': '*%A+L+O+T+L+O+T*', 'modules': 207}], [('#1', 'full', 2), {'data': '*/C1*', 'modules': 64}], [('ABa+b', 'full', 2), {'data': '*AB+A/K+B*', 'modules': 129}], [('', 'full', 3), {'data': '**', 'modules': 31}], [('\x1b', 'full', 2), {'data': '*%A*', 'modules': 51}], [('q$5café', 'standard', 4), {'error': 'ratio'}]], [[('\x7f#1', 'standard', 4), {'error': 'ratio'}], [(' ', 'full', 1), {'error': 'ratio'}], [('$5 \x00', 'full', 2), {'data': '*/D5 %U*', 'modules': 103}], [('$550%', 'full', 3), {'data': '*/D550/E*', 'modules': 143}], [('*\x1bcafé', 'full', 2), {'error': 'char', 'char': 'é'}], [('q \x00', 'full', 2), {'data': '*+Q %U*', 'modules': 90}], [('xcafé50%', 'standard', 3), {'error': 'char', 'char': 'x'}], [('', 'full', 4), {'error': 'ratio'}]], [[('a+blot\x1b', 'full', 4), {'error': 'ratio'}], [('', 'full', 1), {'error': 'ratio'}], [('qPN/7café', 'full', 2), {'error': 'char', 'char': 'é'}], [('*', 'full', 2), {'data': '*/J*', 'modules': 51}], [('AB12', 'standard', 2), {'data': '*AB12*', 'modules': 77}], [('\x7f\tlot', 'full', 3), {'data': '*%T$I+L+O+T*', 'modules': 191}], [('#1café', 'full', 2), {'error': 'char', 'char': 'é'}], [('PN/7', 'full', 4), {'error': 'ratio'}]], [[('PN/7', 'standard', 4), {'error': 'ratio'}], [('\x7f$5', 'full', 1), {'error': 'ratio'}], [('$5lot', 'full', 3), {'data': '*/D5+L+O+T*', 'modules': 175}], [('', 'standard', 2), {'data': '**', 'modules': 25}], [('$5a+bAB', 'full', 3), {'data': '*/D5+A/K+BAB*', 'modules': 207}], [('#112\x7f', 'full', 3), {'data': '*/C112%T*', 'modules': 143}], [('q*PN/7', 'standard', 2), {'error': 'char', 'char': 'q'}], [('Z-9$512', 'standard', 4), {'error': 'ratio'}]]]
labels = ["regression: wide to narrow ratio validation", "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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(text, mode, ratio):
    std = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%'
    if ratio > 3:
        return {'error': 'ratio'}
    if mode == 'standard':
        for ch in text:
            if ch not in std:
                return {'error': 'char', 'char': ch}
        enc = text
    else:
        punct = {'$': '/D', '%': '/E', '+': '/K', '/': '/O', '!': '/A', '"': '/B', '#': '/C', '&': '/F', "'": '/G',
                 '(': '/H', ')': '/I', '*': '/J', ',': '/L', ':': '/Z', ';': '%F', '<': '%G', '=': '%H', '>': '%I',
                 '?': '%J', '@': '%V', '[': '%K', '\\': '%L', ']': '%M', '^': '%N', '_': '%O', '`': '%W',
                 '{': '%P', '|': '%Q', '}': '%R', '~': '%S'}
        enc = ''
        for ch in text:
            o = ord(ch)
            if o > 127:
                return {'error': 'char', 'char': ch}
            if ch in punct:
                enc += punct[ch]
            elif 'a' <= ch <= 'z':
                enc += '+' + ch.upper()
            elif 1 <= o <= 26:
                enc += '$' + chr(o + 64)
            elif o == 0:
                enc += '%U'
            elif 27 <= o <= 31:
                enc += '%' + chr(o - 27 + 65)
            elif o == 127:
                enc += '%T'
            else:
                enc += ch
    count = len(enc) + 2
    return {'data': '*' + enc + '*', 'modules': count * (6 + 3 * ratio) + (count - 1)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('café', 'standard', 4), {'error': 'ratio'}], [('ABPN/7PN/7', 'full', 1), {'error': 'ratio'}], [('Z-9a+blot', 'standard', 2), {'error': 'char', 'char': 'a'}], [('PN/7PN/7$5', 'full', 3), {'data': '*PN/O7PN/O7/D5*', 'modules': 239}], [('\x1b', 'full', 2), {'data': '*%A*', 'modules': 51}], [('', 'full', 3), {'data': '**', 'modules': 31}], [('café', 'standard', 3), {'error': 'char', 'char': 'c'}], [('a+ba+b', 'full', 4), {'error': 'ratio'}]], [[('\x00caféq', 'full', 4), {'error': 'ratio'}], [('', 'standard', 1), {'error': 'ratio'}], [('\x1blotlot', 'full', 2), {'data': '*%A+L+O+T+L+O+T*', 'modules': 207}], [('#1', 'full', 2), {'data': '*/C1*', 'modules': 64}], [('ABa+b', 'full', 2), {'data': '*AB+A/K+B*', 'modules': 129}], [('', 'full', 3), {'data': '**', 'modules': 31}], [('\x1b', 'full', 2), {'data': '*%A*', 'modules': 51}], [('q$5café', 'standard', 4), {'error': 'ratio'}]], [[('\x7f#1', 'standard', 4), {'error': 'ratio'}], [(' ', 'full', 1), {'error': 'ratio'}], [('$5 \x00', 'full', 2), {'data': '*/D5 %U*', 'modules': 103}], [('$550%', 'full', 3), {'data': '*/D550/E*', 'modules': 143}], [('*\x1bcafé', 'full', 2), {'error': 'char', 'char': 'é'}], [('q \x00', 'full', 2), {'data': '*+Q %U*', 'modules': 90}], [('xcafé50%', 'standard', 3), {'error': 'char', 'char': 'x'}], [('', 'full', 4), {'error': 'ratio'}]], [[('a+blot\x1b', 'full', 4), {'error': 'ratio'}], [('', 'full', 1), {'error': 'ratio'}], [('qPN/7café', 'full', 2), {'error': 'char', 'char': 'é'}], [('*', 'full', 2), {'data': '*/J*', 'modules': 51}], [('AB12', 'standard', 2), {'data': '*AB12*', 'modules': 77}], [('\x7f\tlot', 'full', 3), {'data': '*%T$I+L+O+T*', 'modules': 191}], [('#1café', 'full', 2), {'error': 'char', 'char': 'é'}], [('PN/7', 'full', 4), {'error': 'ratio'}]], [[('PN/7', 'standard', 4), {'error': 'ratio'}], [('\x7f$5', 'full', 1), {'error': 'ratio'}], [('$5lot', 'full', 3), {'data': '*/D5+L+O+T*', 'modules': 175}], [('', 'standard', 2), {'data': '**', 'modules': 25}], [('$5a+bAB', 'full', 3), {'data': '*/D5+A/K+BAB*', 'modules': 207}], [('#112\x7f', 'full', 3), {'data': '*/C112%T*', 'modules': 143}], [('q*PN/7', 'standard', 2), {'error': 'char', 'char': 'q'}], [('Z-9$512', 'standard', 4), {'error': 'ratio'}]]]
labels = ["regression: wide to narrow ratio validation", "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)

prompt:
Symbols printed with an out-of-range ratio are wider than planned and fail grading.

Encode text for Code 39 with a wide:narrow ratio of 2 or 3. Standard mode accepts only the 43 characters 0-9 A-Z - . space $ / + %. Full ASCII mode maps lowercase to "+" plus the capital, controls 1..26 to "$" plus A..Z, NUL to %U, 27..31 to %A..%E, DEL to %T, and punctuation (including the four standard shift characters $ % + /) to its two-character escape. Every symbol character, including the start/stop "*", has 6 narrow and 3 wide elements, and one narrow gap separates adjacent characters. Return the framed data and the total width in narrow modules.

split: open-access


prompt:
Retail labels reserve four extra modules on the right and overflow narrow shelf strips.

Input {sym, modules, x_um, addon?}. Quiet zones in X: ean13 11 left / 7 right, upca 9/9, ean8 7/7, code128, code39 and itf14 10/10. Allowed X-dimensions in micrometres: EAN/UPC 264..660 inclusive, code128/code39 >= 190, itf14 >= 495. An EAN-2 (20 modules) or EAN-5 (47 modules) add-on is only allowed on EAN/UPC; it replaces the right quiet zone by a 7-module gap, the add-on and a 5-module trailing quiet zone. Return [total_um, left_quiet_um] or unknown/x-out-of-range/bad-addon.

split: open-access


prompt:
Magazine labels with EAN-5 add-ons are laid out too narrow and the add-on is clipped.

Input {sym, modules, x_um, addon?}. Quiet zones in X: ean13 11 left / 7 right, upca 9/9, ean8 7/7, code128, code39 and itf14 10/10. Allowed X-dimensions in micrometres: EAN/UPC 264..660 inclusive, code128/code39 >= 190, itf14 >= 495. An EAN-2 (20 modules) or EAN-5 (47 modules) add-on is only allowed on EAN/UPC; it replaces the right quiet zone by a 7-module gap, the add-on and a 5-module trailing quiet zone. Return [total_um, left_quiet_um] or unknown/x-out-of-range/bad-addon.

split: open-access


prompt:
Symbols with add-ons are wider than the allowed label area.

Input {sym, modules, x_um, addon?}. Quiet zones in X: ean13 11 left / 7 right, upca 9/9, ean8 7/7, code128, code39 and itf14 10/10. Allowed X-dimensions in micrometres: EAN/UPC 264..660 inclusive, code128/code39 >= 190, itf14 >= 495. An EAN-2 (20 modules) or EAN-5 (47 modules) add-on is only allowed on EAN/UPC; it replaces the right quiet zone by a 7-module gap, the add-on and a 5-module trailing quiet zone. Return [total_um, left_quiet_um] or unknown/x-out-of-range/bad-addon.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(spec):
    qz = {'ean13': (11, 7), 'upca': (9, 9), 'ean8': (7, 7), 'code128': (10, 10), 'code39': (10, 10), 'itf14': (10, 10)}
    xr = {'ean13': (264, 660), 'upca': (264, 660), 'ean8': (264, 660), 'code128': (190, None), 'code39': (190, None), 'itf14': (190, None)}
    sym = spec['sym']
    if sym not in qz:
        return 'unknown'
    lo, hi = xr[sym]
    x = spec['x_um']
    if x < lo or (hi is not None and x > hi):
        return 'x-out-of-range'
    left, right = qz[sym]
    addon = spec.get('addon', 0)
    if addon:
        if sym not in ('ean13', 'upca', 'ean8') or addon not in (2, 5):
            return 'bad-addon'
        right = 7 + (20 if addon == 2 else 47) + 5
    total = left + spec['modules'] + right
    return [total * x, left * x]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'sym': 'itf14', 'modules': 95, 'x_um': 250, 'addon': 2}, 'x-out-of-range'], [{'sym': 'itf14', 'modules': 95, 'x_um': 1100}, [126500, 11000]], [{'sym': 'code39', 'modules': 200, 'x_um': 661}, [145420, 6610]], [{'sym': 'ean13', 'modules': 67, 'x_um': 330}, [28050, 3630]], [{'sym': 'qr', 'modules': 200, 'x_um': 250, 'addon': 2}, 'unknown'], [{'sym': 'ean8', 'modules': 101, 'x_um': 1100, 'addon': 5}, 'x-out-of-range'], [{'sym': 'code128', 'modules': 200, 'x_um': 1000, 'addon': 5}, 'bad-addon'], [{'sym': 'itf14', 'modules': 142, 'x_um': 400, 'addon': 5}, 'x-out-of-range']], [[{'sym': 'itf14', 'modules': 142, 'x_um': 263}, 'x-out-of-range'], [{'sym': 'itf14', 'modules': 95, 'x_um': 1100}, [126500, 11000]], [{'sym': 'itf14', 'modules': 67, 'x_um': 1000}, [87000, 10000]], [{'sym': 'code128', 'modules': 200, 'x_um': 660}, [145200, 6600]], [{'sym': 'ean13', 'modules': 95, 'x_um': 661}, 'x-out-of-range'], [{'sym': 'ean13', 'modules': 95, 'x_um': 190}, 'x-out-of-range'], [{'sym': 'ean8', 'modules': 95, 'x_um': 330, 'addon': 5}, [53130, 2310]], [{'sym': 'itf14', 'modules': 101, 'x_um': 400}, 'x-out-of-range']], [[{'sym': 'itf14', 'modules': 101, 'x_um': 250}, 'x-out-of-range'], [{'sym': 'itf14', 'modules': 200, 'x_um': 1100, 'addon': 2}, 'bad-addon'], [{'sym': 'ean13', 'modules': 200, 'x_um': 190}, 'x-out-of-range'], [{'sym': 'code39', 'modules': 101, 'x_um': 400}, [48400, 4000]], [{'sym': 'code39', 'modules': 101, 'x_um': 190, 'addon': 3}, 'bad-addon'], [{'sym': 'upca', 'modules': 101, 'x_um': 1000}, 'x-out-of-range'], [{'sym': 'code39', 'modules': 95, 'x_um': 495, 'addon': 5}, 'bad-addon'], [{'sym': 'itf14', 'modules': 200, 'x_um': 263}, 'x-out-of-range']], [[{'sym': 'itf14', 'modules': 200, 'x_um': 263, 'addon': 2}, 'x-out-of-range'], [{'sym': 'itf14', 'modules': 67, 'x_um': 1100}, [95700, 11000]], [{'sym': 'ean8', 'modules': 142, 'x_um': 400, 'addon': 5}, [83200, 2800]], [{'sym': 'code39', 'modules': 67, 'x_um': 330, 'addon': 2}, 'bad-addon'], [{'sym': 'ean13', 'modules': 101, 'x_um': 1100}, 'x-out-of-range'], [{'sym': 'ean13', 'modules': 67, 'x_um': 661}, 'x-out-of-range'], [{'sym': 'upca', 'modules': 67, 'x_um': 330}, [28050, 2970]], [{'sym': 'itf14', 'modules': 67, 'x_um': 300}, 'x-out-of-range']], [[{'sym': 'itf14', 'modules': 67, 'x_um': 263}, 'x-out-of-range'], [{'sym': 'itf14', 'modules': 101, 'x_um': 1100}, [133100, 11000]], [{'sym': 'ean13', 'modules': 67, 'x_um': 330}, [28050, 3630]], [{'sym': 'ean13', 'modules': 101, 'x_um': 264}, [31416, 2904]], [{'sym': 'ean13', 'modules': 67, 'x_um': 264, 'addon': 2}, [29040, 2904]], [{'sym': 'code128', 'modules': 101, 'x_um': 400}, [48400, 4000]], [{'sym': 'ean13', 'modules': 101, 'x_um': 660}, [78540, 7260]], [{'sym': 'itf14', 'modules': 200, 'x_um': 264}, 'x-out-of-range']]]
labels = ["regression: ITF-14 minimum X-dimension", "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)

prompt:
Carton labels are printed with bars too thin for distribution-centre scanners.

Input {sym, modules, x_um, addon?}. Quiet zones in X: ean13 11 left / 7 right, upca 9/9, ean8 7/7, code128, code39 and itf14 10/10. Allowed X-dimensions in micrometres: EAN/UPC 264..660 inclusive, code128/code39 >= 190, itf14 >= 495. An EAN-2 (20 modules) or EAN-5 (47 modules) add-on is only allowed on EAN/UPC; it replaces the right quiet zone by a 7-module gap, the add-on and a 5-module trailing quiet zone. Return [total_um, left_quiet_um] or unknown/x-out-of-range/bad-addon.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(spec):
    qz = {'ean13': (11, 7), 'upca': (9, 9), 'ean8': (7, 7), 'code128': (10, 10), 'code39': (10, 10), 'itf14': (10, 10)}
    xr = {'ean13': (264, 660), 'upca': (264, 660), 'ean8': (264, 660), 'code128': (190, None), 'code39': (190, None), 'itf14': (495, None)}
    sym = spec['sym']
    if sym not in qz:
        return 'unknown'
    lo, hi = xr[sym]
    x = spec['x_um']
    if x < lo or (hi is not None and x > hi):
        return 'x-out-of-range'
    left, right = qz[sym]
    addon = spec.get('addon', 0)
    if addon:
        if addon not in (2, 5):
            return 'bad-addon'
        right = 7 + (20 if addon == 2 else 47) + 5
    total = left + spec['modules'] + right
    return [total * x, left * x]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'sym': 'code128', 'modules': 200, 'x_um': 1000, 'addon': 5}, 'bad-addon'], [{'sym': 'code128', 'modules': 200, 'x_um': 495, 'addon': 2}, 'bad-addon'], [{'sym': 'code39', 'modules': 200, 'x_um': 661}, [145420, 6610]], [{'sym': 'ean13', 'modules': 67, 'x_um': 330}, [28050, 3630]], [{'sym': 'qr', 'modules': 200, 'x_um': 250, 'addon': 2}, 'unknown'], [{'sym': 'ean8', 'modules': 101, 'x_um': 1100, 'addon': 5}, 'x-out-of-range'], [{'sym': 'itf14', 'modules': 95, 'x_um': 250, 'addon': 2}, 'x-out-of-range'], [{'sym': 'code128', 'modules': 67, 'x_um': 400, 'addon': 2}, 'bad-addon']], [[{'sym': 'code39', 'modules': 95, 'x_um': 661, 'addon': 5}, 'bad-addon'], [{'sym': 'code128', 'modules': 67, 'x_um': 263, 'addon': 5}, 'bad-addon'], [{'sym': 'itf14', 'modules': 142, 'x_um': 495, 'addon': 2}, 'bad-addon'], [{'sym': 'itf14', 'modules': 67, 'x_um': 1000}, [87000, 10000]], [{'sym': 'itf14', 'modules': 67, 'x_um': 250}, 'x-out-of-range'], [{'sym': 'code128', 'modules': 200, 'x_um': 660}, [145200, 6600]], [{'sym': 'ean13', 'modules': 95, 'x_um': 661}, 'x-out-of-range'], [{'sym': 'code39', 'modules': 67, 'x_um': 330, 'addon': 5}, 'bad-addon']], [[{'sym': 'code39', 'modules': 200, 'x_um': 190, 'addon': 5}, 'bad-addon'], [{'sym': 'itf14', 'modules': 200, 'x_um': 1100, 'addon': 2}, 'bad-addon'], [{'sym': 'code128', 'modules': 67, 'x_um': 661, 'addon': 5}, 'bad-addon'], [{'sym': 'ean13', 'modules': 200, 'x_um': 190}, 'x-out-of-range'], [{'sym': 'code39', 'modules': 101, 'x_um': 400}, [48400, 4000]], [{'sym': 'itf14', 'modules': 95, 'x_um': 263, 'addon': 5}, 'x-out-of-range'], [{'sym': 'code39', 'modules': 101, 'x_um': 190, 'addon': 3}, 'bad-addon'], [{'sym': 'code39', 'modules': 101, 'x_um': 660, 'addon': 2}, 'bad-addon']], [[{'sym': 'code128', 'modules': 101, 'x_um': 400, 'addon': 5}, 'bad-addon'], [{'sym': 'code128', 'modules': 67, 'x_um': 250, 'addon': 2}, 'bad-addon'], [{'sym': 'ean8', 'modules': 142, 'x_um': 400, 'addon': 5}, [83200, 2800]], [{'sym': 'ean13', 'modules': 101, 'x_um': 1100}, 'x-out-of-range'], [{'sym': 'itf14', 'modules': 95, 'x_um': 264, 'addon': 2}, 'x-out-of-range'], [{'sym': 'ean13', 'modules': 67, 'x_um': 661}, 'x-out-of-range'], [{'sym': 'itf14', 'modules': 67, 'x_um': 1100, 'addon': 3}, 'bad-addon'], [{'sym': 'code39', 'modules': 142, 'x_um': 263, 'addon': 5}, 'bad-addon']], [[{'sym': 'code39', 'modules': 142, 'x_um': 190, 'addon': 5}, 'bad-addon'], [{'sym': 'code128', 'modules': 101, 'x_um': 190, 'addon': 5}, 'bad-addon'], [{'sym': 'code128', 'modules': 67, 'x_um': 250, 'addon': 2}, 'bad-addon'], [{'sym': 'ean13', 'modules': 67, 'x_um': 330}, [28050, 3630]], [{'sym': 'ean13', 'modules': 101, 'x_um': 264}, [31416, 2904]], [{'sym': 'ean13', 'modules': 67, 'x_um': 264, 'addon': 2}, [29040, 2904]], [{'sym': 'code128', 'modules': 101, 'x_um': 400}, [48400, 4000]], [{'sym': 'itf14', 'modules': 200, 'x_um': 661, 'addon': 5}, 'bad-addon']]]
labels = ["regression: add-on symbology restriction", "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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(spec):
    qz = {'ean13': (11, 7), 'upca': (9, 9), 'ean8': (7, 7), 'code128': (10, 10), 'code39': (10, 10), 'itf14': (10, 10)}
    xr = {'ean13': (264, 660), 'upca': (264, 660), 'ean8': (264, 660), 'code128': (190, None), 'code39': (190, None), 'itf14': (495, None)}
    sym = spec['sym']
    if sym not in qz:
        return 'unknown'
    lo, hi = xr[sym]
    x = spec['x_um']
    if x < lo or (hi is not None and x > hi):
        return 'x-out-of-range'
    left, right = qz[sym]
    addon = spec.get('addon', 0)
    if addon:
        if sym == 'code39' or addon not in (2, 5):
            return 'bad-addon'
        right = 7 + (20 if addon == 2 else 47) + 5
    total = left + spec['modules'] + right
    return [total * x, left * x]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'sym': 'code128', 'modules': 200, 'x_um': 1000, 'addon': 5}, 'bad-addon'], [{'sym': 'code128', 'modules': 200, 'x_um': 495, 'addon': 2}, 'bad-addon'], [{'sym': 'code39', 'modules': 200, 'x_um': 661}, [145420, 6610]], [{'sym': 'ean13', 'modules': 67, 'x_um': 330}, [28050, 3630]], [{'sym': 'qr', 'modules': 200, 'x_um': 250, 'addon': 2}, 'unknown'], [{'sym': 'ean8', 'modules': 101, 'x_um': 1100, 'addon': 5}, 'x-out-of-range'], [{'sym': 'itf14', 'modules': 95, 'x_um': 250, 'addon': 2}, 'x-out-of-range'], [{'sym': 'code128', 'modules': 67, 'x_um': 400, 'addon': 2}, 'bad-addon']], [[{'sym': 'code39', 'modules': 95, 'x_um': 661, 'addon': 5}, 'bad-addon'], [{'sym': 'code128', 'modules': 67, 'x_um': 263, 'addon': 5}, 'bad-addon'], [{'sym': 'itf14', 'modules': 142, 'x_um': 495, 'addon': 2}, 'bad-addon'], [{'sym': 'itf14', 'modules': 67, 'x_um': 1000}, [87000, 10000]], [{'sym': 'itf14', 'modules': 67, 'x_um': 250}, 'x-out-of-range'], [{'sym': 'code128', 'modules': 200, 'x_um': 660}, [145200, 6600]], [{'sym': 'ean13', 'modules': 95, 'x_um': 661}, 'x-out-of-range'], [{'sym': 'code39', 'modules': 67, 'x_um': 330, 'addon': 5}, 'bad-addon']], [[{'sym': 'code39', 'modules': 200, 'x_um': 190, 'addon': 5}, 'bad-addon'], [{'sym': 'itf14', 'modules': 200, 'x_um': 1100, 'addon': 2}, 'bad-addon'], [{'sym': 'code128', 'modules': 67, 'x_um': 661, 'addon': 5}, 'bad-addon'], [{'sym': 'ean13', 'modules': 200, 'x_um': 190}, 'x-out-of-range'], [{'sym': 'code39', 'modules': 101, 'x_um': 400}, [48400, 4000]], [{'sym': 'itf14', 'modules': 95, 'x_um': 263, 'addon': 5}, 'x-out-of-range'], [{'sym': 'code39', 'modules': 101, 'x_um': 190, 'addon': 3}, 'bad-addon'], [{'sym': 'code39', 'modules': 101, 'x_um': 660, 'addon': 2}, 'bad-addon']], [[{'sym': 'code128', 'modules': 101, 'x_um': 400, 'addon': 5}, 'bad-addon'], [{'sym': 'code128', 'modules': 67, 'x_um': 250, 'addon': 2}, 'bad-addon'], [{'sym': 'ean8', 'modules': 142, 'x_um': 400, 'addon': 5}, [83200, 2800]], [{'sym': 'ean13', 'modules': 101, 'x_um': 1100}, 'x-out-of-range'], [{'sym': 'itf14', 'modules': 95, 'x_um': 264, 'addon': 2}, 'x-out-of-range'], [{'sym': 'ean13', 'modules': 67, 'x_um': 661}, 'x-out-of-range'], [{'sym': 'itf14', 'modules': 67, 'x_um': 1100, 'addon': 3}, 'bad-addon'], [{'sym': 'code39', 'modules': 142, 'x_um': 263, 'addon': 5}, 'bad-addon']], [[{'sym': 'code39', 'modules': 142, 'x_um': 190, 'addon': 5}, 'bad-addon'], [{'sym': 'code128', 'modules': 101, 'x_um': 190, 'addon': 5}, 'bad-addon'], [{'sym': 'code128', 'modules': 67, 'x_um': 250, 'addon': 2}, 'bad-addon'], [{'sym': 'ean13', 'modules': 67, 'x_um': 330}, [28050, 3630]], [{'sym': 'ean13', 'modules': 101, 'x_um': 264}, [31416, 2904]], [{'sym': 'ean13', 'modules': 67, 'x_um': 264, 'addon': 2}, [29040, 2904]], [{'sym': 'code128', 'modules': 101, 'x_um': 400}, [48400, 4000]], [{'sym': 'itf14', 'modules': 200, 'x_um': 661, 'addon': 5}, 'bad-addon']]]
labels = ["regression: add-on symbology restriction", "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)

prompt:
Layouts reserve space for an EAN-5 next to a Code 128 symbol that scanners will never read together.

Input {sym, modules, x_um, addon?}. Quiet zones in X: ean13 11 left / 7 right, upca 9/9, ean8 7/7, code128, code39 and itf14 10/10. Allowed X-dimensions in micrometres: EAN/UPC 264..660 inclusive, code128/code39 >= 190, itf14 >= 495. An EAN-2 (20 modules) or EAN-5 (47 modules) add-on is only allowed on EAN/UPC; it replaces the right quiet zone by a 7-module gap, the add-on and a 5-module trailing quiet zone. Return [total_um, left_quiet_um] or unknown/x-out-of-range/bad-addon.

split: open-access


prompt:
The add-on runs into the label edge and its last digit is misread.

Input {sym, modules, x_um, addon?}. Quiet zones in X: ean13 11 left / 7 right, upca 9/9, ean8 7/7, code128, code39 and itf14 10/10. Allowed X-dimensions in micrometres: EAN/UPC 264..660 inclusive, code128/code39 >= 190, itf14 >= 495. An EAN-2 (20 modules) or EAN-5 (47 modules) add-on is only allowed on EAN/UPC; it replaces the right quiet zone by a 7-module gap, the add-on and a 5-module trailing quiet zone. Return [total_um, left_quiet_um] or unknown/x-out-of-range/bad-addon.

split: open-access


prompt:
Every digit pair scans reversed, so 1234 reads as 2143.

Encode ASCII digits as Interleaved 2 of 5 element widths (narrow 1, wide = ratio in {2, 2.5, 3}). An odd-length input gets a leading 0. Start is narrow bar/space/bar/space; each digit pair interleaves the first digit's pattern in the bars with the second digit's pattern in the spaces; stop is wide bar, narrow space, narrow bar. Digit patterns use weights 1,2,4,7 plus parity (0 = NNWWN). Invalid input returns None.

split: open-access


prompt:
A five-digit value 12345 scans as 123450, changing its magnitude.

Encode ASCII digits as Interleaved 2 of 5 element widths (narrow 1, wide = ratio in {2, 2.5, 3}). An odd-length input gets a leading 0. Start is narrow bar/space/bar/space; each digit pair interleaves the first digit's pattern in the bars with the second digit's pattern in the spaces; stop is wide bar, narrow space, narrow bar. Digit patterns use weights 1,2,4,7 plus parity (0 = NNWWN). Invalid input returns None.

split: open-access


prompt:
Scanners fail to find the stop pattern when reading right to left.

Encode ASCII digits as Interleaved 2 of 5 element widths (narrow 1, wide = ratio in {2, 2.5, 3}). An odd-length input gets a leading 0. Start is narrow bar/space/bar/space; each digit pair interleaves the first digit's pattern in the bars with the second digit's pattern in the spaces; stop is wide bar, narrow space, narrow bar. Digit patterns use weights 1,2,4,7 plus parity (0 = NNWWN). Invalid input returns None.

split: open-access


prompt:
Any zero digit makes the pair undecodable because each digit must have exactly two wide elements.

Encode ASCII digits as Interleaved 2 of 5 element widths (narrow 1, wide = ratio in {2, 2.5, 3}). An odd-length input gets a leading 0. Start is narrow bar/space/bar/space; each digit pair interleaves the first digit's pattern in the bars with the second digit's pattern in the spaces; stop is wide bar, narrow space, narrow bar. Digit patterns use weights 1,2,4,7 plus parity (0 = NNWWN). Invalid input returns None.

split: open-access


prompt:
Blank quantity fields produce a symbol that scans as nothing instead of an error.

Encode ASCII digits as Interleaved 2 of 5 element widths (narrow 1, wide = ratio in {2, 2.5, 3}). An odd-length input gets a leading 0. Start is narrow bar/space/bar/space; each digit pair interleaves the first digit's pattern in the bars with the second digit's pattern in the spaces; stop is wide bar, narrow space, narrow bar. Digit patterns use weights 1,2,4,7 plus parity (0 = NNWWN). Invalid input returns None.

split: open-access


prompt:
Symbols printed at a 3:1 ratio have data elements at 2:1 but a 3:1 stop bar.

Encode ASCII digits as Interleaved 2 of 5 element widths (narrow 1, wide = ratio in {2, 2.5, 3}). An odd-length input gets a leading 0. Start is narrow bar/space/bar/space; each digit pair interleaves the first digit's pattern in the bars with the second digit's pattern in the spaces; stop is wide bar, narrow space, narrow bar. Digit patterns use weights 1,2,4,7 plus parity (0 = NNWWN). Invalid input returns None.

split: open-access


prompt:
Blood-bag and library labels containing "-" are laid out wider than printed.

Validate and size a Codabar symbol text with a wide:narrow ratio between 2 and 3 inclusive. The first and last characters must be start/stop letters A-D (uppercase only, at least two characters); body characters are 0-9 - $ : / . +. Each character has 7 elements: digits, "-" and "$" have 2 wide elements, ": / . +" and A-D have 3. One narrow gap separates adjacent characters. Return the total width in narrow modules or an error.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(text, ratio):
    if not 2 <= ratio <= 3:
        return {'error': 'ratio'}
    if len(text) < 2:
        return {'error': 'short'}
    if text[0].upper() not in 'ABCD' or text[-1].upper() not in 'ABCD':
        return {'error': 'start-stop'}
    body = text[1:-1]
    for ch in body:
        if ch not in '0123456789-$:/.+':
            return {'error': 'char', 'char': ch}
    total = 0
    for ch in text:
        wides = 2 if ch in '0123456789-$' else 3
        total += (7 - wides) + wides * ratio
    return {'modules': total + len(text) - 1}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('a+d', 2.5), {'error': 'start-stop'}], [('A+53T', 3), {'error': 'start-stop'}], [('DA/40D', 2.5), {'error': 'char', 'char': 'A'}], [('AE2$5C', 3), {'error': 'char', 'char': 'E'}], [('C5525D', 1.5), {'error': 'ratio'}], [('D$554A', 4), {'error': 'ratio'}], [('C+B', 3), {'modules': 41}], [('ad', 3), {'error': 'start-stop'}]], [[('a3/AC', 3), {'error': 'start-stop'}], [('BT', 3), {'error': 'start-stop'}], [('a$5D', 1.5), {'error': 'ratio'}], [('CD', 2), {'modules': 21}], [('AAA$03d', 4), {'error': 'ratio'}], [('C773C', 1.5), {'error': 'ratio'}], [('a2$A', 1.5), {'error': 'ratio'}], [('BE3Ed', 2.5), {'error': 'start-stop'}]], [[('B55d', 2.5), {'error': 'start-stop'}], [('C35355T', 3), {'error': 'start-stop'}], [('a+A', 4), {'error': 'ratio'}], [('A9505D', 2), {'modules': 61}], [('a958$3C', 1.5), {'error': 'ratio'}], [('D5357T', 1.5), {'error': 'ratio'}], [('a6C', 4), {'error': 'ratio'}], [('a5C', 2), {'error': 'start-stop'}]], [[('a2/C', 2), {'error': 'start-stop'}], [('A3AA+3T', 2.5), {'error': 'start-stop'}], [('B+-+-5B', 1.5), {'error': 'ratio'}], [('A95-42T', 1.5), {'error': 'ratio'}], [('aT', 2.5), {'error': 'start-stop'}], [('A:5B', 2), {'modules': 42}], [('C528+D', 2), {'modules': 62}], [('D3$20d', 3), {'error': 'start-stop'}]], [[('a/D', 3), {'error': 'start-stop'}], [('A9T', 2.5), {'error': 'start-stop'}], [('B5C', 3), {'modules': 39}], [('A-$1A', 3), {'modules': 63}], [('A035/$C', 1.5), {'error': 'ratio'}], [('C55-T', 4), {'error': 'ratio'}], [('a/803T', 3), {'error': 'start-stop'}], [('A97+$5d', 2.5), {'error': 'start-stop'}]]]
labels = ["regression: start and stop letters", "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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(text, ratio):
    if not 2 <= ratio <= 3:
        return {'error': 'ratio'}
    if len(text) < 2:
        return {'error': 'short'}
    if text[0] not in 'ABCDTN*E' or text[-1] not in 'ABCDTN*E':
        return {'error': 'start-stop'}
    body = text[1:-1]
    for ch in body:
        if ch not in '0123456789-$:/.+':
            return {'error': 'char', 'char': ch}
    total = 0
    for ch in text:
        wides = 2 if ch in '0123456789-$' else 3
        total += (7 - wides) + wides * ratio
    return {'modules': total + len(text) - 1}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('a+d', 2.5), {'error': 'start-stop'}], [('A+53T', 3), {'error': 'start-stop'}], [('DA/40D', 2.5), {'error': 'char', 'char': 'A'}], [('AE2$5C', 3), {'error': 'char', 'char': 'E'}], [('C5525D', 1.5), {'error': 'ratio'}], [('D$554A', 4), {'error': 'ratio'}], [('C+B', 3), {'modules': 41}], [('ad', 3), {'error': 'start-stop'}]], [[('a3/AC', 3), {'error': 'start-stop'}], [('BT', 3), {'error': 'start-stop'}], [('a$5D', 1.5), {'error': 'ratio'}], [('CD', 2), {'modules': 21}], [('AAA$03d', 4), {'error': 'ratio'}], [('C773C', 1.5), {'error': 'ratio'}], [('a2$A', 1.5), {'error': 'ratio'}], [('BE3Ed', 2.5), {'error': 'start-stop'}]], [[('B55d', 2.5), {'error': 'start-stop'}], [('C35355T', 3), {'error': 'start-stop'}], [('a+A', 4), {'error': 'ratio'}], [('A9505D', 2), {'modules': 61}], [('a958$3C', 1.5), {'error': 'ratio'}], [('D5357T', 1.5), {'error': 'ratio'}], [('a6C', 4), {'error': 'ratio'}], [('a5C', 2), {'error': 'start-stop'}]], [[('a2/C', 2), {'error': 'start-stop'}], [('A3AA+3T', 2.5), {'error': 'start-stop'}], [('B+-+-5B', 1.5), {'error': 'ratio'}], [('A95-42T', 1.5), {'error': 'ratio'}], [('aT', 2.5), {'error': 'start-stop'}], [('A:5B', 2), {'modules': 42}], [('C528+D', 2), {'modules': 62}], [('D3$20d', 3), {'error': 'start-stop'}]], [[('a/D', 3), {'error': 'start-stop'}], [('A9T', 2.5), {'error': 'start-stop'}], [('B5C', 3), {'modules': 39}], [('A-$1A', 3), {'modules': 63}], [('A035/$C', 1.5), {'error': 'ratio'}], [('C55-T', 4), {'error': 'ratio'}], [('a/803T', 3), {'error': 'start-stop'}], [('A97+$5d', 2.5), {'error': 'start-stop'}]]]
labels = ["regression: start and stop letters", "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)

prompt:
Symbols framed with lowercase letters are passed to a font that has no glyphs for them.

Validate and size a Codabar symbol text with a wide:narrow ratio between 2 and 3 inclusive. The first and last characters must be start/stop letters A-D (uppercase only, at least two characters); body characters are 0-9 - $ : / . +. Each character has 7 elements: digits, "-" and "$" have 2 wide elements, ": / . +" and A-D have 3. One narrow gap separates adjacent characters. Return the total width in narrow modules or an error.

split: open-access


prompt:
The symbol is one narrow module wider than the layout expects.

Validate and size a Codabar symbol text with a wide:narrow ratio between 2 and 3 inclusive. The first and last characters must be start/stop letters A-D (uppercase only, at least two characters); body characters are 0-9 - $ : / . +. Each character has 7 elements: digits, "-" and "$" have 2 wide elements, ": / . +" and A-D have 3. One narrow gap separates adjacent characters. Return the total width in narrow modules or an error.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(text, ratio):
    if not 2 <= ratio <= 3:
        return {'error': 'ratio'}
    if len(text) < 3:
        return {'error': 'short'}
    if text[0] not in 'ABCD' or text[-1] not in 'ABCD':
        return {'error': 'start-stop'}
    body = text[1:-1]
    for ch in body:
        if ch not in '0123456789-$:/.+':
            return {'error': 'char', 'char': ch}
    total = 0
    for ch in text:
        wides = 2 if ch in '0123456789-$' else 3
        total += (7 - wides) + wides * ratio
    return {'modules': total + len(text) - 1}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('ad', 3), {'error': 'start-stop'}], [('A', 3), {'error': 'short'}], [('DA/40D', 2.5), {'error': 'char', 'char': 'A'}], [('AE2$5C', 3), {'error': 'char', 'char': 'E'}], [('a+d', 2.5), {'error': 'start-stop'}], [('C5525D', 1.5), {'error': 'ratio'}], [('D$554A', 4), {'error': 'ratio'}], [('AA', 3), {'modules': 27}]], [[('CA', 3), {'modules': 27}], [('A', 3), {'error': 'short'}], [('a$5D', 1.5), {'error': 'ratio'}], [('AAA$03d', 4), {'error': 'ratio'}], [('A+3d', 2), {'error': 'start-stop'}], [('a3/AC', 3), {'error': 'start-stop'}], [('A/59$T', 3), {'error': 'start-stop'}], [('BT', 3), {'error': 'start-stop'}]], [[('AT', 2.5), {'error': 'start-stop'}], [('A', 3), {'error': 'short'}], [('A$7:+d', 1.5), {'error': 'ratio'}], [('a+A', 4), {'error': 'ratio'}], [('A9505D', 2), {'modules': 61}], [('a958$3C', 1.5), {'error': 'ratio'}], [('D5357T', 1.5), {'error': 'ratio'}], [('BT', 3), {'error': 'start-stop'}]], [[('AB', 2.5), {'modules': 24.0}], [('A', 3), {'error': 'short'}], [('D55B', 3), {'modules': 51}], [('B+-+-5B', 1.5), {'error': 'ratio'}], [('A95-42T', 1.5), {'error': 'ratio'}], [('A:5B', 2), {'modules': 42}], [('C528+D', 2), {'modules': 62}], [('aB', 2.5), {'error': 'start-stop'}]], [[('Cd', 3), {'error': 'start-stop'}], [('A', 3), {'error': 'short'}], [('A97+$5d', 2.5), {'error': 'start-stop'}], [('B5C', 3), {'modules': 39}], [('a/D', 3), {'error': 'start-stop'}], [('A117.T', 2.5), {'error': 'start-stop'}], [('A-$1A', 3), {'modules': 63}], [('aB', 3), {'error': 'start-stop'}]]]
labels = ["regression: minimum symbol length", "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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(text, ratio):
    if not 2 <= ratio <= 3:
        return {'error': 'ratio'}
    if len(text) < 1:
        return {'error': 'short'}
    if text[0] not in 'ABCD' or text[-1] not in 'ABCD':
        return {'error': 'start-stop'}
    body = text[1:-1]
    for ch in body:
        if ch not in '0123456789-$:/.+':
            return {'error': 'char', 'char': ch}
    total = 0
    for ch in text:
        wides = 2 if ch in '0123456789-$' else 3
        total += (7 - wides) + wides * ratio
    return {'modules': total + len(text) - 1}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('ad', 3), {'error': 'start-stop'}], [('A', 3), {'error': 'short'}], [('DA/40D', 2.5), {'error': 'char', 'char': 'A'}], [('AE2$5C', 3), {'error': 'char', 'char': 'E'}], [('a+d', 2.5), {'error': 'start-stop'}], [('C5525D', 1.5), {'error': 'ratio'}], [('D$554A', 4), {'error': 'ratio'}], [('AA', 3), {'modules': 27}]], [[('CA', 3), {'modules': 27}], [('A', 3), {'error': 'short'}], [('a$5D', 1.5), {'error': 'ratio'}], [('AAA$03d', 4), {'error': 'ratio'}], [('A+3d', 2), {'error': 'start-stop'}], [('a3/AC', 3), {'error': 'start-stop'}], [('A/59$T', 3), {'error': 'start-stop'}], [('BT', 3), {'error': 'start-stop'}]], [[('AT', 2.5), {'error': 'start-stop'}], [('A', 3), {'error': 'short'}], [('A$7:+d', 1.5), {'error': 'ratio'}], [('a+A', 4), {'error': 'ratio'}], [('A9505D', 2), {'modules': 61}], [('a958$3C', 1.5), {'error': 'ratio'}], [('D5357T', 1.5), {'error': 'ratio'}], [('BT', 3), {'error': 'start-stop'}]], [[('AB', 2.5), {'modules': 24.0}], [('A', 3), {'error': 'short'}], [('D55B', 3), {'modules': 51}], [('B+-+-5B', 1.5), {'error': 'ratio'}], [('A95-42T', 1.5), {'error': 'ratio'}], [('A:5B', 2), {'modules': 42}], [('C528+D', 2), {'modules': 62}], [('aB', 2.5), {'error': 'start-stop'}]], [[('Cd', 3), {'error': 'start-stop'}], [('A', 3), {'error': 'short'}], [('A97+$5d', 2.5), {'error': 'start-stop'}], [('B5C', 3), {'modules': 39}], [('a/D', 3), {'error': 'start-stop'}], [('A117.T', 2.5), {'error': 'start-stop'}], [('A-$1A', 3), {'modules': 63}], [('aB', 3), {'error': 'start-stop'}]]]
labels = ["regression: minimum symbol length", "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)

prompt:
A start/stop pair used as a separator label cannot be printed.

Validate and size a Codabar symbol text with a wide:narrow ratio between 2 and 3 inclusive. The first and last characters must be start/stop letters A-D (uppercase only, at least two characters); body characters are 0-9 - $ : / . +. Each character has 7 elements: digits, "-" and "$" have 2 wide elements, ": / . +" and A-D have 3. One narrow gap separates adjacent characters. Return the total width in narrow modules or an error.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(text, ratio):
    if not 2 <= ratio <= 3:
        return {'error': 'ratio'}
    if len(text) < 2:
        return {'error': 'short'}
    if text[0] not in 'ABCD' or text[-1] not in 'ABCD':
        return {'error': 'start-stop'}
    body = text[1:-1]
    for ch in body:
        if ch not in '0123456789-$:/.+':
            return {'error': 'char', 'char': ch}
    total = 0
    for ch in text:
        wides = 2 if ch in '0123456789-$' else (2 if ch in 'ABCD' else 3)
        total += (7 - wides) + wides * ratio
    return {'modules': total + len(text) - 1}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('C+B', 3), {'modules': 41}], [('B:0C', 3), {'modules': 53}], [('DA/40D', 2.5), {'error': 'char', 'char': 'A'}], [('AE2$5C', 3), {'error': 'char', 'char': 'E'}], [('a+d', 2.5), {'error': 'start-stop'}], [('ad', 3), {'error': 'start-stop'}], [('C5525D', 1.5), {'error': 'ratio'}], [('B5355D', 3), {'modules': 75}]], [[('CD', 2), {'modules': 21}], [('C//5D', 2.5), {'modules': 60.0}], [('AAA$03d', 4), {'error': 'ratio'}], [('A+3d', 2), {'error': 'start-stop'}], [('a3/AC', 3), {'error': 'start-stop'}], [('A/59$T', 3), {'error': 'start-stop'}], [('C773C', 1.5), {'error': 'ratio'}], [('CA', 3), {'modules': 27}]], [[('B957A', 2.5), {'modules': 57.0}], [('B53C', 2), {'modules': 41}], [('A$7:+d', 1.5), {'error': 'ratio'}], [('a+A', 4), {'error': 'ratio'}], [('a958$3C', 1.5), {'error': 'ratio'}], [('D5357T', 1.5), {'error': 'ratio'}], [('a5C', 2), {'error': 'start-stop'}], [('D5-B', 2.5), {'modules': 46.0}]], [[('A:5B', 2), {'modules': 42}], [('B$D', 2), {'modules': 31}], [('aT', 2.5), {'error': 'start-stop'}], [('D3$20d', 3), {'error': 'start-stop'}], [('C58d', 1.5), {'error': 'ratio'}], [('D/5:3B', 4), {'error': 'ratio'}], [('AA', 1.5), {'error': 'ratio'}], [('A1D', 3), {'modules': 39}]], [[('A-31A', 3), {'modules': 63}], [('A905C', 3), {'modules': 63}], [('aB', 3), {'error': 'start-stop'}], [('Cd', 2), {'error': 'start-stop'}], [('a/D', 3), {'error': 'start-stop'}], [('A117.T', 2.5), {'error': 'start-stop'}], [('aD', 3), {'error': 'start-stop'}], [('C55C', 3), {'modules': 51}]]]
labels = ["regression: start and stop wide count", "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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(text, ratio):
    if not 2 <= ratio <= 3:
        return {'error': 'ratio'}
    if len(text) < 2:
        return {'error': 'short'}
    if text[0] not in 'ABCD' or text[-1] not in 'ABCD':
        return {'error': 'start-stop'}
    body = text[1:-1]
    for ch in body:
        if ch not in '0123456789-$:/.+':
            return {'error': 'char', 'char': ch}
    total = 0
    for ch in text:
        wides = 2 if ch in '0123456789-$' else (4 if ch in 'ABCD' else 3)
        total += (7 - wides) + wides * ratio
    return {'modules': total + len(text) - 1}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('C+B', 3), {'modules': 41}], [('B:0C', 3), {'modules': 53}], [('DA/40D', 2.5), {'error': 'char', 'char': 'A'}], [('AE2$5C', 3), {'error': 'char', 'char': 'E'}], [('a+d', 2.5), {'error': 'start-stop'}], [('ad', 3), {'error': 'start-stop'}], [('C5525D', 1.5), {'error': 'ratio'}], [('B5355D', 3), {'modules': 75}]], [[('CD', 2), {'modules': 21}], [('C//5D', 2.5), {'modules': 60.0}], [('AAA$03d', 4), {'error': 'ratio'}], [('A+3d', 2), {'error': 'start-stop'}], [('a3/AC', 3), {'error': 'start-stop'}], [('A/59$T', 3), {'error': 'start-stop'}], [('C773C', 1.5), {'error': 'ratio'}], [('CA', 3), {'modules': 27}]], [[('B957A', 2.5), {'modules': 57.0}], [('B53C', 2), {'modules': 41}], [('A$7:+d', 1.5), {'error': 'ratio'}], [('a+A', 4), {'error': 'ratio'}], [('a958$3C', 1.5), {'error': 'ratio'}], [('D5357T', 1.5), {'error': 'ratio'}], [('a5C', 2), {'error': 'start-stop'}], [('D5-B', 2.5), {'modules': 46.0}]], [[('A:5B', 2), {'modules': 42}], [('B$D', 2), {'modules': 31}], [('aT', 2.5), {'error': 'start-stop'}], [('D3$20d', 3), {'error': 'start-stop'}], [('C58d', 1.5), {'error': 'ratio'}], [('D/5:3B', 4), {'error': 'ratio'}], [('AA', 1.5), {'error': 'ratio'}], [('A1D', 3), {'modules': 39}]], [[('A-31A', 3), {'modules': 63}], [('A905C', 3), {'modules': 63}], [('aB', 3), {'error': 'start-stop'}], [('Cd', 2), {'error': 'start-stop'}], [('a/D', 3), {'error': 'start-stop'}], [('A117.T', 2.5), {'error': 'start-stop'}], [('aD', 3), {'error': 'start-stop'}], [('C55C', 3), {'modules': 51}]]]
labels = ["regression: start and stop wide count", "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)

prompt:
Every symbol is two wide elements shorter than printed, so the layout clips the stop character.

Validate and size a Codabar symbol text with a wide:narrow ratio between 2 and 3 inclusive. The first and last characters must be start/stop letters A-D (uppercase only, at least two characters); body characters are 0-9 - $ : / . +. Each character has 7 elements: digits, "-" and "$" have 2 wide elements, ": / . +" and A-D have 3. One narrow gap separates adjacent characters. Return the total width in narrow modules or an error.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(text, ratio):
    if ratio < 2:
        return {'error': 'ratio'}
    if len(text) < 2:
        return {'error': 'short'}
    if text[0] not in 'ABCD' or text[-1] not in 'ABCD':
        return {'error': 'start-stop'}
    body = text[1:-1]
    for ch in body:
        if ch not in '0123456789-$:/.+':
            return {'error': 'char', 'char': ch}
    total = 0
    for ch in text:
        wides = 2 if ch in '0123456789-$' else 3
        total += (7 - wides) + wides * ratio
    return {'modules': total + len(text) - 1}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('D$554A', 4), {'error': 'ratio'}], [('A5547:T', 2), {'error': 'start-stop'}], [('DA/40D', 2.5), {'error': 'char', 'char': 'A'}], [('AE2$5C', 3), {'error': 'char', 'char': 'E'}], [('a+d', 2.5), {'error': 'start-stop'}], [('ad', 3), {'error': 'start-stop'}], [('C5525D', 1.5), {'error': 'ratio'}], [('D97.5D', 4), {'error': 'ratio'}]], [[('D.48E6C', 4), {'error': 'ratio'}], [('CD', 2), {'modules': 21}], [('a3/AC', 3), {'error': 'start-stop'}], [('A/59$T', 3), {'error': 'start-stop'}], [('C773C', 1.5), {'error': 'ratio'}], [('a2$A', 1.5), {'error': 'ratio'}], [('BE3Ed', 2.5), {'error': 'start-stop'}], [('A63$T', 4), {'error': 'ratio'}]], [[('a6C', 4), {'error': 'ratio'}], [('aEd', 2), {'error': 'start-stop'}], [('a958$3C', 1.5), {'error': 'ratio'}], [('D5357T', 1.5), {'error': 'ratio'}], [('A:5A$D', 3), {'error': 'char', 'char': 'A'}], [('A$0552T', 2.5), {'error': 'start-stop'}], [('A/.ET', 1.5), {'error': 'ratio'}], [('a+A', 4), {'error': 'ratio'}]], [[('A9d', 4), {'error': 'ratio'}], [('D67C', 2), {'modules': 41}], [('D55B', 3), {'modules': 51}], [('B+-+-5B', 1.5), {'error': 'ratio'}], [('A95-42T', 1.5), {'error': 'ratio'}], [('aT', 2.5), {'error': 'start-stop'}], [('A55+5A', 3), {'modules': 77}], [('a/55--d', 4), {'error': 'ratio'}]], [[('C0.9.D', 4), {'error': 'ratio'}], [('a5C', 2), {'error': 'start-stop'}], [('A97+$5d', 2.5), {'error': 'start-stop'}], [('B5C', 3), {'modules': 39}], [('aB', 3), {'error': 'start-stop'}], [('a/D', 3), {'error': 'start-stop'}], [('A117.T', 2.5), {'error': 'start-stop'}], [('AT', 4), {'error': 'ratio'}]]]
labels = ["regression: ratio validation bounds", "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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(text, ratio):
    if not 2 < ratio <= 3:
        return {'error': 'ratio'}
    if len(text) < 2:
        return {'error': 'short'}
    if text[0] not in 'ABCD' or text[-1] not in 'ABCD':
        return {'error': 'start-stop'}
    body = text[1:-1]
    for ch in body:
        if ch not in '0123456789-$:/.+':
            return {'error': 'char', 'char': ch}
    total = 0
    for ch in text:
        wides = 2 if ch in '0123456789-$' else 3
        total += (7 - wides) + wides * ratio
    return {'modules': total + len(text) - 1}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('D$554A', 4), {'error': 'ratio'}], [('A5547:T', 2), {'error': 'start-stop'}], [('DA/40D', 2.5), {'error': 'char', 'char': 'A'}], [('AE2$5C', 3), {'error': 'char', 'char': 'E'}], [('a+d', 2.5), {'error': 'start-stop'}], [('ad', 3), {'error': 'start-stop'}], [('C5525D', 1.5), {'error': 'ratio'}], [('D97.5D', 4), {'error': 'ratio'}]], [[('D.48E6C', 4), {'error': 'ratio'}], [('CD', 2), {'modules': 21}], [('a3/AC', 3), {'error': 'start-stop'}], [('A/59$T', 3), {'error': 'start-stop'}], [('C773C', 1.5), {'error': 'ratio'}], [('a2$A', 1.5), {'error': 'ratio'}], [('BE3Ed', 2.5), {'error': 'start-stop'}], [('A63$T', 4), {'error': 'ratio'}]], [[('a6C', 4), {'error': 'ratio'}], [('aEd', 2), {'error': 'start-stop'}], [('a958$3C', 1.5), {'error': 'ratio'}], [('D5357T', 1.5), {'error': 'ratio'}], [('A:5A$D', 3), {'error': 'char', 'char': 'A'}], [('A$0552T', 2.5), {'error': 'start-stop'}], [('A/.ET', 1.5), {'error': 'ratio'}], [('a+A', 4), {'error': 'ratio'}]], [[('A9d', 4), {'error': 'ratio'}], [('D67C', 2), {'modules': 41}], [('D55B', 3), {'modules': 51}], [('B+-+-5B', 1.5), {'error': 'ratio'}], [('A95-42T', 1.5), {'error': 'ratio'}], [('aT', 2.5), {'error': 'start-stop'}], [('A55+5A', 3), {'modules': 77}], [('a/55--d', 4), {'error': 'ratio'}]], [[('C0.9.D', 4), {'error': 'ratio'}], [('a5C', 2), {'error': 'start-stop'}], [('A97+$5d', 2.5), {'error': 'start-stop'}], [('B5C', 3), {'modules': 39}], [('aB', 3), {'error': 'start-stop'}], [('a/D', 3), {'error': 'start-stop'}], [('A117.T', 2.5), {'error': 'start-stop'}], [('AT', 4), {'error': 'ratio'}]]]
labels = ["regression: ratio validation bounds", "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)

prompt:
Oversized wide elements push the symbol beyond its allocated width.

Validate and size a Codabar symbol text with a wide:narrow ratio between 2 and 3 inclusive. The first and last characters must be start/stop letters A-D (uppercase only, at least two characters); body characters are 0-9 - $ : / . +. Each character has 7 elements: digits, "-" and "$" have 2 wide elements, ": / . +" and A-D have 3. One narrow gap separates adjacent characters. Return the total width in narrow modules or an error.

split: open-access


prompt:
Labels waste a symbol character after every GTIN and date and some parsers reject the extra separator.

Assemble GS1-128 data from [AI, value] pairs; "#" stands for FNC1. The string starts with FNC1. Predefined fixed-length AIs: 00 (18), 01 and 02 (14), 11/13/15/17 (6), 3103 (6); variable-length AIs with maximum length: 10 and 21 (20), 30 and 37 (8), 400 (30). Numeric AIs: 00, 01, 02, 11, 13, 15, 17, 3103, 30, 37. Values use printable ASCII 33..126 except "#". A variable-length field is followed by FNC1 unless it is last. Errors: unknown-ai, bad-value.

split: open-access


prompt:
Batch or serial fields at the end of the label are followed by a separator that decoders report as an empty field.

Assemble GS1-128 data from [AI, value] pairs; "#" stands for FNC1. The string starts with FNC1. Predefined fixed-length AIs: 00 (18), 01 and 02 (14), 11/13/15/17 (6), 3103 (6); variable-length AIs with maximum length: 10 and 21 (20), 30 and 37 (8), 400 (30). Numeric AIs: 00, 01, 02, 11, 13, 15, 17, 3103, 30, 37. Values use printable ASCII 33..126 except "#". A variable-length field is followed by FNC1 unless it is last. Errors: unknown-ai, bad-value.

split: open-access


prompt:
YYMMDD expiry dates are rejected while YYYYMMDD values are accepted.

Assemble GS1-128 data from [AI, value] pairs; "#" stands for FNC1. The string starts with FNC1. Predefined fixed-length AIs: 00 (18), 01 and 02 (14), 11/13/15/17 (6), 3103 (6); variable-length AIs with maximum length: 10 and 21 (20), 30 and 37 (8), 400 (30). Numeric AIs: 00, 01, 02, 11, 13, 15, 17, 3103, 30, 37. Values use printable ASCII 33..126 except "#". A variable-length field is followed by FNC1 unless it is last. Errors: unknown-ai, bad-value.

split: open-access


prompt:
A blank batch field yields an AI with no data followed by FNC1.

Assemble GS1-128 data from [AI, value] pairs; "#" stands for FNC1. The string starts with FNC1. Predefined fixed-length AIs: 00 (18), 01 and 02 (14), 11/13/15/17 (6), 3103 (6); variable-length AIs with maximum length: 10 and 21 (20), 30 and 37 (8), 400 (30). Numeric AIs: 00, 01, 02, 11, 13, 15, 17, 3103, 30, 37. Values use printable ASCII 33..126 except "#". A variable-length field is followed by FNC1 unless it is last. Errors: unknown-ai, bad-value.

split: open-access


prompt:
A quantity field with a letter passes validation and fails downstream EDI parsing.

Assemble GS1-128 data from [AI, value] pairs; "#" stands for FNC1. The string starts with FNC1. Predefined fixed-length AIs: 00 (18), 01 and 02 (14), 11/13/15/17 (6), 3103 (6); variable-length AIs with maximum length: 10 and 21 (20), 30 and 37 (8), 400 (30). Numeric AIs: 00, 01, 02, 11, 13, 15, 17, 3103, 30, 37. Values use printable ASCII 33..126 except "#". A variable-length field is followed by FNC1 unless it is last. Errors: unknown-ai, bad-value.

split: open-access


prompt:
A serial number containing "#" is decoded as two fields.

Assemble GS1-128 data from [AI, value] pairs; "#" stands for FNC1. The string starts with FNC1. Predefined fixed-length AIs: 00 (18), 01 and 02 (14), 11/13/15/17 (6), 3103 (6); variable-length AIs with maximum length: 10 and 21 (20), 30 and 37 (8), 400 (30). Numeric AIs: 00, 01, 02, 11, 13, 15, 17, 3103, 30, 37. Values use printable ASCII 33..126 except "#". A variable-length field is followed by FNC1 unless it is last. Errors: unknown-ai, bad-value.

split: open-access


prompt:
Internal Code 128 labels whose text happens to start with digits are interpreted as GTINs.

Parse scanner output of a GS1-128 symbol: it must start with the symbology identifier "]C1"; FNC1 separators arrive as GS (0x1D) and redundant separators are skipped. AIs are recognised by the shortest matching prefix among the predefined fixed-length AIs (00:18, 01/02:14, 11/13/15/17:6, 3103:6) and variable AIs (10/21 max 20, 30/37 max 8, 400 max 30). A fixed field must be complete and contain no GS; a variable field runs to the next GS or the end and must have 1..max characters. Return [[ai, value], ...] or an error.

split: open-access


prompt:
Labels from printers that add FNC1 after every field fail to parse.

Parse scanner output of a GS1-128 symbol: it must start with the symbology identifier "]C1"; FNC1 separators arrive as GS (0x1D) and redundant separators are skipped. AIs are recognised by the shortest matching prefix among the predefined fixed-length AIs (00:18, 01/02:14, 11/13/15/17:6, 3103:6) and variable AIs (10/21 max 20, 30/37 max 8, 400 max 30). A fixed field must be complete and contain no GS; a variable field runs to the next GS or the end and must have 1..max characters. Return [[ai, value], ...] or an error.

split: open-access


prompt:
A truncated GTIN followed by a separator parses as a GTIN containing GS and shifts every later field.

Parse scanner output of a GS1-128 symbol: it must start with the symbology identifier "]C1"; FNC1 separators arrive as GS (0x1D) and redundant separators are skipped. AIs are recognised by the shortest matching prefix among the predefined fixed-length AIs (00:18, 01/02:14, 11/13/15/17:6, 3103:6) and variable AIs (10/21 max 20, 30/37 max 8, 400 max 30). A fixed field must be complete and contain no GS; a variable field runs to the next GS or the end and must have 1..max characters. Return [[ai, value], ...] or an error.

split: open-access


prompt:
A missing separator after AI 30 merges the next field into the count without an error.

Parse scanner output of a GS1-128 symbol: it must start with the symbology identifier "]C1"; FNC1 separators arrive as GS (0x1D) and redundant separators are skipped. AIs are recognised by the shortest matching prefix among the predefined fixed-length AIs (00:18, 01/02:14, 11/13/15/17:6, 3103:6) and variable AIs (10/21 max 20, 30/37 max 8, 400 max 30). A fixed field must be complete and contain no GS; a variable field runs to the next GS or the end and must have 1..max characters. Return [[ai, value], ...] or an error.

split: open-access


prompt:
A blank batch number followed by GS is parsed as a batch containing the next field.

Parse scanner output of a GS1-128 symbol: it must start with the symbology identifier "]C1"; FNC1 separators arrive as GS (0x1D) and redundant separators are skipped. AIs are recognised by the shortest matching prefix among the predefined fixed-length AIs (00:18, 01/02:14, 11/13/15/17:6, 3103:6) and variable AIs (10/21 max 20, 30/37 max 8, 400 max 30). A fixed field must be complete and contain no GS; a variable field runs to the next GS or the end and must have 1..max characters. Return [[ai, value], ...] or an error.

split: open-access


prompt:
A partially read symbol yields a 12-digit GTIN without error.

Parse scanner output of a GS1-128 symbol: it must start with the symbology identifier "]C1"; FNC1 separators arrive as GS (0x1D) and redundant separators are skipped. AIs are recognised by the shortest matching prefix among the predefined fixed-length AIs (00:18, 01/02:14, 11/13/15/17:6, 3103:6) and variable AIs (10/21 max 20, 30/37 max 8, 400 max 30). A fixed field must be complete and contain no GS; a variable field runs to the next GS or the end and must have 1..max characters. Return [[ai, value], ...] or an error.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(mode, data, version):
    if not 1 <= version <= 40:
        return {'error': 'version'}
    band = 0 if version <= 9 else (1 if version <= 26 else 2)
    ALNUM = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:'
    if mode == 'numeric':
        if not all(c in '0123456789' for c in data):
            return {'error': 'charset'}
        count = len(data)
        bits = 10 * (count // 3) + [0, 4, 8][count % 3]
        cci = [10, 12, 14][band]
    elif mode == 'alnum':
        if not all(c in ALNUM for c in data):
            return {'error': 'charset'}
        count = len(data)
        bits = 11 * (count // 2) + 6 * (count % 2)
        cci = [9, 11, 13][band]
    elif mode == 'byte':
        count = len(data.encode('utf-8'))
        bits = 8 * count
        cci = [8, 16, 16][band]
    else:
        return {'error': 'mode'}
    if count >= 1 << cci:
        return {'error': 'too-long'}
    return 4 + cci + bits
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('numeric', '51951717', 40), 45], [('numeric', '1322507885', 27), 52], [('alnum', '-/$é+/%é+', 0), {'error': 'version'}], [('alnum', '-', 1), 19], [('alnum', '%', 1), 19], [('byte', '1€11€é', 40), 108], [('alnum', 'ééA- q', 9), {'error': 'charset'}], [('numeric', '97888196275', 27), 55]], [[('numeric', '41605446623', 10), 53], [('numeric', '7840130886', 40), 52], [('numeric', '053142', 0), {'error': 'version'}], [('numeric', '089405', 10), 36], [('kanji', 'b1ab11', 5), {'error': 'mode'}], [('alnum', 'q+$ ', 40), {'error': 'charset'}], [('alnum', '++$:é1*.+', 10), {'error': 'charset'}], [('numeric', '51', 40), 25]], [[('numeric', '53', 26), 23], [('numeric', '6256737', 1), 38], [('numeric', '', 40), 18], [('numeric', '716925614701', 5), 54], [('kanji', 'é b€b', 10), {'error': 'mode'}], [('byte', '', 26), 20], [('alnum', '%/2*+% $', 0), {'error': 'version'}], [('numeric', '37219', 5), 31]], [[('numeric', '86667136', 5), 41], [('numeric', '9736438869', 15), 50], [('byte', 'abbbaaa', 26), 76], [('byte', '€', 41), {'error': 'version'}], [('numeric', '', 0), {'error': 'version'}], [('alnum', '%1.qZ-', 5), {'error': 'charset'}], [('alnum', 'A:*éZA', 40), {'error': 'charset'}], [('numeric', '82758', 27), 35]], [[('numeric', '30390', 26), 33], [('numeric', '5', 1), 18], [('kanji', 'é ba', 40), {'error': 'mode'}], [('kanji', 'éb', 1), {'error': 'mode'}], [('byte', 'a€', 26), 52], [('alnum', '.', 5), 19], [('byte', '€é1', 27), 68], [('numeric', '14974', 9), 31]]]
labels = ["regression: numeric remainder bits", "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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(mode, data, version):
    if not 1 <= version <= 40:
        return {'error': 'version'}
    band = 0 if version <= 9 else (1 if version <= 26 else 2)
    ALNUM = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:'
    if mode == 'numeric':
        if not all(c in '0123456789' for c in data):
            return {'error': 'charset'}
        count = len(data)
        bits = 10 * (count // 3) + [0, 3, 7][count % 3]
        cci = [10, 12, 14][band]
    elif mode == 'alnum':
        if not all(c in ALNUM for c in data):
            return {'error': 'charset'}
        count = len(data)
        bits = 11 * (count // 2) + 6 * (count % 2)
        cci = [9, 11, 13][band]
    elif mode == 'byte':
        count = len(data.encode('utf-8'))
        bits = 8 * count
        cci = [8, 16, 16][band]
    else:
        return {'error': 'mode'}
    if count >= 1 << cci:
        return {'error': 'too-long'}
    return 4 + cci + bits
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('numeric', '51951717', 40), 45], [('numeric', '1322507885', 27), 52], [('alnum', '-/$é+/%é+', 0), {'error': 'version'}], [('alnum', '-', 1), 19], [('alnum', '%', 1), 19], [('byte', '1€11€é', 40), 108], [('alnum', 'ééA- q', 9), {'error': 'charset'}], [('numeric', '97888196275', 27), 55]], [[('numeric', '41605446623', 10), 53], [('numeric', '7840130886', 40), 52], [('numeric', '053142', 0), {'error': 'version'}], [('numeric', '089405', 10), 36], [('kanji', 'b1ab11', 5), {'error': 'mode'}], [('alnum', 'q+$ ', 40), {'error': 'charset'}], [('alnum', '++$:é1*.+', 10), {'error': 'charset'}], [('numeric', '51', 40), 25]], [[('numeric', '53', 26), 23], [('numeric', '6256737', 1), 38], [('numeric', '', 40), 18], [('numeric', '716925614701', 5), 54], [('kanji', 'é b€b', 10), {'error': 'mode'}], [('byte', '', 26), 20], [('alnum', '%/2*+% $', 0), {'error': 'version'}], [('numeric', '37219', 5), 31]], [[('numeric', '86667136', 5), 41], [('numeric', '9736438869', 15), 50], [('byte', 'abbbaaa', 26), 76], [('byte', '€', 41), {'error': 'version'}], [('numeric', '', 0), {'error': 'version'}], [('alnum', '%1.qZ-', 5), {'error': 'charset'}], [('alnum', 'A:*éZA', 40), {'error': 'charset'}], [('numeric', '82758', 27), 35]], [[('numeric', '30390', 26), 33], [('numeric', '5', 1), 18], [('kanji', 'é ba', 40), {'error': 'mode'}], [('kanji', 'éb', 1), {'error': 'mode'}], [('byte', 'a€', 26), 52], [('alnum', '.', 5), 19], [('byte', '€é1', 27), 68], [('numeric', '14974', 9), 31]]]
labels = ["regression: numeric remainder bits", "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)

prompt:
Capacity checks reject payloads that would still fit, forcing a larger symbol version.

Compute the length in bits of one QR segment: 4-bit mode indicator, a character count indicator whose width depends on mode and version band (1-9, 10-26, 27-40): numeric 10/12/14, alphanumeric 9/11/13, byte 8/16/16, and the data bits: numeric 10 bits per 3 digits plus 4 or 7 for a remainder of 1 or 2, alphanumeric 11 bits per pair plus 6 for a single, byte 8 bits per UTF-8 byte. Alphanumeric allows 0-9 A-Z space $ % * + - . / :. A count that does not fit the indicator is too-long. Errors: version, charset, mode, too-long.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(mode, data, version):
    if not 1 <= version <= 40:
        return {'error': 'version'}
    band = 0 if version < 9 else (1 if version < 26 else 2)
    ALNUM = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:'
    if mode == 'numeric':
        if not all(c in '0123456789' for c in data):
            return {'error': 'charset'}
        count = len(data)
        bits = 10 * (count // 3) + [0, 4, 7][count % 3]
        cci = [10, 12, 14][band]
    elif mode == 'alnum':
        if not all(c in ALNUM for c in data):
            return {'error': 'charset'}
        count = len(data)
        bits = 11 * (count // 2) + 6 * (count % 2)
        cci = [9, 11, 13][band]
    elif mode == 'byte':
        count = len(data.encode('utf-8'))
        bits = 8 * count
        cci = [8, 16, 16][band]
    else:
        return {'error': 'mode'}
    if count >= 1 << cci:
        return {'error': 'too-long'}
    return 4 + cci + bits
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('numeric', '443978087443', 26), 56], [('numeric', '115232806735', 10), 56], [('alnum', '-/$é+/%é+', 0), {'error': 'version'}], [('alnum', '-', 1), 19], [('alnum', '%', 1), 19], [('byte', '1€11€é', 40), 108], [('alnum', 'ééA- q', 9), {'error': 'charset'}], [('byte', '€éa1a1 ', 9), 92]], [[('numeric', '7643868', 9), 38], [('alnum', '*::2Z%:*', 10), 59], [('numeric', '053142', 0), {'error': 'version'}], [('kanji', 'b1ab11', 5), {'error': 'mode'}], [('alnum', 'q+$ ', 40), {'error': 'charset'}], [('alnum', '++$:é1*.+', 10), {'error': 'charset'}], [('alnum', '+qB+', 0), {'error': 'version'}], [('byte', 'bé', 9), 36]], [[('alnum', '*Z+-', 9), 35], [('numeric', '9420', 10), 30], [('numeric', '37219', 5), 31], [('numeric', '', 40), 18], [('numeric', '716925614701', 5), 54], [('kanji', 'é b€b', 10), {'error': 'mode'}], [('byte', '', 26), 20], [('numeric', '53', 26), 23]], [[('alnum', '$A.', 9), 30], [('byte', ' 11b€€', 10), 100], [('byte', 'abbbaaa', 26), 76], [('byte', '€', 41), {'error': 'version'}], [('numeric', '', 0), {'error': 'version'}], [('numeric', '2', 1), 18], [('alnum', '%1.qZ-', 5), {'error': 'charset'}], [('alnum', ' *$$:*/Z$', 26), 65]], [[('alnum', '+Z2Z2B', 26), 48], [('alnum', '+', 10), 21], [('kanji', 'é ba', 40), {'error': 'mode'}], [('kanji', 'éb', 1), {'error': 'mode'}], [('byte', 'a€', 26), 52], [('alnum', '.', 5), 19], [('byte', '€é1', 27), 68], [('numeric', '14974', 9), 31]]]
labels = ["regression: count indicator version band", "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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(mode, data, version):
    if not 1 <= version <= 40:
        return {'error': 'version'}
    band = 0 if version <= 10 else (1 if version <= 26 else 2)
    ALNUM = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:'
    if mode == 'numeric':
        if not all(c in '0123456789' for c in data):
            return {'error': 'charset'}
        count = len(data)
        bits = 10 * (count // 3) + [0, 4, 7][count % 3]
        cci = [10, 12, 14][band]
    elif mode == 'alnum':
        if not all(c in ALNUM for c in data):
            return {'error': 'charset'}
        count = len(data)
        bits = 11 * (count // 2) + 6 * (count % 2)
        cci = [9, 11, 13][band]
    elif mode == 'byte':
        count = len(data.encode('utf-8'))
        bits = 8 * count
        cci = [8, 16, 16][band]
    else:
        return {'error': 'mode'}
    if count >= 1 << cci:
        return {'error': 'too-long'}
    return 4 + cci + bits
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('numeric', '443978087443', 26), 56], [('numeric', '115232806735', 10), 56], [('alnum', '-/$é+/%é+', 0), {'error': 'version'}], [('alnum', '-', 1), 19], [('alnum', '%', 1), 19], [('byte', '1€11€é', 40), 108], [('alnum', 'ééA- q', 9), {'error': 'charset'}], [('byte', '€éa1a1 ', 9), 92]], [[('numeric', '7643868', 9), 38], [('alnum', '*::2Z%:*', 10), 59], [('numeric', '053142', 0), {'error': 'version'}], [('kanji', 'b1ab11', 5), {'error': 'mode'}], [('alnum', 'q+$ ', 40), {'error': 'charset'}], [('alnum', '++$:é1*.+', 10), {'error': 'charset'}], [('alnum', '+qB+', 0), {'error': 'version'}], [('byte', 'bé', 9), 36]], [[('alnum', '*Z+-', 9), 35], [('numeric', '9420', 10), 30], [('numeric', '37219', 5), 31], [('numeric', '', 40), 18], [('numeric', '716925614701', 5), 54], [('kanji', 'é b€b', 10), {'error': 'mode'}], [('byte', '', 26), 20], [('numeric', '53', 26), 23]], [[('alnum', '$A.', 9), 30], [('byte', ' 11b€€', 10), 100], [('byte', 'abbbaaa', 26), 76], [('byte', '€', 41), {'error': 'version'}], [('numeric', '', 0), {'error': 'version'}], [('numeric', '2', 1), 18], [('alnum', '%1.qZ-', 5), {'error': 'charset'}], [('alnum', ' *$$:*/Z$', 26), 65]], [[('alnum', '+Z2Z2B', 26), 48], [('alnum', '+', 10), 21], [('kanji', 'é ba', 40), {'error': 'mode'}], [('kanji', 'éb', 1), {'error': 'mode'}], [('byte', 'a€', 26), 52], [('alnum', '.', 5), 19], [('byte', '€é1', 27), 68], [('numeric', '14974', 9), 31]]]
labels = ["regression: count indicator version band", "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)

prompt:
Symbols at versions 9 and 26 are built with a count field two bits too wide and fail to decode.

Compute the length in bits of one QR segment: 4-bit mode indicator, a character count indicator whose width depends on mode and version band (1-9, 10-26, 27-40): numeric 10/12/14, alphanumeric 9/11/13, byte 8/16/16, and the data bits: numeric 10 bits per 3 digits plus 4 or 7 for a remainder of 1 or 2, alphanumeric 11 bits per pair plus 6 for a single, byte 8 bits per UTF-8 byte. Alphanumeric allows 0-9 A-Z space $ % * + - . / :. A count that does not fit the indicator is too-long. Errors: version, charset, mode, too-long.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(mode, data, version):
    if not 1 <= version <= 40:
        return {'error': 'version'}
    band = 0 if version <= 9 else (1 if version <= 26 else 2)
    ALNUM = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:'
    if mode == 'numeric':
        if not all(c in '0123456789' for c in data):
            return {'error': 'charset'}
        count = len(data)
        bits = 10 * (count // 3) + [0, 4, 7][count % 3]
        cci = [10, 12, 14][band]
    elif mode == 'alnum':
        if not all(c in ALNUM for c in data):
            return {'error': 'charset'}
        count = len(data)
        bits = 11 * (count // 2) + 11 * (count % 2)
        cci = [9, 11, 13][band]
    elif mode == 'byte':
        count = len(data.encode('utf-8'))
        bits = 8 * count
        cci = [8, 16, 16][band]
    else:
        return {'error': 'mode'}
    if count >= 1 << cci:
        return {'error': 'too-long'}
    return 4 + cci + bits
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('alnum', '-', 1), 19], [('alnum', '$', 15), 21], [('alnum', '-/$é+/%é+', 0), {'error': 'version'}], [('byte', '1€11€é', 40), 108], [('alnum', 'ééA- q', 9), {'error': 'charset'}], [('byte', '', 1), 12], [('numeric', '548976', 15), 36], [('alnum', '%', 1), 19]], [[('alnum', ':', 9), 19], [('alnum', 'A', 10), 21], [('numeric', '053142', 0), {'error': 'version'}], [('numeric', '089405', 10), 36], [('kanji', 'b1ab11', 5), {'error': 'mode'}], [('alnum', 'q+$ ', 40), {'error': 'charset'}], [('alnum', '++$:é1*.+', 10), {'error': 'charset'}], [('alnum', ' -/', 26), 32]], [[('alnum', 'A. ', 27), 34], [('alnum', 'A*%/ :Z', 15), 54], [('numeric', '00575', 9), 31], [('numeric', '37219', 5), 31], [('numeric', '', 40), 18], [('numeric', '716925614701', 5), 54], [('kanji', 'é b€b', 10), {'error': 'mode'}], [('alnum', '+:.:Z', 10), 43]], [[('alnum', '$A.', 9), 30], [('alnum', '.1A', 15), 32], [('byte', 'abbbaaa', 26), 76], [('byte', '€', 41), {'error': 'version'}], [('numeric', '', 0), {'error': 'version'}], [('numeric', '2', 1), 18], [('alnum', '%1.qZ-', 5), {'error': 'charset'}], [('alnum', ' ', 40), 23]], [[('alnum', '*:B', 10), 32], [('alnum', '/ -', 40), 34], [('kanji', 'é ba', 40), {'error': 'mode'}], [('kanji', 'éb', 1), {'error': 'mode'}], [('byte', 'a€', 26), 52], [('byte', '€é1', 27), 68], [('numeric', '4813206244', 15), 50], [('alnum', '+', 10), 21]]]
labels = ["regression: alphanumeric trailing character", "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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(mode, data, version):
    if not 1 <= version <= 40:
        return {'error': 'version'}
    band = 0 if version <= 9 else (1 if version <= 26 else 2)
    ALNUM = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:'
    if mode == 'numeric':
        if not all(c in '0123456789' for c in data):
            return {'error': 'charset'}
        count = len(data)
        bits = 10 * (count // 3) + [0, 4, 7][count % 3]
        cci = [10, 12, 14][band]
    elif mode == 'alnum':
        if not all(c in ALNUM for c in data):
            return {'error': 'charset'}
        count = len(data)
        bits = 11 * (count // 2) + 8 * (count % 2)
        cci = [9, 11, 13][band]
    elif mode == 'byte':
        count = len(data.encode('utf-8'))
        bits = 8 * count
        cci = [8, 16, 16][band]
    else:
        return {'error': 'mode'}
    if count >= 1 << cci:
        return {'error': 'too-long'}
    return 4 + cci + bits
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('alnum', '-', 1), 19], [('alnum', '$', 15), 21], [('alnum', '-/$é+/%é+', 0), {'error': 'version'}], [('byte', '1€11€é', 40), 108], [('alnum', 'ééA- q', 9), {'error': 'charset'}], [('byte', '', 1), 12], [('numeric', '548976', 15), 36], [('alnum', '%', 1), 19]], [[('alnum', ':', 9), 19], [('alnum', 'A', 10), 21], [('numeric', '053142', 0), {'error': 'version'}], [('numeric', '089405', 10), 36], [('kanji', 'b1ab11', 5), {'error': 'mode'}], [('alnum', 'q+$ ', 40), {'error': 'charset'}], [('alnum', '++$:é1*.+', 10), {'error': 'charset'}], [('alnum', ' -/', 26), 32]], [[('alnum', 'A. ', 27), 34], [('alnum', 'A*%/ :Z', 15), 54], [('numeric', '00575', 9), 31], [('numeric', '37219', 5), 31], [('numeric', '', 40), 18], [('numeric', '716925614701', 5), 54], [('kanji', 'é b€b', 10), {'error': 'mode'}], [('alnum', '+:.:Z', 10), 43]], [[('alnum', '$A.', 9), 30], [('alnum', '.1A', 15), 32], [('byte', 'abbbaaa', 26), 76], [('byte', '€', 41), {'error': 'version'}], [('numeric', '', 0), {'error': 'version'}], [('numeric', '2', 1), 18], [('alnum', '%1.qZ-', 5), {'error': 'charset'}], [('alnum', ' ', 40), 23]], [[('alnum', '*:B', 10), 32], [('alnum', '/ -', 40), 34], [('kanji', 'é ba', 40), {'error': 'mode'}], [('kanji', 'éb', 1), {'error': 'mode'}], [('byte', 'a€', 26), 52], [('byte', '€é1', 27), 68], [('numeric', '4813206244', 15), 50], [('alnum', '+', 10), 21]]]
labels = ["regression: alphanumeric trailing character", "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)

prompt:
Odd-length alphanumeric payloads are overestimated by five bits and may bump the version.

Compute the length in bits of one QR segment: 4-bit mode indicator, a character count indicator whose width depends on mode and version band (1-9, 10-26, 27-40): numeric 10/12/14, alphanumeric 9/11/13, byte 8/16/16, and the data bits: numeric 10 bits per 3 digits plus 4 or 7 for a remainder of 1 or 2, alphanumeric 11 bits per pair plus 6 for a single, byte 8 bits per UTF-8 byte. Alphanumeric allows 0-9 A-Z space $ % * + - . / :. A count that does not fit the indicator is too-long. Errors: version, charset, mode, too-long.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(mode, data, version):
    if not 1 <= version <= 40:
        return {'error': 'version'}
    band = 0 if version <= 9 else (1 if version <= 26 else 2)
    ALNUM = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:'
    if mode == 'numeric':
        if not all(c in '0123456789' for c in data):
            return {'error': 'charset'}
        count = len(data)
        bits = 10 * (count // 3) + [0, 4, 7][count % 3]
        cci = [10, 12, 14][band]
    elif mode == 'alnum':
        if not all(c in ALNUM for c in data):
            return {'error': 'charset'}
        count = len(data)
        bits = 11 * (count // 2) + 6 * (count % 2)
        cci = [9, 11, 13][band]
    elif mode == 'byte':
        count = len(data)
        bits = 8 * count
        cci = [8, 16, 16][band]
    else:
        return {'error': 'mode'}
    if count >= 1 << cci:
        return {'error': 'too-long'}
    return 4 + cci + bits
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('byte', '1€11€é', 40), 108], [('byte', '€éa1a1 ', 9), 92], [('alnum', '-/$é+/%é+', 0), {'error': 'version'}], [('alnum', '-', 1), 19], [('alnum', '%', 1), 19], [('alnum', 'ééA- q', 9), {'error': 'charset'}], [('byte', '', 1), 12], [('byte', '€1é ', 27), 76]], [[('byte', 'ébba', 27), 60], [('byte', 'é1 ', 27), 52], [('numeric', '053142', 0), {'error': 'version'}], [('numeric', '089405', 10), 36], [('kanji', 'b1ab11', 5), {'error': 'mode'}], [('alnum', 'q+$ ', 40), {'error': 'charset'}], [('alnum', '++$:é1*.+', 10), {'error': 'charset'}], [('byte', 'ébé', 1), 52]], [[('byte', '1abé', 1), 52], [('byte', 'é  ', 5), 44], [('numeric', '00575', 9), 31], [('numeric', '37219', 5), 31], [('numeric', '', 40), 18], [('numeric', '716925614701', 5), 54], [('kanji', 'é b€b', 10), {'error': 'mode'}], [('byte', '€a€', 10), 76]], [[('byte', 'é€ééa ba', 15), 124], [('byte', 'b€a', 1), 52], [('byte', '€', 41), {'error': 'version'}], [('numeric', '', 0), {'error': 'version'}], [('numeric', '2', 1), 18], [('alnum', '%1.qZ-', 5), {'error': 'charset'}], [('alnum', 'A:*éZA', 40), {'error': 'charset'}], [('byte', 'éb aa€a', 10), 100]], [[('byte', ' a bbé', 10), 76], [('byte', '111bé1', 5), 68], [('kanji', 'éb', 1), {'error': 'mode'}], [('alnum', '.', 5), 19], [('numeric', '4813206244', 15), 50], [('numeric', '19928871', 5), 41], [('numeric', '', 1), 14], [('byte', 'a€', 26), 52]]]
labels = ["regression: byte mode length unit", "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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(mode, data, version):
    if not 1 <= version <= 40:
        return {'error': 'version'}
    band = 0 if version <= 9 else (1 if version <= 26 else 2)
    ALNUM = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:'
    if mode == 'numeric':
        if not all(c in '0123456789' for c in data):
            return {'error': 'charset'}
        count = len(data)
        bits = 10 * (count // 3) + [0, 4, 7][count % 3]
        cci = [10, 12, 14][band]
    elif mode == 'alnum':
        if not all(c in ALNUM for c in data):
            return {'error': 'charset'}
        count = len(data)
        bits = 11 * (count // 2) + 6 * (count % 2)
        cci = [9, 11, 13][band]
    elif mode == 'byte':
        count = len(data.encode('latin-1', 'replace'))
        bits = 8 * count
        cci = [8, 16, 16][band]
    else:
        return {'error': 'mode'}
    if count >= 1 << cci:
        return {'error': 'too-long'}
    return 4 + cci + bits
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('byte', '1€11€é', 40), 108], [('byte', '€éa1a1 ', 9), 92], [('alnum', '-/$é+/%é+', 0), {'error': 'version'}], [('alnum', '-', 1), 19], [('alnum', '%', 1), 19], [('alnum', 'ééA- q', 9), {'error': 'charset'}], [('byte', '', 1), 12], [('byte', '€1é ', 27), 76]], [[('byte', 'ébba', 27), 60], [('byte', 'é1 ', 27), 52], [('numeric', '053142', 0), {'error': 'version'}], [('numeric', '089405', 10), 36], [('kanji', 'b1ab11', 5), {'error': 'mode'}], [('alnum', 'q+$ ', 40), {'error': 'charset'}], [('alnum', '++$:é1*.+', 10), {'error': 'charset'}], [('byte', 'ébé', 1), 52]], [[('byte', '1abé', 1), 52], [('byte', 'é  ', 5), 44], [('numeric', '00575', 9), 31], [('numeric', '37219', 5), 31], [('numeric', '', 40), 18], [('numeric', '716925614701', 5), 54], [('kanji', 'é b€b', 10), {'error': 'mode'}], [('byte', '€a€', 10), 76]], [[('byte', 'é€ééa ba', 15), 124], [('byte', 'b€a', 1), 52], [('byte', '€', 41), {'error': 'version'}], [('numeric', '', 0), {'error': 'version'}], [('numeric', '2', 1), 18], [('alnum', '%1.qZ-', 5), {'error': 'charset'}], [('alnum', 'A:*éZA', 40), {'error': 'charset'}], [('byte', 'éb aa€a', 10), 100]], [[('byte', ' a bbé', 10), 76], [('byte', '111bé1', 5), 68], [('kanji', 'éb', 1), {'error': 'mode'}], [('alnum', '.', 5), 19], [('numeric', '4813206244', 15), 50], [('numeric', '19928871', 5), 41], [('numeric', '', 1), 14], [('byte', 'a€', 26), 52]]]
labels = ["regression: byte mode length unit", "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)

prompt:
Payloads with accented letters or the euro sign overflow the chosen version and are truncated by the encoder.

Compute the length in bits of one QR segment: 4-bit mode indicator, a character count indicator whose width depends on mode and version band (1-9, 10-26, 27-40): numeric 10/12/14, alphanumeric 9/11/13, byte 8/16/16, and the data bits: numeric 10 bits per 3 digits plus 4 or 7 for a remainder of 1 or 2, alphanumeric 11 bits per pair plus 6 for a single, byte 8 bits per UTF-8 byte. Alphanumeric allows 0-9 A-Z space $ % * + - . / :. A count that does not fit the indicator is too-long. Errors: version, charset, mode, too-long.

split: open-access