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.upper() 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 = [[[('alnum', '1+$q2*', 40), {'error': 'charset'}], [('alnum', 'ééA- q', 9), {'error': 'charset'}], [('alnum', 'q .B2%*', 5), {'error': 'charset'}], [('alnum', '-/$é+/%é+', 0), {'error': 'version'}], [('alnum', '-', 1), 19], [('alnum', '%', 1), 19], [('byte', '1€11€é', 40), 108], [('alnum', '/q', 9), {'error': 'charset'}]], [[('alnum', ' Aq%:.', 27), {'error': 'charset'}], [('alnum', '++$:é1*.+', 10), {'error': 'charset'}], [('alnum', '-:q2*-q', 15), {'error': 'charset'}], [('numeric', '053142', 0), {'error': 'version'}], [('numeric', '089405', 10), 36], [('kanji', 'b1ab11', 5), {'error': 'mode'}], [('alnum', '+qB+', 0), {'error': 'version'}], [('alnum', 'Aq ', 5), {'error': 'charset'}]], [[('alnum', 'BA qq/', 1), {'error': 'charset'}], [('alnum', ': q', 15), {'error': 'charset'}], [('alnum', 'ZZq', 1), {'error': 'charset'}], [('numeric', '00575', 9), 31], [('numeric', '37219', 5), 31], [('numeric', '', 40), 18], [('numeric', '716925614701', 5), 54], [('alnum', '*Zq$', 40), {'error': 'charset'}]], [[('alnum', 'B+ +q+B', 26), {'error': 'charset'}], [('alnum', 'B2q*.é.2-', 15), {'error': 'charset'}], [('alnum', '1ZqA-', 1), {'error': 'charset'}], [('byte', 'abbbaaa', 26), 76], [('byte', '€', 41), {'error': 'version'}], [('numeric', '', 0), {'error': 'version'}], [('numeric', '2', 1), 18], [('alnum', 'A+*+Zq1B.', 26), {'error': 'charset'}]], [[('alnum', 'q1 :B.-', 1), {'error': 'charset'}], [('alnum', 'q*/q-é', 9), {'error': 'charset'}], [('alnum', '*/Zq1 %B', 10), {'error': 'charset'}], [('kanji', 'é ba', 40), {'error': 'mode'}], [('kanji', 'éb', 1), {'error': 'mode'}], [('byte', 'a€', 26), 52], [('alnum', '.', 5), 19], [('alnum', '.1q', 5), {'error': 'charset'}]]]
labels = ["regression: alphanumeric character set", "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.isalnum() or c in ' $%*+-./:' 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 = [[[('alnum', '1+$q2*', 40), {'error': 'charset'}], [('alnum', 'ééA- q', 9), {'error': 'charset'}], [('alnum', 'q .B2%*', 5), {'error': 'charset'}], [('alnum', '-/$é+/%é+', 0), {'error': 'version'}], [('alnum', '-', 1), 19], [('alnum', '%', 1), 19], [('byte', '1€11€é', 40), 108], [('alnum', '/q', 9), {'error': 'charset'}]], [[('alnum', ' Aq%:.', 27), {'error': 'charset'}], [('alnum', '++$:é1*.+', 10), {'error': 'charset'}], [('alnum', '-:q2*-q', 15), {'error': 'charset'}], [('numeric', '053142', 0), {'error': 'version'}], [('numeric', '089405', 10), 36], [('kanji', 'b1ab11', 5), {'error': 'mode'}], [('alnum', '+qB+', 0), {'error': 'version'}], [('alnum', 'Aq ', 5), {'error': 'charset'}]], [[('alnum', 'BA qq/', 1), {'error': 'charset'}], [('alnum', ': q', 15), {'error': 'charset'}], [('alnum', 'ZZq', 1), {'error': 'charset'}], [('numeric', '00575', 9), 31], [('numeric', '37219', 5), 31], [('numeric', '', 40), 18], [('numeric', '716925614701', 5), 54], [('alnum', '*Zq$', 40), {'error': 'charset'}]], [[('alnum', 'B+ +q+B', 26), {'error': 'charset'}], [('alnum', 'B2q*.é.2-', 15), {'error': 'charset'}], [('alnum', '1ZqA-', 1), {'error': 'charset'}], [('byte', 'abbbaaa', 26), 76], [('byte', '€', 41), {'error': 'version'}], [('numeric', '', 0), {'error': 'version'}], [('numeric', '2', 1), 18], [('alnum', 'A+*+Zq1B.', 26), {'error': 'charset'}]], [[('alnum', 'q1 :B.-', 1), {'error': 'charset'}], [('alnum', 'q*/q-é', 9), {'error': 'charset'}], [('alnum', '*/Zq1 %B', 10), {'error': 'charset'}], [('kanji', 'é ba', 40), {'error': 'mode'}], [('kanji', 'éb', 1), {'error': 'mode'}], [('byte', 'a€', 26), 52], [('alnum', '.', 5), 19], [('alnum', '.1q', 5), {'error': 'charset'}]]]
labels = ["regression: alphanumeric character set", "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:
Lowercase URLs are sized as alphanumeric but the encoder has no values for them.

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


meaning: Fixture-count band, not measured model difficulty

deps: stdlib

prompt:
A 256-byte segment at version 9 wraps its 8-bit count to zero.

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, 12, 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', 26), 28], [('byte', '11 ', 15), 44], [('alnum', '-/$é+/%é+', 0), {'error': 'version'}], [('alnum', '-', 1), 19], [('alnum', '%', 1), 19], [('byte', '1€11€é', 40), 108], [('alnum', 'ééA- q', 9), {'error': 'charset'}], [('byte', 'b1', 26), 36]], [[('byte', 'éé1 ébé1', 15), 116], [('byte', '€éaéaa', 15), 100], [('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', ' aa1', 10), 52]], [[('byte', '', 26), 20], [('numeric', '00575', 9), 31], [('numeric', '37219', 5), 31], [('numeric', '', 40), 18], [('numeric', '716925614701', 5), 54], [('kanji', 'é b€b', 10), {'error': 'mode'}], [('numeric', '53', 26), 23], [('byte', '€a€', 10), 76]], [[('byte', '', 15), 20], [('byte', 'éb1€ ', 26), 84], [('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', '1é', 26), 44], [('byte', '  éa ', 15), 68], [('kanji', 'é ba', 40), {'error': 'mode'}], [('kanji', 'éb', 1), {'error': 'mode'}], [('alnum', '.', 5), 19], [('byte', '€é1', 27), 68], [('numeric', '4813206244', 15), 50], [('byte', 'a1a', 15), 44]]]
labels = ["regression: byte mode indicator widths", "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('utf-8'))
        bits = 8 * count
        cci = [8, 8, 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', 26), 28], [('byte', '11 ', 15), 44], [('alnum', '-/$é+/%é+', 0), {'error': 'version'}], [('alnum', '-', 1), 19], [('alnum', '%', 1), 19], [('byte', '1€11€é', 40), 108], [('alnum', 'ééA- q', 9), {'error': 'charset'}], [('byte', 'b1', 26), 36]], [[('byte', 'éé1 ébé1', 15), 116], [('byte', '€éaéaa', 15), 100], [('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', ' aa1', 10), 52]], [[('byte', '', 26), 20], [('numeric', '00575', 9), 31], [('numeric', '37219', 5), 31], [('numeric', '', 40), 18], [('numeric', '716925614701', 5), 54], [('kanji', 'é b€b', 10), {'error': 'mode'}], [('numeric', '53', 26), 23], [('byte', '€a€', 10), 76]], [[('byte', '', 15), 20], [('byte', 'éb1€ ', 26), 84], [('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', '1é', 26), 44], [('byte', '  éa ', 15), 68], [('kanji', 'é ba', 40), {'error': 'mode'}], [('kanji', 'éb', 1), {'error': 'mode'}], [('alnum', '.', 5), 19], [('byte', '€é1', 27), 68], [('numeric', '4813206244', 15), 50], [('byte', 'a1a', 15), 44]]]
labels = ["regression: byte mode indicator widths", "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:
Byte segments at versions 10-26 are written with a 12-bit count and misparse.

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


prompt:
Scanned text has every pair of characters swapped, so "AC" reads as "CA".

Encode the data part of a QR alphanumeric segment. Character values: 0-9 -> 0-9, A-Z -> 10-35, space 36, $ 37, % 38, * 39, + 40, - 41, . 42, / 43, : 44. Each pair becomes 45*first + second in 11 bits, a final single character becomes its value in 6 bits. Characters outside the set return None.

split: open-access


prompt:
Every pair value above 1023 overflows its field and the rest of the stream is misaligned.

Encode the data part of a QR alphanumeric segment. Character values: 0-9 -> 0-9, A-Z -> 10-35, space 36, $ 37, % 38, * 39, + 40, - 41, . 42, / 43, : 44. Each pair becomes 45*first + second in 11 bits, a final single character becomes its value in 6 bits. Characters outside the set return None.

split: open-access


prompt:
Odd-length data ending in a character with value 32 or more corrupts the terminator.

Encode the data part of a QR alphanumeric segment. Character values: 0-9 -> 0-9, A-Z -> 10-35, space 36, $ 37, % 38, * 39, + 40, - 41, . 42, / 43, : 44. Each pair becomes 45*first + second in 11 bits, a final single character becomes its value in 6 bits. Characters outside the set return None.

split: open-access


prompt:
Even-length strings lose their final two characters.

Encode the data part of a QR alphanumeric segment. Character values: 0-9 -> 0-9, A-Z -> 10-35, space 36, $ 37, % 38, * 39, + 40, - 41, . 42, / 43, : 44. Each pair becomes 45*first + second in 11 bits, a final single character becomes its value in 6 bits. Characters outside the set return None.

split: open-access


prompt:
Text containing spaces or punctuation decodes with shifted symbols.

Encode the data part of a QR alphanumeric segment. Character values: 0-9 -> 0-9, A-Z -> 10-35, space 36, $ 37, % 38, * 39, + 40, - 41, . 42, / 43, : 44. Each pair becomes 45*first + second in 11 bits, a final single character becomes its value in 6 bits. Characters outside the set return None.

split: open-access


prompt:
Payloads that fill all but a few bits get an extra codeword and the symbol is rejected as too long.

Finish a QR data bit stream for a symbol with `capacity` data codewords: data longer than capacity*8 bits returns None; append a terminator of up to four 0 bits (truncated if capacity is reached), pad with 0 bits to a byte boundary, split into codewords, then append pad codewords alternating 0xEC, 0x11 starting with 0xEC until the capacity is filled.

split: open-access


prompt:
Strict decoders flag the pad sequence and some generators produce different symbols for the same data.

Finish a QR data bit stream for a symbol with `capacity` data codewords: data longer than capacity*8 bits returns None; append a terminator of up to four 0 bits (truncated if capacity is reached), pad with 0 bits to a byte boundary, split into codewords, then append pad codewords alternating 0xEC, 0x11 starting with 0xEC until the capacity is filled.

split: open-access


prompt:
The encoder moves to a larger version for payloads that fit exactly.

Finish a QR data bit stream for a symbol with `capacity` data codewords: data longer than capacity*8 bits returns None; append a terminator of up to four 0 bits (truncated if capacity is reached), pad with 0 bits to a byte boundary, split into codewords, then append pad codewords alternating 0xEC, 0x11 starting with 0xEC until the capacity is filled.

split: open-access


prompt:
Symbols with an odd number of data codewords start padding with 0x11.

Finish a QR data bit stream for a symbol with `capacity` data codewords: data longer than capacity*8 bits returns None; append a terminator of up to four 0 bits (truncated if capacity is reached), pad with 0 bits to a byte boundary, split into codewords, then append pad codewords alternating 0xEC, 0x11 starting with 0xEC until the capacity is filled.

split: open-access


prompt:
Aligned payloads gain a spurious 0x00 codeword before the pad bytes.

Finish a QR data bit stream for a symbol with `capacity` data codewords: data longer than capacity*8 bits returns None; append a terminator of up to four 0 bits (truncated if capacity is reached), pad with 0 bits to a byte boundary, split into codewords, then append pad codewords alternating 0xEC, 0x11 starting with 0xEC until the capacity is filled.

split: open-access


prompt:
Magazine issue numbers decode as different issues.

Encode a two-digit EAN-2 add-on (issue number) as modules: start 1011, first character, separator 01, second character. The parity pattern is chosen by the two-digit value modulo 4: 0 LL, 1 LG, 2 GL, 3 GG, using the EAN L and G code sets. Invalid input returns None.

split: open-access


prompt:
Issue numbers with value mod 4 of 1 or 2 fail the add-on parity check at the till.

Encode a two-digit EAN-2 add-on (issue number) as modules: start 1011, first character, separator 01, second character. The parity pattern is chosen by the two-digit value modulo 4: 0 LL, 1 LG, 2 GL, 3 GG, using the EAN L and G code sets. Invalid input returns None.

split: open-access


prompt:
Scanners do not detect the add-on because its start pattern is one module short.

Encode a two-digit EAN-2 add-on (issue number) as modules: start 1011, first character, separator 01, second character. The parity pattern is chosen by the two-digit value modulo 4: 0 LL, 1 LG, 2 GL, 3 GG, using the EAN L and G code sets. Invalid input returns None.

split: open-access


prompt:
The second digit is misaligned by one module and fails to decode.

Encode a two-digit EAN-2 add-on (issue number) as modules: start 1011, first character, separator 01, second character. The parity pattern is chosen by the two-digit value modulo 4: 0 LL, 1 LG, 2 GL, 3 GG, using the EAN L and G code sets. Invalid input returns None.

split: open-access


prompt:
Symbols printed at fractional pixel pitches grow or shrink across their width and fail verification.

Render a module string ("1" bar, "0" space) at xn/xd device pixels per module after `quiet` leading quiet-zone modules. Module boundary k lies at round-half-up((quiet + k) * X), computed from the exact fraction so errors do not accumulate. Adjacent bar modules merge into one bar [start, end); bar width reduction shaves `bwr` pixels from the right edge of each bar, but a bar is never narrower than 1 pixel.

split: open-access


prompt:
At pitches above one pixel per module the quiet zone is too small and the symbol starts too close to the label edge.

Render a module string ("1" bar, "0" space) at xn/xd device pixels per module after `quiet` leading quiet-zone modules. Module boundary k lies at round-half-up((quiet + k) * X), computed from the exact fraction so errors do not accumulate. Adjacent bar modules merge into one bar [start, end); bar width reduction shaves `bwr` pixels from the right edge of each bar, but a bar is never narrower than 1 pixel.

split: open-access


prompt:
With bar width reduction every wide bar shows hairline gaps between its modules.

Render a module string ("1" bar, "0" space) at xn/xd device pixels per module after `quiet` leading quiet-zone modules. Module boundary k lies at round-half-up((quiet + k) * X), computed from the exact fraction so errors do not accumulate. Adjacent bar modules merge into one bar [start, end); bar width reduction shaves `bwr` pixels from the right edge of each bar, but a bar is never narrower than 1 pixel.

split: open-access


prompt:
Bars lose twice the intended ink-spread compensation and read as too narrow.

Render a module string ("1" bar, "0" space) at xn/xd device pixels per module after `quiet` leading quiet-zone modules. Module boundary k lies at round-half-up((quiet + k) * X), computed from the exact fraction so errors do not accumulate. Adjacent bar modules merge into one bar [start, end); bar width reduction shaves `bwr` pixels from the right edge of each bar, but a bar is never narrower than 1 pixel.

split: open-access


prompt:
At low resolutions single-module bars vanish, making the symbol unreadable.

Render a module string ("1" bar, "0" space) at xn/xd device pixels per module after `quiet` leading quiet-zone modules. Module boundary k lies at round-half-up((quiet + k) * X), computed from the exact fraction so errors do not accumulate. Adjacent bar modules merge into one bar [start, end); bar width reduction shaves `bwr` pixels from the right edge of each bar, but a bar is never narrower than 1 pixel.

split: open-access


prompt:
Heavily printed labels read every narrow bar as wide because ink spread shifts bars against spaces.

Classify measured element widths of a two-width symbology scanline (bars at even indexes, spaces at odd) into N/W. Bars and spaces are classified separately because ink spread widens bars. Within a class, if max < 1.5 * min all elements are narrow; otherwise the threshold is (min + max) / 2, elements above it are wide, below it narrow, and an element exactly on it is {"error": "ambiguous", "index": i}.

split: open-access


prompt:
Symbols whose spaces are all narrow fail to decode with an ambiguity error.

Classify measured element widths of a two-width symbology scanline (bars at even indexes, spaces at odd) into N/W. Bars and spaces are classified separately because ink spread widens bars. Within a class, if max < 1.5 * min all elements are narrow; otherwise the threshold is (min + max) / 2, elements above it are wide, below it narrow, and an element exactly on it is {"error": "ambiguous", "index": i}.

split: open-access


prompt:
Borderline scans decode to wrong data instead of being retried.

Classify measured element widths of a two-width symbology scanline (bars at even indexes, spaces at odd) into N/W. Bars and spaces are classified separately because ink spread widens bars. Within a class, if max < 1.5 * min all elements are narrow; otherwise the threshold is (min + max) / 2, elements above it are wide, below it narrow, and an element exactly on it is {"error": "ambiguous", "index": i}.

split: open-access


prompt:
Elements just above the true midpoint are misread when min + max is odd.

Classify measured element widths of a two-width symbology scanline (bars at even indexes, spaces at odd) into N/W. Bars and spaces are classified separately because ink spread widens bars. Within a class, if max < 1.5 * min all elements are narrow; otherwise the threshold is (min + max) / 2, elements above it are wide, below it narrow, and an element exactly on it is {"error": "ambiguous", "index": i}.

split: open-access


prompt:
Numeric pairs 00 and 01 collide with the pad and upper-shift range and serial numbers decode wrongly.

Data Matrix ASCII encodation into `capacity` data codewords: two consecutive ASCII digits become 130 + their value; ASCII 0..127 becomes ord + 1; 128..255 becomes Upper Shift 235 then ord - 127; higher code points are unencodable. Too many codewords -> overflow. Padding: the first pad is 129; each later pad at 1-based position p is 129 + ((149 * p) mod 253) + 1, minus 254 if above 254.

split: open-access


prompt:
Every letter decodes as its predecessor in the alphabet.

Data Matrix ASCII encodation into `capacity` data codewords: two consecutive ASCII digits become 130 + their value; ASCII 0..127 becomes ord + 1; 128..255 becomes Upper Shift 235 then ord - 127; higher code points are unencodable. Too many codewords -> overflow. Padding: the first pad is 129; each later pad at 1-based position p is 129 + ((149 * p) mod 253) + 1, minus 254 if above 254.

split: open-access


prompt:
Accented characters decode as the previous Latin-1 character.

Data Matrix ASCII encodation into `capacity` data codewords: two consecutive ASCII digits become 130 + their value; ASCII 0..127 becomes ord + 1; 128..255 becomes Upper Shift 235 then ord - 127; higher code points are unencodable. Too many codewords -> overflow. Padding: the first pad is 129; each later pad at 1-based position p is 129 + ((149 * p) mod 253) + 1, minus 254 if above 254.

split: open-access


prompt:
Symbols with padding fail strict verification because every randomised pad is off by one position.

Data Matrix ASCII encodation into `capacity` data codewords: two consecutive ASCII digits become 130 + their value; ASCII 0..127 becomes ord + 1; 128..255 becomes Upper Shift 235 then ord - 127; higher code points are unencodable. Too many codewords -> overflow. Padding: the first pad is 129; each later pad at 1-based position p is 129 + ((149 * p) mod 253) + 1, minus 254 if above 254.

split: open-access


prompt:
Decoders do not recognise the end of data because the first pad is not 129.

Data Matrix ASCII encodation into `capacity` data codewords: two consecutive ASCII digits become 130 + their value; ASCII 0..127 becomes ord + 1; 128..255 becomes Upper Shift 235 then ord - 127; higher code points are unencodable. Too many codewords -> overflow. Padding: the first pad is 129; each later pad at 1-based position p is 129 + ((149 * p) mod 253) + 1, minus 254 if above 254.

split: open-access


prompt:
Some pad codewords are one higher than the reference encoder produces.

Data Matrix ASCII encodation into `capacity` data codewords: two consecutive ASCII digits become 130 + their value; ASCII 0..127 becomes ord + 1; 128..255 becomes Upper Shift 235 then ord - 127; higher code points are unencodable. Too many codewords -> overflow. Padding: the first pad is 129; each later pad at 1-based position p is 129 + ((149 * p) mod 253) + 1, minus 254 if above 254.

split: open-access


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

N = 1
observations = []
def solve(n):
    if not isinstance(n, int) or n < 1 or n > 131070:
        return None
    bars = []
    while n > 0:
        if n % 2 == 0:
            bars.append('w')
            n = (n - 2) // 2
        else:
            bars.append('n')
            n = (n - 1) // 2
    bars.reverse()
    width = sum(3 if b == 'w' else 1 for b in bars) + 2 * (len(bars) - 1)
    return [''.join(bars), width]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[1, None], [2, None], [34, ['nnnww', 17]], [306, ['nnwwnnww', 30]], [371, ['nwwwnwnn', 30]], [120, ['wwwnnw', 24]], [98, ['wnnnww', 22]], [297, ['nnwnwnwn', 28]]], [[2, None], [6, ['ww', 8]], [85, ['nwnwwn', 22]], [155, ['nnwwwnn', 25]], [306, ['nnwwnnww', 30]], [201, ['wnnwnwn', 25]], [146, ['nnwnnww', 25]], [240, ['wwwnnnw', 27]]], [[1, None], [2, None], [142, ['nnnwwww', 27]], [335, ['nwnwnnnn', 26]], [232, ['wwnwnnw', 27]], [397, ['wnnnwwwn', 30]], [147, ['nnwnwnn', 23]], [225, ['wwnnnwn', 25]]], [[2, None], [229, ['wwnnwwn', 27]], [157, ['nnwwwwn', 27]], [19, ['nwnn', 12]], [27, ['wwnn', 14]], [36, ['nnwnw', 17]], [75, ['nnwwnn', 20]], [228, ['wwnnwnw', 27]]], [[1, None], [2, None], [157, ['nnwwwwn', 27]], [228, ['wwnnwnw', 27]], [361, ['nwwnwnwn', 30]], [153, ['nnwwnwn', 25]], [326, ['nwnnnwww', 30]], [188, ['nwwwwnw', 29]]]]
labels = ["regression: minimum encodable value", "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(n):
    if not isinstance(n, int) or n < 2 or n > 131070:
        return None
    bars = []
    while n > 0:
        if n % 2 == 0:
            bars.append('w')
            n = (n - 2) // 2
        else:
            bars.append('n')
            n = (n - 1) // 2
    bars.reverse()
    width = sum(3 if b == 'w' else 1 for b in bars) + 2 * (len(bars) - 1)
    return [''.join(bars), width]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[1, None], [2, None], [34, ['nnnww', 17]], [306, ['nnwwnnww', 30]], [371, ['nwwwnwnn', 30]], [120, ['wwwnnw', 24]], [98, ['wnnnww', 22]], [297, ['nnwnwnwn', 28]]], [[2, None], [6, ['ww', 8]], [85, ['nwnwwn', 22]], [155, ['nnwwwnn', 25]], [306, ['nnwwnnww', 30]], [201, ['wnnwnwn', 25]], [146, ['nnwnnww', 25]], [240, ['wwwnnnw', 27]]], [[1, None], [2, None], [142, ['nnnwwww', 27]], [335, ['nwnwnnnn', 26]], [232, ['wwnwnnw', 27]], [397, ['wnnnwwwn', 30]], [147, ['nnwnwnn', 23]], [225, ['wwnnnwn', 25]]], [[2, None], [229, ['wwnnwwn', 27]], [157, ['nnwwwwn', 27]], [19, ['nwnn', 12]], [27, ['wwnn', 14]], [36, ['nnwnw', 17]], [75, ['nnwwnn', 20]], [228, ['wwnnwnw', 27]]], [[1, None], [2, None], [157, ['nnwwwwn', 27]], [228, ['wwnnwnw', 27]], [361, ['nwwnwnwn', 30]], [153, ['nnwwnwn', 25]], [326, ['nwnnnwww', 30]], [188, ['nwwwwnw', 29]]]]
labels = ["regression: minimum encodable value", "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:
Single-bar codes are printed although scanners require at least two bars.

Encode an integer 3..131070 as a one-track Pharmacode: repeatedly, an even value adds a wide bar and becomes (n - 2) / 2, an odd value adds a narrow bar and becomes (n - 1) / 2, until zero; bars are read in the reverse order of generation (left to right). Width: narrow 1, wide 3, spaces 2 between bars. Return [pattern, width] or None outside the range.

split: open-access


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

N = 1
observations = []
def solve(n):
    if not isinstance(n, int) or n < 3 or n > 131071:
        return None
    bars = []
    while n > 0:
        if n % 2 == 0:
            bars.append('w')
            n = (n - 2) // 2
        else:
            bars.append('n')
            n = (n - 1) // 2
    bars.reverse()
    width = sum(3 if b == 'w' else 1 for b in bars) + 2 * (len(bars) - 1)
    return [''.join(bars), width]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[131071, None], [88037, ['nwnwnwwwwwwnnwwn', 66]], [34, ['nnnww', 17]], [306, ['nnwwnnww', 30]], [371, ['nwwwnwnn', 30]], [120, ['wwwnnw', 24]], [98, ['wnnnww', 22]], [124778, ['wwwnnwwwnwwnwnww', 68]]], [[131071, None], [96385, ['nwwwwnnnwnnnnnwn', 58]], [6, ['ww', 8]], [85, ['nwnwwn', 22]], [155, ['nnwwwnn', 25]], [306, ['nnwwnnww', 30]], [201, ['wnnwnwn', 25]], [106660, ['wnwnnnnnwnwnnwnw', 58]]], [[131071, None], [93303, ['nwwnwwnnnwwwwnnn', 62]], [142, ['nnnwwww', 27]], [335, ['nwnwnnnn', 26]], [232, ['wwnwnnw', 27]], [397, ['wnnnwwwn', 30]], [147, ['nnwnwnn', 23]], [130692, ['wwwwwwwnwnnnnwnw', 66]]], [[131071, None], [80722, ['nnwwwnwwnwnwnnww', 64]], [229, ['wwnnwwn', 27]], [157, ['nnwwwwn', 27]], [19, ['nwnn', 12]], [27, ['wwnn', 14]], [36, ['nnwnw', 17]], [72515, ['nnnwwnwwnwnnnwnn', 58]]], [[131071, None], [98004, ['nwwwwwwnwwnwnwnw', 68]], [157, ['nnwwwwn', 27]], [228, ['wwnnwnw', 27]], [361, ['nwwnwnwn', 30]], [153, ['nnwwnwn', 25]], [326, ['nwnnnwww', 30]], [84211, ['nwnnwnnnwwwwnwnn', 60]]]]
labels = ["regression: maximum encodable value", "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(n):
    if not isinstance(n, int) or n < 3 or n > 65535:
        return None
    bars = []
    while n > 0:
        if n % 2 == 0:
            bars.append('w')
            n = (n - 2) // 2
        else:
            bars.append('n')
            n = (n - 1) // 2
    bars.reverse()
    width = sum(3 if b == 'w' else 1 for b in bars) + 2 * (len(bars) - 1)
    return [''.join(bars), width]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[131071, None], [88037, ['nwnwnwwwwwwnnwwn', 66]], [34, ['nnnww', 17]], [306, ['nnwwnnww', 30]], [371, ['nwwwnwnn', 30]], [120, ['wwwnnw', 24]], [98, ['wnnnww', 22]], [124778, ['wwwnnwwwnwwnwnww', 68]]], [[131071, None], [96385, ['nwwwwnnnwnnnnnwn', 58]], [6, ['ww', 8]], [85, ['nwnwwn', 22]], [155, ['nnwwwnn', 25]], [306, ['nnwwnnww', 30]], [201, ['wnnwnwn', 25]], [106660, ['wnwnnnnnwnwnnwnw', 58]]], [[131071, None], [93303, ['nwwnwwnnnwwwwnnn', 62]], [142, ['nnnwwww', 27]], [335, ['nwnwnnnn', 26]], [232, ['wwnwnnw', 27]], [397, ['wnnnwwwn', 30]], [147, ['nnwnwnn', 23]], [130692, ['wwwwwwwnwnnnnwnw', 66]]], [[131071, None], [80722, ['nnwwwnwwnwnwnnww', 64]], [229, ['wwnnwwn', 27]], [157, ['nnwwwwn', 27]], [19, ['nwnn', 12]], [27, ['wwnn', 14]], [36, ['nnwnw', 17]], [72515, ['nnnwwnwwnwnnnwnn', 58]]], [[131071, None], [98004, ['nwwwwwwnwwnwnwnw', 68]], [157, ['nnwwwwn', 27]], [228, ['wwnnwnw', 27]], [361, ['nwwnwnwn', 30]], [153, ['nnwwnwn', 25]], [326, ['nwnnnwww', 30]], [84211, ['nwnnwnnnwwwwnwnn', 60]]]]
labels = ["regression: maximum encodable value", "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:
Value 131071 produces 17 narrow bars that exceed the symbol definition.

Encode an integer 3..131070 as a one-track Pharmacode: repeatedly, an even value adds a wide bar and becomes (n - 2) / 2, an odd value adds a narrow bar and becomes (n - 1) / 2, until zero; bars are read in the reverse order of generation (left to right). Width: narrow 1, wide 3, spaces 2 between bars. Return [pattern, width] or None outside the range.

split: open-access


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

N = 1
observations = []
def solve(n):
    if not isinstance(n, int) or n < 3 or n > 131070:
        return None
    bars = []
    while n > 0:
        if n % 2 == 1:
            bars.append('w')
            n = (n - 2) // 2
        else:
            bars.append('n')
            n = (n - 1) // 2
    bars.reverse()
    width = sum(3 if b == 'w' else 1 for b in bars) + 2 * (len(bars) - 1)
    return [''.join(bars), width]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[34, ['nnnww', 17]], [120, ['wwwnnw', 24]], [1, None], [2, None], [131071, None], [0, None], [-5, None], [306, ['nnwwnnww', 30]]], [[6, ['ww', 8]], [146, ['nnwnnww', 25]], [2, None], [131071, None], [0, None], [-5, None], [1, None], [85, ['nwnwwn', 22]]], [[142, ['nnnwwww', 27]], [86, ['nwnwww', 24]], [131071, None], [0, None], [-5, None], [1, None], [2, None], [396, ['wnnnwwnw', 30]]], [[229, ['wwnnwwn', 27]], [157, ['nnwwwwn', 27]], [240, ['wwwnnnw', 27]], [0, None], [-5, None], [1, None], [2, None], [143, ['nnwnnnn', 21]]], [[157, ['nnwwwwn', 27]], [228, ['wwnnwnw', 27]], [242, ['wwwnnww', 29]], [-5, None], [1, None], [2, None], [131071, None], [225, ['wwnnnwn', 25]]]]
labels = ["regression: even value bar type", "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(n):
    if not isinstance(n, int) or n < 3 or n > 131070:
        return None
    bars = []
    while n > 0:
        if n % 4 == 0:
            bars.append('w')
            n = (n - 2) // 2
        else:
            bars.append('n')
            n = (n - 1) // 2
    bars.reverse()
    width = sum(3 if b == 'w' else 1 for b in bars) + 2 * (len(bars) - 1)
    return [''.join(bars), width]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[34, ['nnnww', 17]], [120, ['wwwnnw', 24]], [1, None], [2, None], [131071, None], [0, None], [-5, None], [306, ['nnwwnnww', 30]]], [[6, ['ww', 8]], [146, ['nnwnnww', 25]], [2, None], [131071, None], [0, None], [-5, None], [1, None], [85, ['nwnwwn', 22]]], [[142, ['nnnwwww', 27]], [86, ['nwnwww', 24]], [131071, None], [0, None], [-5, None], [1, None], [2, None], [396, ['wnnnwwnw', 30]]], [[229, ['wwnnwwn', 27]], [157, ['nnwwwwn', 27]], [240, ['wwwnnnw', 27]], [0, None], [-5, None], [1, None], [2, None], [143, ['nnwnnnn', 21]]], [[157, ['nnwwwwn', 27]], [228, ['wwnnwnw', 27]], [242, ['wwwnnww', 29]], [-5, None], [1, None], [2, None], [131071, None], [225, ['wwnnnwn', 25]]]]
labels = ["regression: even value bar type", "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 package code scans as a different product number.

Encode an integer 3..131070 as a one-track Pharmacode: repeatedly, an even value adds a wide bar and becomes (n - 2) / 2, an odd value adds a narrow bar and becomes (n - 1) / 2, until zero; bars are read in the reverse order of generation (left to right). Width: narrow 1, wide 3, spaces 2 between bars. Return [pattern, width] or None outside the range.

split: open-access


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

N = 1
observations = []
def solve(n):
    if not isinstance(n, int) or n < 3 or n > 131070:
        return None
    bars = []
    while n > 0:
        if n % 2 == 0:
            bars.append('w')
            n = (n - 2) // 2
        else:
            bars.append('n')
            n = (n - 1) // 2
    pass
    width = sum(3 if b == 'w' else 1 for b in bars) + 2 * (len(bars) - 1)
    return [''.join(bars), width]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[34, ['nnnww', 17]], [120, ['wwwnnw', 24]], [7, ['nnn', 7]], [30, ['wwww', 18]], [127, ['nnnnnnn', 19]], [1, None], [2, None], [306, ['nnwwnnww', 30]]], [[85, ['nwnwwn', 22]], [353, ['nwwnnnwn', 28]], [31, ['nnnnn', 13]], [126, ['wwwwww', 28]], [127, ['nnnnnnn', 19]], [1022, ['wwwwwwwww', 43]], [1, None], [306, ['nnwwnnww', 30]]], [[142, ['nnnwwww', 27]], [274, ['nnnwnnww', 28]], [15, ['nnnn', 10]], [63, ['nnnnnn', 16]], [255, ['nnnnnnnn', 22]], [14, ['www', 13]], [1, None], [396, ['wnnnwwnw', 30]]], [[157, ['nnwwwwn', 27]], [19, ['nwnn', 12]], [240, ['wwwnnnw', 27]], [3, ['nn', 4]], [254, ['wwwwwww', 33]], [127, ['nnnnnnn', 19]], [1, None], [143, ['nnwnnnn', 21]]], [[157, ['nnwwwwn', 27]], [228, ['wwnnwnw', 27]], [158, ['nnwwwww', 29]], [30, ['wwww', 18]], [6, ['ww', 8]], [1, None], [2, None], [225, ['wwnnnwn', 25]]]]
labels = ["regression: reading order of bars", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(n):
    if not isinstance(n, int) or n < 3 or n > 131070:
        return None
    bars = []
    while n > 0:
        if n % 2 == 0:
            bars.append('w')
            n = (n - 2) // 2
        else:
            bars.append('n')
            n = (n - 1) // 2
    bars.insert(0, bars.pop())
    width = sum(3 if b == 'w' else 1 for b in bars) + 2 * (len(bars) - 1)
    return [''.join(bars), width]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[34, ['nnnww', 17]], [120, ['wwwnnw', 24]], [7, ['nnn', 7]], [30, ['wwww', 18]], [127, ['nnnnnnn', 19]], [1, None], [2, None], [306, ['nnwwnnww', 30]]], [[85, ['nwnwwn', 22]], [353, ['nwwnnnwn', 28]], [31, ['nnnnn', 13]], [126, ['wwwwww', 28]], [127, ['nnnnnnn', 19]], [1022, ['wwwwwwwww', 43]], [1, None], [306, ['nnwwnnww', 30]]], [[142, ['nnnwwww', 27]], [274, ['nnnwnnww', 28]], [15, ['nnnn', 10]], [63, ['nnnnnn', 16]], [255, ['nnnnnnnn', 22]], [14, ['www', 13]], [1, None], [396, ['wnnnwwnw', 30]]], [[157, ['nnwwwwn', 27]], [19, ['nwnn', 12]], [240, ['wwwnnnw', 27]], [3, ['nn', 4]], [254, ['wwwwwww', 33]], [127, ['nnnnnnn', 19]], [1, None], [143, ['nnwnnnn', 21]]], [[157, ['nnwwwwn', 27]], [228, ['wwnnwnw', 27]], [158, ['nnwwwww', 29]], [30, ['wwww', 18]], [6, ['ww', 8]], [1, None], [2, None], [225, ['wwnnnwn', 25]]]]
labels = ["regression: reading order of bars", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Codes are mirrored, so asymmetric patterns scan as other values.

Encode an integer 3..131070 as a one-track Pharmacode: repeatedly, an even value adds a wide bar and becomes (n - 2) / 2, an odd value adds a narrow bar and becomes (n - 1) / 2, until zero; bars are read in the reverse order of generation (left to right). Width: narrow 1, wide 3, spaces 2 between bars. Return [pattern, width] or None outside the range.

split: open-access


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

N = 1
observations = []
def solve(n):
    if not isinstance(n, int) or n < 3 or n > 131070:
        return None
    bars = []
    while n > 0:
        if n % 2 == 0:
            bars.append('w')
            n = (n - 2) // 2
        else:
            bars.append('n')
            n = (n - 1) // 2
    bars.reverse()
    width = sum(3 if b == 'w' else 1 for b in bars) + 2 * len(bars)
    return [''.join(bars), width]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[34, ['nnnww', 17]], [120, ['wwwnnw', 24]], [1, None], [2, None], [131071, None], [0, None], [-5, None], [306, ['nnwwnnww', 30]]], [[6, ['ww', 8]], [146, ['nnwnnww', 25]], [2, None], [131071, None], [0, None], [-5, None], [1, None], [85, ['nwnwwn', 22]]], [[142, ['nnnwwww', 27]], [65, ['nnnnwn', 18]], [131071, None], [0, None], [-5, None], [1, None], [2, None], [396, ['wnnnwwnw', 30]]], [[229, ['wwnnwwn', 27]], [333, ['nwnnwwwn', 30]], [0, None], [-5, None], [1, None], [2, None], [131071, None], [143, ['nnwnnnn', 21]]], [[157, ['nnwwwwn', 27]], [29, ['wwwn', 16]], [-5, None], [1, None], [2, None], [131071, None], [0, None], [225, ['wwnnnwn', 25]]]]
labels = ["regression: spaces between bars", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(n):
    if not isinstance(n, int) or n < 3 or n > 131070:
        return None
    bars = []
    while n > 0:
        if n % 2 == 0:
            bars.append('w')
            n = (n - 2) // 2
        else:
            bars.append('n')
            n = (n - 1) // 2
    bars.reverse()
    width = sum(3 if b == 'w' else 1 for b in bars) + (len(bars) - 1)
    return [''.join(bars), width]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[34, ['nnnww', 17]], [120, ['wwwnnw', 24]], [1, None], [2, None], [131071, None], [0, None], [-5, None], [306, ['nnwwnnww', 30]]], [[6, ['ww', 8]], [146, ['nnwnnww', 25]], [2, None], [131071, None], [0, None], [-5, None], [1, None], [85, ['nwnwwn', 22]]], [[142, ['nnnwwww', 27]], [65, ['nnnnwn', 18]], [131071, None], [0, None], [-5, None], [1, None], [2, None], [396, ['wnnnwwnw', 30]]], [[229, ['wwnnwwn', 27]], [333, ['nwnnwwwn', 30]], [0, None], [-5, None], [1, None], [2, None], [131071, None], [143, ['nnwnnnn', 21]]], [[157, ['nnwwwwn', 27]], [29, ['wwwn', 16]], [-5, None], [1, None], [2, None], [131071, None], [0, None], [225, ['wwnnnwn', 25]]]]
labels = ["regression: spaces between bars", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Packaging artwork reserves two extra modules after the last bar.

Encode an integer 3..131070 as a one-track Pharmacode: repeatedly, an even value adds a wide bar and becomes (n - 2) / 2, an odd value adds a narrow bar and becomes (n - 1) / 2, until zero; bars are read in the reverse order of generation (left to right). Width: narrow 1, wide 3, spaces 2 between bars. Return [pattern, width] or None outside the range.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    natural, stretch, shrink, width, tolerance = x
    shortfall = width - natural
    if shortfall > 0:
        if stretch == 0:
            return ['underfull', 10000, 'very_loose']
        r = Fraction(shortfall, stretch)
    elif shortfall < 0:
        if -shortfall >= shrink:
            return ['overfull', 1000000, 'tight']
        r = Fraction(shortfall, shrink)
    else:
        r = Fraction(0)
    badness = min(10000, math.floor(100 * abs(r) ** 3 + Fraction(1, 2)))
    if r < Fraction(-1, 2):
        fitness = 'tight'
    elif r <= Fraction(1, 2):
        fitness = 'decent'
    elif r <= 1:
        fitness = 'loose'
    else:
        fitness = 'very_loose'
    status = 'ok' if badness <= tolerance else 'underfull'
    return [status, badness, fitness]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('regression: shrink exhaustion limit', [92, 6, 12, 80, 100], ['ok', 100, 'tight']), ('partial-repair probe', [82, 3, 10, 77, 100], ['ok', 13, 'decent']), ('partial-repair probe', [108, 0, 6, 105, 1000], ['ok', 13, 'decent']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('half stretch ratio rounds 12.5 up', [100, 10, 5, 105, 200], ['ok', 13, 'decent']), ('control layout', [107, 16, 10, 115, 150], ['ok', 13, 'decent']), ('control layout', [66, 4, 5, 60, 200], ['overfull', 1000000, 'tight'])], [('regression: shrink exhaustion limit', [108, 1, 10, 98, 1000], ['ok', 100, 'tight']), ('regression: shrink exhaustion limit', [106, 16, 11, 95, 200], ['ok', 100, 'tight']), ('regression: shrink exhaustion limit', [85, 3, 7, 78, 150], ['ok', 100, 'tight']), ('partial-repair probe', [74, 16, 4, 67, 500], ['overfull', 1000000, 'tight']), ('rigid line with slack', [100, 0, 5, 110, 200], ['underfull', 10000, 'very_loose']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('control layout', [116, 0, 11, 126, 100], ['underfull', 10000, 'very_loose']), ('control layout', [104, 0, 1, 124, 100], ['underfull', 10000, 'very_loose'])], [('regression: shrink exhaustion limit', [92, 6, 12, 80, 100], ['ok', 100, 'tight']), ('regression: shrink exhaustion limit', [92, 10, 6, 86, 500], ['ok', 100, 'tight']), ('partial-repair probe', [76, 1, 11, 74, 1000], ['ok', 1, 'decent']), ('partial-repair probe', [118, 20, 4, 106, 1000], ['overfull', 1000000, 'tight']), ('one unit past total shrink', [100, 10, 5, 94, 200], ['overfull', 1000000, 'tight']), ('rigid line with slack', [100, 0, 5, 110, 200], ['underfull', 10000, 'very_loose']), ('control layout', [64, 20, 12, 59, 100], ['ok', 7, 'decent']), ('control layout', [74, 6, 6, 67, 100], ['overfull', 1000000, 'tight'])], [('regression: shrink exhaustion limit', [90, 12, 2, 88, 150], ['ok', 100, 'tight']), ('regression: shrink exhaustion limit', [62, 4, 4, 58, 200], ['ok', 100, 'tight']), ('partial-repair probe', [61, 8, 1, 56, 100], ['overfull', 1000000, 'tight']), ('partial-repair probe', [86, 10, 5, 77, 500], ['overfull', 1000000, 'tight']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('rigid line with slack', [100, 0, 5, 110, 200], ['underfull', 10000, 'very_loose']), ('control layout', [63, 6, 7, 53, 150], ['overfull', 1000000, 'tight']), ('control layout', [73, 0, 12, 81, 500], ['underfull', 10000, 'very_loose'])], [('regression: shrink exhaustion limit', [92, 10, 6, 86, 500], ['ok', 100, 'tight']), ('regression: shrink exhaustion limit', [106, 16, 11, 95, 200], ['ok', 100, 'tight']), ('partial-repair probe', [104, 8, 3, 98, 500], ['overfull', 1000000, 'tight']), ('regression: shrink exhaustion limit', [108, 1, 10, 98, 1000], ['ok', 100, 'tight']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('half stretch ratio rounds 12.5 up', [100, 10, 5, 105, 200], ['ok', 13, 'decent']), ('control layout', [80, 20, 11, 82, 150], ['ok', 0, 'decent']), ('control layout', [111, 8, 4, 130, 150], ['underfull', 1340, 'very_loose'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    natural, stretch, shrink, width, tolerance = x
    shortfall = width - natural
    if shortfall > 0:
        if stretch == 0:
            return ['underfull', 10000, 'very_loose']
        r = Fraction(shortfall, stretch)
    elif shortfall < 0:
        if -shortfall > stretch:
            return ['overfull', 1000000, 'tight']
        r = Fraction(shortfall, shrink)
    else:
        r = Fraction(0)
    badness = min(10000, math.floor(100 * abs(r) ** 3 + Fraction(1, 2)))
    if r < Fraction(-1, 2):
        fitness = 'tight'
    elif r <= Fraction(1, 2):
        fitness = 'decent'
    elif r <= 1:
        fitness = 'loose'
    else:
        fitness = 'very_loose'
    status = 'ok' if badness <= tolerance else 'underfull'
    return [status, badness, fitness]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('regression: shrink exhaustion limit', [92, 6, 12, 80, 100], ['ok', 100, 'tight']), ('partial-repair probe', [82, 3, 10, 77, 100], ['ok', 13, 'decent']), ('partial-repair probe', [108, 0, 6, 105, 1000], ['ok', 13, 'decent']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('half stretch ratio rounds 12.5 up', [100, 10, 5, 105, 200], ['ok', 13, 'decent']), ('control layout', [107, 16, 10, 115, 150], ['ok', 13, 'decent']), ('control layout', [66, 4, 5, 60, 200], ['overfull', 1000000, 'tight'])], [('regression: shrink exhaustion limit', [108, 1, 10, 98, 1000], ['ok', 100, 'tight']), ('regression: shrink exhaustion limit', [106, 16, 11, 95, 200], ['ok', 100, 'tight']), ('regression: shrink exhaustion limit', [85, 3, 7, 78, 150], ['ok', 100, 'tight']), ('partial-repair probe', [74, 16, 4, 67, 500], ['overfull', 1000000, 'tight']), ('rigid line with slack', [100, 0, 5, 110, 200], ['underfull', 10000, 'very_loose']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('control layout', [116, 0, 11, 126, 100], ['underfull', 10000, 'very_loose']), ('control layout', [104, 0, 1, 124, 100], ['underfull', 10000, 'very_loose'])], [('regression: shrink exhaustion limit', [92, 6, 12, 80, 100], ['ok', 100, 'tight']), ('regression: shrink exhaustion limit', [92, 10, 6, 86, 500], ['ok', 100, 'tight']), ('partial-repair probe', [76, 1, 11, 74, 1000], ['ok', 1, 'decent']), ('partial-repair probe', [118, 20, 4, 106, 1000], ['overfull', 1000000, 'tight']), ('one unit past total shrink', [100, 10, 5, 94, 200], ['overfull', 1000000, 'tight']), ('rigid line with slack', [100, 0, 5, 110, 200], ['underfull', 10000, 'very_loose']), ('control layout', [64, 20, 12, 59, 100], ['ok', 7, 'decent']), ('control layout', [74, 6, 6, 67, 100], ['overfull', 1000000, 'tight'])], [('regression: shrink exhaustion limit', [90, 12, 2, 88, 150], ['ok', 100, 'tight']), ('regression: shrink exhaustion limit', [62, 4, 4, 58, 200], ['ok', 100, 'tight']), ('partial-repair probe', [61, 8, 1, 56, 100], ['overfull', 1000000, 'tight']), ('partial-repair probe', [86, 10, 5, 77, 500], ['overfull', 1000000, 'tight']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('rigid line with slack', [100, 0, 5, 110, 200], ['underfull', 10000, 'very_loose']), ('control layout', [63, 6, 7, 53, 150], ['overfull', 1000000, 'tight']), ('control layout', [73, 0, 12, 81, 500], ['underfull', 10000, 'very_loose'])], [('regression: shrink exhaustion limit', [92, 10, 6, 86, 500], ['ok', 100, 'tight']), ('regression: shrink exhaustion limit', [106, 16, 11, 95, 200], ['ok', 100, 'tight']), ('partial-repair probe', [104, 8, 3, 98, 500], ['overfull', 1000000, 'tight']), ('regression: shrink exhaustion limit', [108, 1, 10, 98, 1000], ['ok', 100, 'tight']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('half stretch ratio rounds 12.5 up', [100, 10, 5, 105, 200], ['ok', 13, 'decent']), ('control layout', [80, 20, 11, 82, 150], ['ok', 0, 'decent']), ('control layout', [111, 8, 4, 130, 150], ['underfull', 1340, 'very_loose'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A line compressed by exactly its total shrink is reported overfull.

Input [natural, stretch, shrink, width, tolerance] (ints). shortfall=width-natural. Positive shortfall with zero stretch is underfull 10000 very_loose; shrinking past total shrink is overfull 1000000 tight. r=shortfall/stretch (or /shrink when negative); badness=min(10000, floor(100*|r|^3+1/2)); fitness tight r<-1/2, decent r<=1/2, loose r<=1, else very_loose; status ok iff badness<=tolerance. Return [status, badness, fitness].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    natural, stretch, shrink, width, tolerance = x
    shortfall = width - natural
    if shortfall > 0:
        if stretch == 0:
            return ['underfull', 10000, 'very_loose']
        r = Fraction(shortfall, stretch)
    elif shortfall < 0:
        if -shortfall > shrink:
            return ['overfull', 1000000, 'tight']
        r = Fraction(shortfall, stretch)
    else:
        r = Fraction(0)
    badness = min(10000, math.floor(100 * abs(r) ** 3 + Fraction(1, 2)))
    if r < Fraction(-1, 2):
        fitness = 'tight'
    elif r <= Fraction(1, 2):
        fitness = 'decent'
    elif r <= 1:
        fitness = 'loose'
    else:
        fitness = 'very_loose'
    status = 'ok' if badness <= tolerance else 'underfull'
    return [status, badness, fitness]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('regression: shrink ratio denominator', [105, 12, 6, 100, 1000], ['ok', 58, 'tight']), ('regression: shrink ratio denominator', [82, 3, 10, 77, 100], ['ok', 13, 'decent']), ('regression: shrink ratio denominator', [90, 12, 2, 88, 150], ['ok', 100, 'tight']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('control layout', [116, 20, 6, 127, 1000], ['ok', 17, 'loose']), ('control layout', [69, 10, 7, 69, 100], ['ok', 0, 'decent'])], [('regression: shrink ratio denominator', [96, 4, 10, 87, 1000], ['ok', 73, 'tight']), ('regression: shrink ratio denominator', [67, 1, 8, 64, 1000], ['ok', 5, 'decent']), ('regression: shrink ratio denominator', [85, 1, 11, 80, 200], ['ok', 9, 'decent']), ('regression: shrink ratio denominator', [104, 16, 8, 96, 150], ['ok', 100, 'tight']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('one unit past total shrink', [100, 10, 5, 94, 200], ['overfull', 1000000, 'tight']), ('control layout', [103, 8, 4, 116, 500], ['ok', 429, 'very_loose']), ('control layout', [92, 10, 3, 102, 1000], ['ok', 100, 'loose'])], [('regression: shrink ratio denominator', [107, 20, 11, 102, 100], ['ok', 9, 'decent']), ('regression: shrink ratio denominator', [85, 3, 7, 78, 150], ['ok', 100, 'tight']), ('regression: shrink ratio denominator', [96, 12, 2, 95, 200], ['ok', 13, 'decent']), ('partial-repair probe', [88, 8, 8, 84, 150], ['ok', 13, 'decent']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('control layout', [100, 0, 9, 105, 100], ['underfull', 10000, 'very_loose']), ('control layout', [76, 20, 1, 72, 200], ['overfull', 1000000, 'tight'])], [('regression: shrink ratio denominator', [76, 10, 6, 74, 500], ['ok', 4, 'decent']), ('regression: shrink ratio denominator', [82, 3, 7, 76, 200], ['ok', 63, 'tight']), ('regression: shrink ratio denominator', [112, 16, 9, 104, 150], ['ok', 70, 'tight']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [113, 8, 3, 103, 150], ['overfull', 1000000, 'tight']), ('control layout', [105, 12, 8, 111, 100], ['ok', 13, 'decent'])], [('regression: shrink ratio denominator', [107, 20, 11, 102, 100], ['ok', 9, 'decent']), ('regression: shrink ratio denominator', [92, 6, 12, 80, 100], ['ok', 100, 'tight']), ('regression: shrink ratio denominator', [96, 12, 2, 95, 200], ['ok', 13, 'decent']), ('regression: shrink ratio denominator', [105, 12, 5, 103, 1000], ['ok', 6, 'decent']), ('one unit past total shrink', [100, 10, 5, 94, 200], ['overfull', 1000000, 'tight']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('control layout', [114, 0, 0, 136, 500], ['underfull', 10000, 'very_loose']), ('control layout', [95, 20, 10, 113, 500], ['ok', 73, 'loose'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    natural, stretch, shrink, width, tolerance = x
    shortfall = width - natural
    if shortfall > 0:
        if stretch == 0:
            return ['underfull', 10000, 'very_loose']
        r = Fraction(shortfall, stretch)
    elif shortfall < 0:
        if -shortfall > shrink:
            return ['overfull', 1000000, 'tight']
        r = Fraction(shortfall, shrink + stretch)
    else:
        r = Fraction(0)
    badness = min(10000, math.floor(100 * abs(r) ** 3 + Fraction(1, 2)))
    if r < Fraction(-1, 2):
        fitness = 'tight'
    elif r <= Fraction(1, 2):
        fitness = 'decent'
    elif r <= 1:
        fitness = 'loose'
    else:
        fitness = 'very_loose'
    status = 'ok' if badness <= tolerance else 'underfull'
    return [status, badness, fitness]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('regression: shrink ratio denominator', [105, 12, 6, 100, 1000], ['ok', 58, 'tight']), ('regression: shrink ratio denominator', [82, 3, 10, 77, 100], ['ok', 13, 'decent']), ('regression: shrink ratio denominator', [90, 12, 2, 88, 150], ['ok', 100, 'tight']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('control layout', [116, 20, 6, 127, 1000], ['ok', 17, 'loose']), ('control layout', [69, 10, 7, 69, 100], ['ok', 0, 'decent'])], [('regression: shrink ratio denominator', [96, 4, 10, 87, 1000], ['ok', 73, 'tight']), ('regression: shrink ratio denominator', [67, 1, 8, 64, 1000], ['ok', 5, 'decent']), ('regression: shrink ratio denominator', [85, 1, 11, 80, 200], ['ok', 9, 'decent']), ('regression: shrink ratio denominator', [104, 16, 8, 96, 150], ['ok', 100, 'tight']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('one unit past total shrink', [100, 10, 5, 94, 200], ['overfull', 1000000, 'tight']), ('control layout', [103, 8, 4, 116, 500], ['ok', 429, 'very_loose']), ('control layout', [92, 10, 3, 102, 1000], ['ok', 100, 'loose'])], [('regression: shrink ratio denominator', [107, 20, 11, 102, 100], ['ok', 9, 'decent']), ('regression: shrink ratio denominator', [85, 3, 7, 78, 150], ['ok', 100, 'tight']), ('regression: shrink ratio denominator', [96, 12, 2, 95, 200], ['ok', 13, 'decent']), ('partial-repair probe', [88, 8, 8, 84, 150], ['ok', 13, 'decent']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('control layout', [100, 0, 9, 105, 100], ['underfull', 10000, 'very_loose']), ('control layout', [76, 20, 1, 72, 200], ['overfull', 1000000, 'tight'])], [('regression: shrink ratio denominator', [76, 10, 6, 74, 500], ['ok', 4, 'decent']), ('regression: shrink ratio denominator', [82, 3, 7, 76, 200], ['ok', 63, 'tight']), ('regression: shrink ratio denominator', [112, 16, 9, 104, 150], ['ok', 70, 'tight']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [113, 8, 3, 103, 150], ['overfull', 1000000, 'tight']), ('control layout', [105, 12, 8, 111, 100], ['ok', 13, 'decent'])], [('regression: shrink ratio denominator', [107, 20, 11, 102, 100], ['ok', 9, 'decent']), ('regression: shrink ratio denominator', [92, 6, 12, 80, 100], ['ok', 100, 'tight']), ('regression: shrink ratio denominator', [96, 12, 2, 95, 200], ['ok', 13, 'decent']), ('regression: shrink ratio denominator', [105, 12, 5, 103, 1000], ['ok', 6, 'decent']), ('one unit past total shrink', [100, 10, 5, 94, 200], ['overfull', 1000000, 'tight']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('control layout', [114, 0, 0, 136, 500], ['underfull', 10000, 'very_loose']), ('control layout', [95, 20, 10, 113, 500], ['ok', 73, 'loose'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Tight lines get badness and fitness computed from the wrong glue total.

Input [natural, stretch, shrink, width, tolerance] (ints). shortfall=width-natural. Positive shortfall with zero stretch is underfull 10000 very_loose; shrinking past total shrink is overfull 1000000 tight. r=shortfall/stretch (or /shrink when negative); badness=min(10000, floor(100*|r|^3+1/2)); fitness tight r<-1/2, decent r<=1/2, loose r<=1, else very_loose; status ok iff badness<=tolerance. Return [status, badness, fitness].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    natural, stretch, shrink, width, tolerance = x
    shortfall = width - natural
    if shortfall > 0:
        if stretch == 0:
            return ['underfull', 10000, 'very_loose']
        r = Fraction(shortfall, stretch)
    elif shortfall < 0:
        if -shortfall > shrink:
            return ['overfull', 1000000, 'tight']
        r = Fraction(shortfall, shrink)
    else:
        r = Fraction(0)
    badness = min(10000, math.floor(100 * abs(r) ** 2 + Fraction(1, 2)))
    if r < Fraction(-1, 2):
        fitness = 'tight'
    elif r <= Fraction(1, 2):
        fitness = 'decent'
    elif r <= 1:
        fitness = 'loose'
    else:
        fitness = 'very_loose'
    status = 'ok' if badness <= tolerance else 'underfull'
    return [status, badness, fitness]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('half stretch ratio rounds 12.5 up', [100, 10, 5, 105, 200], ['ok', 13, 'decent']), ('regression: cubic badness curve', [111, 10, 12, 125, 1000], ['ok', 274, 'very_loose']), ('regression: cubic badness curve', [76, 8, 4, 74, 500], ['ok', 13, 'decent']), ('regression: cubic badness curve', [88, 4, 3, 105, 1000], ['underfull', 7677, 'very_loose']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('one unit past total shrink', [100, 10, 5, 94, 200], ['overfull', 1000000, 'tight']), ('control layout', [62, 4, 4, 58, 200], ['ok', 100, 'tight']), ('control layout', [97, 1, 3, 91, 500], ['overfull', 1000000, 'tight'])], [('regression: cubic badness curve', [86, 10, 8, 106, 100], ['underfull', 800, 'very_loose']), ('regression: cubic badness curve', [119, 3, 8, 117, 500], ['ok', 2, 'decent']), ('regression: cubic badness curve', [99, 8, 9, 96, 100], ['ok', 4, 'decent']), ('regression: cubic badness curve', [105, 12, 6, 100, 1000], ['ok', 58, 'tight']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [75, 3, 3, 78, 500], ['ok', 100, 'loose']), ('control layout', [101, 8, 2, 91, 1000], ['overfull', 1000000, 'tight'])], [('regression: cubic badness curve', [114, 2, 7, 113, 200], ['ok', 0, 'decent']), ('regression: cubic badness curve', [81, 1, 3, 83, 100], ['underfull', 800, 'very_loose']), ('regression: cubic badness curve', [73, 10, 1, 79, 150], ['ok', 22, 'loose']), ('regression: cubic badness curve', [109, 16, 4, 117, 200], ['ok', 13, 'decent']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('control layout', [91, 16, 1, 85, 150], ['overfull', 1000000, 'tight']), ('control layout', [82, 1, 9, 82, 500], ['ok', 0, 'decent'])], [('regression: cubic badness curve', [82, 6, 9, 86, 1000], ['ok', 30, 'loose']), ('regression: cubic badness curve', [99, 16, 2, 111, 1000], ['ok', 42, 'loose']), ('regression: cubic badness curve', [80, 4, 2, 97, 500], ['underfull', 7677, 'very_loose']), ('regression: cubic badness curve', [82, 3, 10, 77, 100], ['ok', 13, 'decent']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('control layout', [105, 1, 1, 120, 500], ['underfull', 10000, 'very_loose']), ('control layout', [111, 1, 1, 134, 500], ['underfull', 10000, 'very_loose'])], [('regression: cubic badness curve', [79, 12, 5, 78, 1000], ['ok', 1, 'decent']), ('regression: cubic badness curve', [88, 4, 3, 105, 1000], ['underfull', 7677, 'very_loose']), ('regression: cubic badness curve', [108, 0, 6, 105, 1000], ['ok', 13, 'decent']), ('regression: cubic badness curve', [75, 20, 6, 71, 1000], ['ok', 30, 'tight']), ('rigid line with slack', [100, 0, 5, 110, 200], ['underfull', 10000, 'very_loose']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [71, 8, 8, 71, 150], ['ok', 0, 'decent']), ('control layout', [118, 0, 2, 133, 200], ['underfull', 10000, 'very_loose'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    natural, stretch, shrink, width, tolerance = x
    shortfall = width - natural
    if shortfall > 0:
        if stretch == 0:
            return ['underfull', 10000, 'very_loose']
        r = Fraction(shortfall, stretch)
    elif shortfall < 0:
        if -shortfall > shrink:
            return ['overfull', 1000000, 'tight']
        r = Fraction(shortfall, shrink)
    else:
        r = Fraction(0)
    badness = min(10000, math.floor(100 * abs(r) ** 2 * abs(r)))
    if r < Fraction(-1, 2):
        fitness = 'tight'
    elif r <= Fraction(1, 2):
        fitness = 'decent'
    elif r <= 1:
        fitness = 'loose'
    else:
        fitness = 'very_loose'
    status = 'ok' if badness <= tolerance else 'underfull'
    return [status, badness, fitness]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('half stretch ratio rounds 12.5 up', [100, 10, 5, 105, 200], ['ok', 13, 'decent']), ('regression: cubic badness curve', [111, 10, 12, 125, 1000], ['ok', 274, 'very_loose']), ('regression: cubic badness curve', [76, 8, 4, 74, 500], ['ok', 13, 'decent']), ('regression: cubic badness curve', [88, 4, 3, 105, 1000], ['underfull', 7677, 'very_loose']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('one unit past total shrink', [100, 10, 5, 94, 200], ['overfull', 1000000, 'tight']), ('control layout', [62, 4, 4, 58, 200], ['ok', 100, 'tight']), ('control layout', [97, 1, 3, 91, 500], ['overfull', 1000000, 'tight'])], [('regression: cubic badness curve', [86, 10, 8, 106, 100], ['underfull', 800, 'very_loose']), ('regression: cubic badness curve', [119, 3, 8, 117, 500], ['ok', 2, 'decent']), ('regression: cubic badness curve', [99, 8, 9, 96, 100], ['ok', 4, 'decent']), ('regression: cubic badness curve', [105, 12, 6, 100, 1000], ['ok', 58, 'tight']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [75, 3, 3, 78, 500], ['ok', 100, 'loose']), ('control layout', [101, 8, 2, 91, 1000], ['overfull', 1000000, 'tight'])], [('regression: cubic badness curve', [114, 2, 7, 113, 200], ['ok', 0, 'decent']), ('regression: cubic badness curve', [81, 1, 3, 83, 100], ['underfull', 800, 'very_loose']), ('regression: cubic badness curve', [73, 10, 1, 79, 150], ['ok', 22, 'loose']), ('regression: cubic badness curve', [109, 16, 4, 117, 200], ['ok', 13, 'decent']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('control layout', [91, 16, 1, 85, 150], ['overfull', 1000000, 'tight']), ('control layout', [82, 1, 9, 82, 500], ['ok', 0, 'decent'])], [('regression: cubic badness curve', [82, 6, 9, 86, 1000], ['ok', 30, 'loose']), ('regression: cubic badness curve', [99, 16, 2, 111, 1000], ['ok', 42, 'loose']), ('regression: cubic badness curve', [80, 4, 2, 97, 500], ['underfull', 7677, 'very_loose']), ('regression: cubic badness curve', [82, 3, 10, 77, 100], ['ok', 13, 'decent']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('control layout', [105, 1, 1, 120, 500], ['underfull', 10000, 'very_loose']), ('control layout', [111, 1, 1, 134, 500], ['underfull', 10000, 'very_loose'])], [('regression: cubic badness curve', [79, 12, 5, 78, 1000], ['ok', 1, 'decent']), ('regression: cubic badness curve', [88, 4, 3, 105, 1000], ['underfull', 7677, 'very_loose']), ('regression: cubic badness curve', [108, 0, 6, 105, 1000], ['ok', 13, 'decent']), ('regression: cubic badness curve', [75, 20, 6, 71, 1000], ['ok', 30, 'tight']), ('rigid line with slack', [100, 0, 5, 110, 200], ['underfull', 10000, 'very_loose']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [71, 8, 8, 71, 150], ['ok', 0, 'decent']), ('control layout', [118, 0, 2, 133, 200], ['underfull', 10000, 'very_loose'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Moderately loose lines look far better than they are.

Input [natural, stretch, shrink, width, tolerance] (ints). shortfall=width-natural. Positive shortfall with zero stretch is underfull 10000 very_loose; shrinking past total shrink is overfull 1000000 tight. r=shortfall/stretch (or /shrink when negative); badness=min(10000, floor(100*|r|^3+1/2)); fitness tight r<-1/2, decent r<=1/2, loose r<=1, else very_loose; status ok iff badness<=tolerance. Return [status, badness, fitness].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    natural, stretch, shrink, width, tolerance = x
    shortfall = width - natural
    if shortfall > 0:
        if stretch == 0:
            return ['underfull', 10000, 'very_loose']
        r = Fraction(shortfall, stretch)
    elif shortfall < 0:
        if -shortfall > shrink:
            return ['overfull', 1000000, 'tight']
        r = Fraction(shortfall, shrink)
    else:
        r = Fraction(0)
    badness = min(10000, math.floor(100 * round(abs(r), 1) ** 3 + Fraction(1, 2)))
    if r < Fraction(-1, 2):
        fitness = 'tight'
    elif r <= Fraction(1, 2):
        fitness = 'decent'
    elif r <= 1:
        fitness = 'loose'
    else:
        fitness = 'very_loose'
    status = 'ok' if badness <= tolerance else 'underfull'
    return [status, badness, fitness]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: badness rounding stage', [84, 20, 2, 101, 500], ['ok', 61, 'loose']), ('regression: badness rounding stage', [82, 6, 5, 98, 200], ['underfull', 1896, 'very_loose']), ('half stretch ratio rounds 12.5 up', [100, 10, 5, 105, 200], ['ok', 13, 'decent']), ('partial-repair probe', [111, 8, 7, 131, 150], ['underfull', 1563, 'very_loose']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [83, 0, 3, 97, 100], ['underfull', 10000, 'very_loose']), ('control layout', [94, 20, 0, 108, 100], ['ok', 34, 'loose'])], [('regression: badness rounding stage', [102, 16, 2, 113, 150], ['ok', 32, 'loose']), ('regression: badness rounding stage', [64, 8, 7, 77, 500], ['ok', 429, 'very_loose']), ('partial-repair probe', [88, 8, 8, 84, 150], ['ok', 13, 'decent']), ('partial-repair probe', [117, 2, 12, 111, 100], ['ok', 13, 'decent']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('control layout', [106, 16, 11, 95, 200], ['ok', 100, 'tight']), ('control layout', [80, 1, 6, 84, 1000], ['underfull', 6400, 'very_loose'])], [('regression: badness rounding stage', [89, 4, 12, 80, 150], ['ok', 42, 'tight']), ('regression: badness rounding stage', [119, 4, 10, 134, 100], ['underfull', 5273, 'very_loose']), ('partial-repair probe', [120, 12, 3, 126, 1000], ['ok', 13, 'decent']), ('partial-repair probe', [86, 6, 3, 89, 200], ['ok', 13, 'decent']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('control layout', [66, 4, 5, 60, 200], ['overfull', 1000000, 'tight']), ('control layout', [94, 20, 0, 108, 100], ['ok', 34, 'loose'])], [('regression: badness rounding stage', [88, 3, 12, 79, 1000], ['ok', 42, 'tight']), ('regression: badness rounding stage', [107, 16, 10, 111, 1000], ['ok', 2, 'decent']), ('partial-repair probe', [66, 2, 3, 75, 150], ['underfull', 9113, 'very_loose']), ('partial-repair probe', [120, 12, 3, 126, 1000], ['ok', 13, 'decent']), ('rigid line with slack', [100, 0, 5, 110, 200], ['underfull', 10000, 'very_loose']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('control layout', [64, 0, 3, 50, 1000], ['overfull', 1000000, 'tight']), ('control layout', [64, 4, 9, 52, 100], ['overfull', 1000000, 'tight'])], [('regression: badness rounding stage', [80, 12, 5, 88, 500], ['ok', 30, 'loose']), ('regression: badness rounding stage', [65, 16, 4, 69, 1000], ['ok', 2, 'decent']), ('partial-repair probe', [117, 2, 12, 111, 100], ['ok', 13, 'decent']), ('partial-repair probe', [109, 8, 11, 129, 100], ['underfull', 1563, 'very_loose']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [81, 4, 5, 72, 100], ['overfull', 1000000, 'tight']), ('control layout', [76, 20, 1, 72, 200], ['overfull', 1000000, 'tight'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    natural, stretch, shrink, width, tolerance = x
    shortfall = width - natural
    if shortfall > 0:
        if stretch == 0:
            return ['underfull', 10000, 'very_loose']
        r = Fraction(shortfall, stretch)
    elif shortfall < 0:
        if -shortfall > shrink:
            return ['overfull', 1000000, 'tight']
        r = Fraction(shortfall, shrink)
    else:
        r = Fraction(0)
    badness = min(10000, round(100 * abs(r) ** 3))
    if r < Fraction(-1, 2):
        fitness = 'tight'
    elif r <= Fraction(1, 2):
        fitness = 'decent'
    elif r <= 1:
        fitness = 'loose'
    else:
        fitness = 'very_loose'
    status = 'ok' if badness <= tolerance else 'underfull'
    return [status, badness, fitness]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: badness rounding stage', [84, 20, 2, 101, 500], ['ok', 61, 'loose']), ('regression: badness rounding stage', [82, 6, 5, 98, 200], ['underfull', 1896, 'very_loose']), ('half stretch ratio rounds 12.5 up', [100, 10, 5, 105, 200], ['ok', 13, 'decent']), ('partial-repair probe', [111, 8, 7, 131, 150], ['underfull', 1563, 'very_loose']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [83, 0, 3, 97, 100], ['underfull', 10000, 'very_loose']), ('control layout', [94, 20, 0, 108, 100], ['ok', 34, 'loose'])], [('regression: badness rounding stage', [102, 16, 2, 113, 150], ['ok', 32, 'loose']), ('regression: badness rounding stage', [64, 8, 7, 77, 500], ['ok', 429, 'very_loose']), ('partial-repair probe', [88, 8, 8, 84, 150], ['ok', 13, 'decent']), ('partial-repair probe', [117, 2, 12, 111, 100], ['ok', 13, 'decent']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('control layout', [106, 16, 11, 95, 200], ['ok', 100, 'tight']), ('control layout', [80, 1, 6, 84, 1000], ['underfull', 6400, 'very_loose'])], [('regression: badness rounding stage', [89, 4, 12, 80, 150], ['ok', 42, 'tight']), ('regression: badness rounding stage', [119, 4, 10, 134, 100], ['underfull', 5273, 'very_loose']), ('partial-repair probe', [120, 12, 3, 126, 1000], ['ok', 13, 'decent']), ('partial-repair probe', [86, 6, 3, 89, 200], ['ok', 13, 'decent']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('control layout', [66, 4, 5, 60, 200], ['overfull', 1000000, 'tight']), ('control layout', [94, 20, 0, 108, 100], ['ok', 34, 'loose'])], [('regression: badness rounding stage', [88, 3, 12, 79, 1000], ['ok', 42, 'tight']), ('regression: badness rounding stage', [107, 16, 10, 111, 1000], ['ok', 2, 'decent']), ('partial-repair probe', [66, 2, 3, 75, 150], ['underfull', 9113, 'very_loose']), ('partial-repair probe', [120, 12, 3, 126, 1000], ['ok', 13, 'decent']), ('rigid line with slack', [100, 0, 5, 110, 200], ['underfull', 10000, 'very_loose']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('control layout', [64, 0, 3, 50, 1000], ['overfull', 1000000, 'tight']), ('control layout', [64, 4, 9, 52, 100], ['overfull', 1000000, 'tight'])], [('regression: badness rounding stage', [80, 12, 5, 88, 500], ['ok', 30, 'loose']), ('regression: badness rounding stage', [65, 16, 4, 69, 1000], ['ok', 2, 'decent']), ('partial-repair probe', [117, 2, 12, 111, 100], ['ok', 13, 'decent']), ('partial-repair probe', [109, 8, 11, 129, 100], ['underfull', 1563, 'very_loose']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [81, 4, 5, 72, 100], ['overfull', 1000000, 'tight']), ('control layout', [76, 20, 1, 72, 200], ['overfull', 1000000, 'tight'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Badness of lines with fractional ratios drifts by several points.

Input [natural, stretch, shrink, width, tolerance] (ints). shortfall=width-natural. Positive shortfall with zero stretch is underfull 10000 very_loose; shrinking past total shrink is overfull 1000000 tight. r=shortfall/stretch (or /shrink when negative); badness=min(10000, floor(100*|r|^3+1/2)); fitness tight r<-1/2, decent r<=1/2, loose r<=1, else very_loose; status ok iff badness<=tolerance. Return [status, badness, fitness].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    natural, stretch, shrink, width, tolerance = x
    shortfall = width - natural
    if shortfall > 0:
        if stretch == 0:
            return ['underfull', 10000, 'very_loose']
        r = Fraction(shortfall, stretch)
    elif shortfall < 0:
        if -shortfall > shrink:
            return ['overfull', 1000000, 'tight']
        r = Fraction(shortfall, shrink)
    else:
        r = Fraction(0)
    badness = min(10 ** 9, math.floor(100 * abs(r) ** 3 + Fraction(1, 2)))
    if r < Fraction(-1, 2):
        fitness = 'tight'
    elif r <= Fraction(1, 2):
        fitness = 'decent'
    elif r <= 1:
        fitness = 'loose'
    else:
        fitness = 'very_loose'
    status = 'ok' if badness <= tolerance else 'underfull'
    return [status, badness, fitness]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [71, 4, 1, 93, 200], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [109, 1, 11, 127, 1000], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [101, 3, 6, 123, 200], ['underfull', 10000, 'very_loose']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('control layout', [102, 20, 7, 125, 500], ['ok', 152, 'very_loose']), ('control layout', [107, 8, 3, 121, 500], ['underfull', 536, 'very_loose'])], [('regression: badness ceiling', [94, 3, 10, 118, 500], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [105, 1, 1, 120, 500], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [101, 3, 6, 123, 200], ['underfull', 10000, 'very_loose']), ('partial-repair probe', [69, 6, 6, 85, 150], ['underfull', 1896, 'very_loose']), ('one unit past total shrink', [100, 10, 5, 94, 200], ['overfull', 1000000, 'tight']), ('half stretch ratio rounds 12.5 up', [100, 10, 5, 105, 200], ['ok', 13, 'decent']), ('control layout', [75, 12, 4, 93, 100], ['underfull', 338, 'very_loose']), ('control layout', [80, 12, 4, 75, 1000], ['overfull', 1000000, 'tight'])], [('regression: badness ceiling', [96, 1, 0, 119, 150], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [109, 1, 11, 127, 1000], ['underfull', 10000, 'very_loose']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('regression: badness ceiling', [101, 3, 6, 123, 200], ['underfull', 10000, 'very_loose']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('one unit past total shrink', [100, 10, 5, 94, 200], ['overfull', 1000000, 'tight']), ('control layout', [91, 16, 1, 85, 150], ['overfull', 1000000, 'tight']), ('control layout', [62, 4, 4, 58, 200], ['ok', 100, 'tight'])], [('regression: badness ceiling', [106, 3, 3, 126, 100], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [111, 1, 3, 129, 500], ['underfull', 10000, 'very_loose']), ('partial-repair probe', [109, 10, 12, 132, 200], ['underfull', 1217, 'very_loose']), ('regression: badness ceiling', [85, 1, 12, 100, 500], ['underfull', 10000, 'very_loose']), ('rigid line with slack', [100, 0, 5, 110, 200], ['underfull', 10000, 'very_loose']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [101, 2, 2, 93, 1000], ['overfull', 1000000, 'tight']), ('control layout', [62, 2, 9, 66, 200], ['underfull', 800, 'very_loose'])], [('regression: badness ceiling', [91, 4, 7, 115, 500], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [119, 2, 6, 138, 500], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [60, 2, 12, 73, 500], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [79, 2, 6, 95, 200], ['underfull', 10000, 'very_loose']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('control layout', [99, 16, 2, 111, 1000], ['ok', 42, 'loose']), ('control layout', [85, 1, 11, 80, 200], ['ok', 9, 'decent'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    natural, stretch, shrink, width, tolerance = x
    shortfall = width - natural
    if shortfall > 0:
        if stretch == 0:
            return ['underfull', 10000, 'very_loose']
        r = Fraction(shortfall, stretch)
    elif shortfall < 0:
        if -shortfall > shrink:
            return ['overfull', 1000000, 'tight']
        r = Fraction(shortfall, shrink)
    else:
        r = Fraction(0)
    badness = min(1000, math.floor(100 * abs(r) ** 3 + Fraction(1, 2)))
    if r < Fraction(-1, 2):
        fitness = 'tight'
    elif r <= Fraction(1, 2):
        fitness = 'decent'
    elif r <= 1:
        fitness = 'loose'
    else:
        fitness = 'very_loose'
    status = 'ok' if badness <= tolerance else 'underfull'
    return [status, badness, fitness]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [71, 4, 1, 93, 200], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [109, 1, 11, 127, 1000], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [101, 3, 6, 123, 200], ['underfull', 10000, 'very_loose']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('control layout', [102, 20, 7, 125, 500], ['ok', 152, 'very_loose']), ('control layout', [107, 8, 3, 121, 500], ['underfull', 536, 'very_loose'])], [('regression: badness ceiling', [94, 3, 10, 118, 500], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [105, 1, 1, 120, 500], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [101, 3, 6, 123, 200], ['underfull', 10000, 'very_loose']), ('partial-repair probe', [69, 6, 6, 85, 150], ['underfull', 1896, 'very_loose']), ('one unit past total shrink', [100, 10, 5, 94, 200], ['overfull', 1000000, 'tight']), ('half stretch ratio rounds 12.5 up', [100, 10, 5, 105, 200], ['ok', 13, 'decent']), ('control layout', [75, 12, 4, 93, 100], ['underfull', 338, 'very_loose']), ('control layout', [80, 12, 4, 75, 1000], ['overfull', 1000000, 'tight'])], [('regression: badness ceiling', [96, 1, 0, 119, 150], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [109, 1, 11, 127, 1000], ['underfull', 10000, 'very_loose']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('regression: badness ceiling', [101, 3, 6, 123, 200], ['underfull', 10000, 'very_loose']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('one unit past total shrink', [100, 10, 5, 94, 200], ['overfull', 1000000, 'tight']), ('control layout', [91, 16, 1, 85, 150], ['overfull', 1000000, 'tight']), ('control layout', [62, 4, 4, 58, 200], ['ok', 100, 'tight'])], [('regression: badness ceiling', [106, 3, 3, 126, 100], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [111, 1, 3, 129, 500], ['underfull', 10000, 'very_loose']), ('partial-repair probe', [109, 10, 12, 132, 200], ['underfull', 1217, 'very_loose']), ('regression: badness ceiling', [85, 1, 12, 100, 500], ['underfull', 10000, 'very_loose']), ('rigid line with slack', [100, 0, 5, 110, 200], ['underfull', 10000, 'very_loose']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [101, 2, 2, 93, 1000], ['overfull', 1000000, 'tight']), ('control layout', [62, 2, 9, 66, 200], ['underfull', 800, 'very_loose'])], [('regression: badness ceiling', [91, 4, 7, 115, 500], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [119, 2, 6, 138, 500], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [60, 2, 12, 73, 500], ['underfull', 10000, 'very_loose']), ('regression: badness ceiling', [79, 2, 6, 95, 200], ['underfull', 10000, 'very_loose']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('control layout', [99, 16, 2, 111, 1000], ['ok', 42, 'loose']), ('control layout', [85, 1, 11, 80, 200], ['ok', 9, 'decent'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Extremely loose lines report badness far above the infinite-badness ceiling.

Input [natural, stretch, shrink, width, tolerance] (ints). shortfall=width-natural. Positive shortfall with zero stretch is underfull 10000 very_loose; shrinking past total shrink is overfull 1000000 tight. r=shortfall/stretch (or /shrink when negative); badness=min(10000, floor(100*|r|^3+1/2)); fitness tight r<-1/2, decent r<=1/2, loose r<=1, else very_loose; status ok iff badness<=tolerance. Return [status, badness, fitness].

split: open-access