broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    halves = []
    for amt, carrier, tariff in x['components']:
        halves.append(math.ceil(amt / 2))
    tariffs = {c[2] for c in x['components'][:2]}
    carriers = {c[1] for c in x['components']}
    if len(tariffs) > 1: return 'ERR_TARIFF'
    if len(carriers) > 1 and not x['interline_ok']: return 'ERR_CARRIER'
    return sum(halves)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [659, 'AA', 'PUB']], 'interline_ok': False}, 731], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [601, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1202, 'LH', 'NEG']], 'interline_ok': False}, 601], ['sampled case 1', {'components': [[1106, 'AA', 'PUB'], [904, 'AA', 'PUB'], [1089, 'AA', 'PUB'], [355, 'LH', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['sampled case 2', {'components': [[898, 'AA', 'PUB'], [1009, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['sampled case 3', {'components': [[350, 'AA', 'NEG'], [1535, 'BA', 'NEG'], [587, 'BA', 'PUB'], [220, 'AA', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['regression: tariff combinability scope', {'components': [[302, 'AA', 'NEG'], [903, 'AA', 'PUB'], [781, 'BA', 'NEG'], [486, 'AA', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF']], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [661, 'AA', 'PUB']], 'interline_ok': False}, 732], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1002, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [602, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1204, 'LH', 'NEG']], 'interline_ok': False}, 602], ['sampled case 1', {'components': [[1455, 'LH', 'NEG'], [1654, 'AA', 'NEG'], [1091, 'BA', 'NEG'], [1846, 'LH', 'NEG']], 'interline_ok': True}, 3024], ['sampled case 2', {'components': [[887, 'LH', 'NEG']], 'interline_ok': False}, 444], ['sampled case 3', {'components': [[600, 'BA', 'PUB']], 'interline_ok': False}, 300], ['regression: tariff combinability scope', {'components': [[1307, 'BA', 'PUB'], [613, 'LH', 'NEG'], [1054, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF']], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [663, 'AA', 'PUB']], 'interline_ok': False}, 733], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1003, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [603, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1206, 'LH', 'NEG']], 'interline_ok': False}, 603], ['sampled case 1', {'components': [[1872, 'AA', 'NEG'], [1205, 'AA', 'NEG'], [851, 'AA', 'NEG'], [434, 'LH', 'NEG']], 'interline_ok': True}, 2182], ['sampled case 2', {'components': [[1006, 'AA', 'NEG'], [1939, 'BA', 'PUB'], [850, 'AA', 'PUB'], [1563, 'AA', 'PUB']], 'interline_ok': False}, 'ERR_TARIFF'], ['sampled case 3', {'components': [[305, 'BA', 'PUB']], 'interline_ok': False}, 153]], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [665, 'AA', 'PUB']], 'interline_ok': False}, 734], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1004, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [604, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1208, 'LH', 'NEG']], 'interline_ok': False}, 604], ['sampled case 1', {'components': [[873, 'AA', 'PUB'], [230, 'BA', 'PUB']], 'interline_ok': True}, 552], ['sampled case 2', {'components': [[1819, 'AA', 'NEG'], [1744, 'AA', 'NEG'], [1758, 'BA', 'NEG']], 'interline_ok': False}, 'ERR_CARRIER'], ['sampled case 3', {'components': [[818, 'LH', 'NEG'], [1794, 'AA', 'NEG'], [1837, 'AA', 'NEG'], [631, 'AA', 'NEG']], 'interline_ok': True}, 2541], ['regression: tariff combinability scope', {'components': [[1279, 'AA', 'NEG'], [1421, 'BA', 'PUB'], [491, 'AA', 'PUB']], 'interline_ok': False}, 'ERR_TARIFF']], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [667, 'AA', 'PUB']], 'interline_ok': False}, 735], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1005, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [605, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1210, 'LH', 'NEG']], 'interline_ok': False}, 605], ['sampled case 1', {'components': [[1193, 'BA', 'NEG'], [1868, 'AA', 'PUB']], 'interline_ok': False}, 'ERR_TARIFF'], ['sampled case 2', {'components': [[1981, 'AA', 'NEG']], 'interline_ok': True}, 991], ['sampled case 3', {'components': [[1746, 'LH', 'NEG'], [1675, 'LH', 'NEG'], [1321, 'AA', 'PUB']], 'interline_ok': True}, 'ERR_TARIFF'], ['regression: tariff combinability scope', {'components': [[506, 'LH', 'PUB'], [670, 'LH', 'NEG'], [528, 'LH', 'NEG'], [1019, 'AA', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF']]]
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
N = 1
observations = []
def solve(x):
    halves = []
    for amt, carrier, tariff in x['components']:
        halves.append(math.ceil(amt / 2))
    tariffs = {c[2] for c in x['components'][-2:]}
    carriers = {c[1] for c in x['components']}
    if len(tariffs) > 1: return 'ERR_TARIFF'
    if len(carriers) > 1 and not x['interline_ok']: return 'ERR_CARRIER'
    return sum(halves)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [659, 'AA', 'PUB']], 'interline_ok': False}, 731], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [601, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1202, 'LH', 'NEG']], 'interline_ok': False}, 601], ['sampled case 1', {'components': [[1106, 'AA', 'PUB'], [904, 'AA', 'PUB'], [1089, 'AA', 'PUB'], [355, 'LH', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['sampled case 2', {'components': [[898, 'AA', 'PUB'], [1009, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['sampled case 3', {'components': [[350, 'AA', 'NEG'], [1535, 'BA', 'NEG'], [587, 'BA', 'PUB'], [220, 'AA', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['regression: tariff combinability scope', {'components': [[302, 'AA', 'NEG'], [903, 'AA', 'PUB'], [781, 'BA', 'NEG'], [486, 'AA', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF']], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [661, 'AA', 'PUB']], 'interline_ok': False}, 732], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1002, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [602, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1204, 'LH', 'NEG']], 'interline_ok': False}, 602], ['sampled case 1', {'components': [[1455, 'LH', 'NEG'], [1654, 'AA', 'NEG'], [1091, 'BA', 'NEG'], [1846, 'LH', 'NEG']], 'interline_ok': True}, 3024], ['sampled case 2', {'components': [[887, 'LH', 'NEG']], 'interline_ok': False}, 444], ['sampled case 3', {'components': [[600, 'BA', 'PUB']], 'interline_ok': False}, 300], ['regression: tariff combinability scope', {'components': [[1307, 'BA', 'PUB'], [613, 'LH', 'NEG'], [1054, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF']], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [663, 'AA', 'PUB']], 'interline_ok': False}, 733], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1003, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [603, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1206, 'LH', 'NEG']], 'interline_ok': False}, 603], ['sampled case 1', {'components': [[1872, 'AA', 'NEG'], [1205, 'AA', 'NEG'], [851, 'AA', 'NEG'], [434, 'LH', 'NEG']], 'interline_ok': True}, 2182], ['sampled case 2', {'components': [[1006, 'AA', 'NEG'], [1939, 'BA', 'PUB'], [850, 'AA', 'PUB'], [1563, 'AA', 'PUB']], 'interline_ok': False}, 'ERR_TARIFF'], ['sampled case 3', {'components': [[305, 'BA', 'PUB']], 'interline_ok': False}, 153]], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [665, 'AA', 'PUB']], 'interline_ok': False}, 734], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1004, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [604, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1208, 'LH', 'NEG']], 'interline_ok': False}, 604], ['sampled case 1', {'components': [[873, 'AA', 'PUB'], [230, 'BA', 'PUB']], 'interline_ok': True}, 552], ['sampled case 2', {'components': [[1819, 'AA', 'NEG'], [1744, 'AA', 'NEG'], [1758, 'BA', 'NEG']], 'interline_ok': False}, 'ERR_CARRIER'], ['sampled case 3', {'components': [[818, 'LH', 'NEG'], [1794, 'AA', 'NEG'], [1837, 'AA', 'NEG'], [631, 'AA', 'NEG']], 'interline_ok': True}, 2541], ['regression: tariff combinability scope', {'components': [[1279, 'AA', 'NEG'], [1421, 'BA', 'PUB'], [491, 'AA', 'PUB']], 'interline_ok': False}, 'ERR_TARIFF']], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [667, 'AA', 'PUB']], 'interline_ok': False}, 735], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1005, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [605, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1210, 'LH', 'NEG']], 'interline_ok': False}, 605], ['sampled case 1', {'components': [[1193, 'BA', 'NEG'], [1868, 'AA', 'PUB']], 'interline_ok': False}, 'ERR_TARIFF'], ['sampled case 2', {'components': [[1981, 'AA', 'NEG']], 'interline_ok': True}, 991], ['sampled case 3', {'components': [[1746, 'LH', 'NEG'], [1675, 'LH', 'NEG'], [1321, 'AA', 'PUB']], 'interline_ok': True}, 'ERR_TARIFF'], ['regression: tariff combinability scope', {'components': [[506, 'LH', 'PUB'], [670, 'LH', 'NEG'], [528, 'LH', 'NEG'], [1019, 'AA', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF']]]
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 third component from a negotiated tariff is combined with public fares.

Input {'components':[[RT amount, carrier, tariff]],'interline_ok'}. Each component contributes half its RT amount rounded up to a whole unit. All components must share one tariff ('ERR_TARIFF', checked first); multiple carriers require interline_ok ('ERR_CARRIER'). Return the summed halves.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    halves = []
    for amt, carrier, tariff in x['components']:
        halves.append(math.ceil(amt / 2))
    tariffs = {c[2] for c in x['components']}
    carriers = {c[1] for c in x['components']}
    if len(tariffs) > 1: return 'ERR_TARIFF'
    if len(carriers) > 1 and x['interline_ok']: return 'ERR_CARRIER'
    return sum(halves)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [659, 'AA', 'PUB']], 'interline_ok': False}, 731], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [601, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1202, 'LH', 'NEG']], 'interline_ok': False}, 601], ['sampled case 1', {'components': [[1106, 'AA', 'PUB'], [904, 'AA', 'PUB'], [1089, 'AA', 'PUB'], [355, 'LH', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['sampled case 2', {'components': [[898, 'AA', 'PUB'], [1009, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['sampled case 3', {'components': [[350, 'AA', 'NEG'], [1535, 'BA', 'NEG'], [587, 'BA', 'PUB'], [220, 'AA', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF']], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [661, 'AA', 'PUB']], 'interline_ok': False}, 732], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1002, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [602, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1204, 'LH', 'NEG']], 'interline_ok': False}, 602], ['sampled case 1', {'components': [[1455, 'LH', 'NEG'], [1654, 'AA', 'NEG'], [1091, 'BA', 'NEG'], [1846, 'LH', 'NEG']], 'interline_ok': True}, 3024], ['sampled case 2', {'components': [[887, 'LH', 'NEG']], 'interline_ok': False}, 444], ['sampled case 3', {'components': [[600, 'BA', 'PUB']], 'interline_ok': False}, 300]], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [663, 'AA', 'PUB']], 'interline_ok': False}, 733], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1003, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [603, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1206, 'LH', 'NEG']], 'interline_ok': False}, 603], ['sampled case 1', {'components': [[1872, 'AA', 'NEG'], [1205, 'AA', 'NEG'], [851, 'AA', 'NEG'], [434, 'LH', 'NEG']], 'interline_ok': True}, 2182], ['sampled case 2', {'components': [[1006, 'AA', 'NEG'], [1939, 'BA', 'PUB'], [850, 'AA', 'PUB'], [1563, 'AA', 'PUB']], 'interline_ok': False}, 'ERR_TARIFF'], ['sampled case 3', {'components': [[305, 'BA', 'PUB']], 'interline_ok': False}, 153]], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [665, 'AA', 'PUB']], 'interline_ok': False}, 734], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1004, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [604, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1208, 'LH', 'NEG']], 'interline_ok': False}, 604], ['sampled case 1', {'components': [[873, 'AA', 'PUB'], [230, 'BA', 'PUB']], 'interline_ok': True}, 552], ['sampled case 2', {'components': [[1819, 'AA', 'NEG'], [1744, 'AA', 'NEG'], [1758, 'BA', 'NEG']], 'interline_ok': False}, 'ERR_CARRIER'], ['sampled case 3', {'components': [[818, 'LH', 'NEG'], [1794, 'AA', 'NEG'], [1837, 'AA', 'NEG'], [631, 'AA', 'NEG']], 'interline_ok': True}, 2541]], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [667, 'AA', 'PUB']], 'interline_ok': False}, 735], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1005, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [605, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1210, 'LH', 'NEG']], 'interline_ok': False}, 605], ['sampled case 1', {'components': [[1193, 'BA', 'NEG'], [1868, 'AA', 'PUB']], 'interline_ok': False}, 'ERR_TARIFF'], ['sampled case 2', {'components': [[1981, 'AA', 'NEG']], 'interline_ok': True}, 991], ['sampled case 3', {'components': [[1746, 'LH', 'NEG'], [1675, 'LH', 'NEG'], [1321, 'AA', 'PUB']], 'interline_ok': True}, 'ERR_TARIFF']]]
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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    halves = []
    for amt, carrier, tariff in x['components']:
        halves.append(math.ceil(amt / 2))
    tariffs = {c[2] for c in x['components']}
    carriers = {c[1] for c in x['components']}
    if len(tariffs) > 1: return 'ERR_TARIFF'
    if len(carriers) > 2 and not x['interline_ok']: return 'ERR_CARRIER'
    return sum(halves)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [659, 'AA', 'PUB']], 'interline_ok': False}, 731], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [601, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1202, 'LH', 'NEG']], 'interline_ok': False}, 601], ['sampled case 1', {'components': [[1106, 'AA', 'PUB'], [904, 'AA', 'PUB'], [1089, 'AA', 'PUB'], [355, 'LH', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['sampled case 2', {'components': [[898, 'AA', 'PUB'], [1009, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['sampled case 3', {'components': [[350, 'AA', 'NEG'], [1535, 'BA', 'NEG'], [587, 'BA', 'PUB'], [220, 'AA', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF']], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [661, 'AA', 'PUB']], 'interline_ok': False}, 732], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1002, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [602, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1204, 'LH', 'NEG']], 'interline_ok': False}, 602], ['sampled case 1', {'components': [[1455, 'LH', 'NEG'], [1654, 'AA', 'NEG'], [1091, 'BA', 'NEG'], [1846, 'LH', 'NEG']], 'interline_ok': True}, 3024], ['sampled case 2', {'components': [[887, 'LH', 'NEG']], 'interline_ok': False}, 444], ['sampled case 3', {'components': [[600, 'BA', 'PUB']], 'interline_ok': False}, 300]], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [663, 'AA', 'PUB']], 'interline_ok': False}, 733], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1003, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [603, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1206, 'LH', 'NEG']], 'interline_ok': False}, 603], ['sampled case 1', {'components': [[1872, 'AA', 'NEG'], [1205, 'AA', 'NEG'], [851, 'AA', 'NEG'], [434, 'LH', 'NEG']], 'interline_ok': True}, 2182], ['sampled case 2', {'components': [[1006, 'AA', 'NEG'], [1939, 'BA', 'PUB'], [850, 'AA', 'PUB'], [1563, 'AA', 'PUB']], 'interline_ok': False}, 'ERR_TARIFF'], ['sampled case 3', {'components': [[305, 'BA', 'PUB']], 'interline_ok': False}, 153]], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [665, 'AA', 'PUB']], 'interline_ok': False}, 734], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1004, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [604, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1208, 'LH', 'NEG']], 'interline_ok': False}, 604], ['sampled case 1', {'components': [[873, 'AA', 'PUB'], [230, 'BA', 'PUB']], 'interline_ok': True}, 552], ['sampled case 2', {'components': [[1819, 'AA', 'NEG'], [1744, 'AA', 'NEG'], [1758, 'BA', 'NEG']], 'interline_ok': False}, 'ERR_CARRIER'], ['sampled case 3', {'components': [[818, 'LH', 'NEG'], [1794, 'AA', 'NEG'], [1837, 'AA', 'NEG'], [631, 'AA', 'NEG']], 'interline_ok': True}, 2541]], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [667, 'AA', 'PUB']], 'interline_ok': False}, 735], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1005, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [605, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1210, 'LH', 'NEG']], 'interline_ok': False}, 605], ['sampled case 1', {'components': [[1193, 'BA', 'NEG'], [1868, 'AA', 'PUB']], 'interline_ok': False}, 'ERR_TARIFF'], ['sampled case 2', {'components': [[1981, 'AA', 'NEG']], 'interline_ok': True}, 991], ['sampled case 3', {'components': [[1746, 'LH', 'NEG'], [1675, 'LH', 'NEG'], [1321, 'AA', 'PUB']], 'interline_ok': True}, 'ERR_TARIFF']]]
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:
Journeys marked interline-permitted are rejected and forbidden ones pass.

Input {'components':[[RT amount, carrier, tariff]],'interline_ok'}. Each component contributes half its RT amount rounded up to a whole unit. All components must share one tariff ('ERR_TARIFF', checked first); multiple carriers require interline_ok ('ERR_CARRIER'). Return the summed halves.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    halves = []
    for amt, carrier, tariff in x['components']:
        halves.append(math.ceil(amt / 2))
    tariffs = {c[2] for c in x['components']}
    carriers = {c[1] for c in x['components']}
    if len(carriers) > 1 and not x['interline_ok']: return 'ERR_CARRIER'
    if len(tariffs) > 1: return 'ERR_TARIFF'
    return sum(halves)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [659, 'AA', 'PUB']], 'interline_ok': False}, 731], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [601, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1202, 'LH', 'NEG']], 'interline_ok': False}, 601], ['sampled case 1', {'components': [[1106, 'AA', 'PUB'], [904, 'AA', 'PUB'], [1089, 'AA', 'PUB'], [355, 'LH', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['sampled case 2', {'components': [[898, 'AA', 'PUB'], [1009, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['sampled case 3', {'components': [[350, 'AA', 'NEG'], [1535, 'BA', 'NEG'], [587, 'BA', 'PUB'], [220, 'AA', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF']], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [661, 'AA', 'PUB']], 'interline_ok': False}, 732], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1002, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [602, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1204, 'LH', 'NEG']], 'interline_ok': False}, 602], ['sampled case 1', {'components': [[1455, 'LH', 'NEG'], [1654, 'AA', 'NEG'], [1091, 'BA', 'NEG'], [1846, 'LH', 'NEG']], 'interline_ok': True}, 3024], ['sampled case 2', {'components': [[887, 'LH', 'NEG']], 'interline_ok': False}, 444], ['sampled case 3', {'components': [[600, 'BA', 'PUB']], 'interline_ok': False}, 300]], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [663, 'AA', 'PUB']], 'interline_ok': False}, 733], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1003, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [603, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1206, 'LH', 'NEG']], 'interline_ok': False}, 603], ['sampled case 1', {'components': [[1872, 'AA', 'NEG'], [1205, 'AA', 'NEG'], [851, 'AA', 'NEG'], [434, 'LH', 'NEG']], 'interline_ok': True}, 2182], ['sampled case 2', {'components': [[1006, 'AA', 'NEG'], [1939, 'BA', 'PUB'], [850, 'AA', 'PUB'], [1563, 'AA', 'PUB']], 'interline_ok': False}, 'ERR_TARIFF'], ['sampled case 3', {'components': [[305, 'BA', 'PUB']], 'interline_ok': False}, 153]], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [665, 'AA', 'PUB']], 'interline_ok': False}, 734], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1004, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [604, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1208, 'LH', 'NEG']], 'interline_ok': False}, 604], ['sampled case 1', {'components': [[873, 'AA', 'PUB'], [230, 'BA', 'PUB']], 'interline_ok': True}, 552], ['sampled case 2', {'components': [[1819, 'AA', 'NEG'], [1744, 'AA', 'NEG'], [1758, 'BA', 'NEG']], 'interline_ok': False}, 'ERR_CARRIER'], ['sampled case 3', {'components': [[818, 'LH', 'NEG'], [1794, 'AA', 'NEG'], [1837, 'AA', 'NEG'], [631, 'AA', 'NEG']], 'interline_ok': True}, 2541]], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [667, 'AA', 'PUB']], 'interline_ok': False}, 735], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1005, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [605, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1210, 'LH', 'NEG']], 'interline_ok': False}, 605], ['sampled case 1', {'components': [[1193, 'BA', 'NEG'], [1868, 'AA', 'PUB']], 'interline_ok': False}, 'ERR_TARIFF'], ['sampled case 2', {'components': [[1981, 'AA', 'NEG']], 'interline_ok': True}, 991], ['sampled case 3', {'components': [[1746, 'LH', 'NEG'], [1675, 'LH', 'NEG'], [1321, 'AA', 'PUB']], 'interline_ok': True}, 'ERR_TARIFF']]]
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
N = 1
observations = []
def solve(x):
    halves = []
    for amt, carrier, tariff in x['components']:
        halves.append(math.ceil(amt / 2))
    tariffs = {c[2] for c in x['components']}
    carriers = {c[1] for c in x['components']}
    if len(tariffs) > 1 and len(carriers) == 1: return 'ERR_TARIFF'
    if len(carriers) > 1 and not x['interline_ok']: return 'ERR_CARRIER'
    return sum(halves)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [659, 'AA', 'PUB']], 'interline_ok': False}, 731], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [601, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1202, 'LH', 'NEG']], 'interline_ok': False}, 601], ['sampled case 1', {'components': [[1106, 'AA', 'PUB'], [904, 'AA', 'PUB'], [1089, 'AA', 'PUB'], [355, 'LH', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['sampled case 2', {'components': [[898, 'AA', 'PUB'], [1009, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['sampled case 3', {'components': [[350, 'AA', 'NEG'], [1535, 'BA', 'NEG'], [587, 'BA', 'PUB'], [220, 'AA', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF']], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [661, 'AA', 'PUB']], 'interline_ok': False}, 732], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1002, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [602, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1204, 'LH', 'NEG']], 'interline_ok': False}, 602], ['sampled case 1', {'components': [[1455, 'LH', 'NEG'], [1654, 'AA', 'NEG'], [1091, 'BA', 'NEG'], [1846, 'LH', 'NEG']], 'interline_ok': True}, 3024], ['sampled case 2', {'components': [[887, 'LH', 'NEG']], 'interline_ok': False}, 444], ['sampled case 3', {'components': [[600, 'BA', 'PUB']], 'interline_ok': False}, 300]], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [663, 'AA', 'PUB']], 'interline_ok': False}, 733], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1003, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [603, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1206, 'LH', 'NEG']], 'interline_ok': False}, 603], ['sampled case 1', {'components': [[1872, 'AA', 'NEG'], [1205, 'AA', 'NEG'], [851, 'AA', 'NEG'], [434, 'LH', 'NEG']], 'interline_ok': True}, 2182], ['sampled case 2', {'components': [[1006, 'AA', 'NEG'], [1939, 'BA', 'PUB'], [850, 'AA', 'PUB'], [1563, 'AA', 'PUB']], 'interline_ok': False}, 'ERR_TARIFF'], ['sampled case 3', {'components': [[305, 'BA', 'PUB']], 'interline_ok': False}, 153]], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [665, 'AA', 'PUB']], 'interline_ok': False}, 734], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1004, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [604, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1208, 'LH', 'NEG']], 'interline_ok': False}, 604], ['sampled case 1', {'components': [[873, 'AA', 'PUB'], [230, 'BA', 'PUB']], 'interline_ok': True}, 552], ['sampled case 2', {'components': [[1819, 'AA', 'NEG'], [1744, 'AA', 'NEG'], [1758, 'BA', 'NEG']], 'interline_ok': False}, 'ERR_CARRIER'], ['sampled case 3', {'components': [[818, 'LH', 'NEG'], [1794, 'AA', 'NEG'], [1837, 'AA', 'NEG'], [631, 'AA', 'NEG']], 'interline_ok': True}, 2541]], [['odd RT fares open jaw', {'components': [[801, 'AA', 'PUB'], [667, 'AA', 'PUB']], 'interline_ok': False}, 735], ['interline allowed', {'components': [[900, 'AA', 'PUB'], [1001, 'BA', 'PUB']], 'interline_ok': True}, 951], ['interline forbidden', {'components': [[900, 'AA', 'PUB'], [1005, 'BA', 'PUB']], 'interline_ok': False}, 'ERR_CARRIER'], ['third component other tariff', {'components': [[500, 'AA', 'PUB'], [601, 'AA', 'PUB'], [703, 'AA', 'NEG']], 'interline_ok': True}, 'ERR_TARIFF'], ['tariff and carrier both differ', {'components': [[500, 'AA', 'PUB'], [605, 'LH', 'NEG']], 'interline_ok': False}, 'ERR_TARIFF'], ['single even component', {'components': [[1210, 'LH', 'NEG']], 'interline_ok': False}, 605], ['sampled case 1', {'components': [[1193, 'BA', 'NEG'], [1868, 'AA', 'PUB']], 'interline_ok': False}, 'ERR_TARIFF'], ['sampled case 2', {'components': [[1981, 'AA', 'NEG']], 'interline_ok': True}, 991], ['sampled case 3', {'components': [[1746, 'LH', 'NEG'], [1675, 'LH', 'NEG'], [1321, 'AA', 'PUB']], 'interline_ok': True}, 'ERR_TARIFF']]]
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 combination that is both cross-tariff and cross-carrier reports only ERR_CARRIER.

Input {'components':[[RT amount, carrier, tariff]],'interline_ok'}. Each component contributes half its RT amount rounded up to a whole unit. All components must share one tariff ('ERR_TARIFF', checked first); multiple carriers require interline_ok ('ERR_CARRIER'). Return the summed halves.

split: open-access


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

N = 1
observations = []
def solve(x):
    s = x
    if not s or not ('A' <= s[0] <= 'Z'): return 'ERR_BASIS'
    out = {'rbd': s[0], 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}
    i = 1
    if i < len(s) and s[i] in 'HL':
        out['season'] = s[i]
        i += 1
    if i < len(s) and s[i] in 'WX':
        out['days'] = 'WEEKEND' if s[i] == 'W' else 'WEEKDAY'
        i += 1
    j = i
    if j < len(s) and s[j].isdigit():
        j += 1
    out['ap'] = int(s[i:j]) if j > i else 0
    rest = s[j:]
    if len(rest) % 2: return 'ERR_TOKEN'
    for k in range(0, len(rest), 2):
        tok = rest[k:k + 2]
        if tok not in ('CH', 'IN', 'NR'): return 'ERR_TOKEN'
        out['flags'].append(tok)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['full basis', 'QLX8NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 8, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW110IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 110, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW3NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 3, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'NHX120', {'rbd': 'N', 'season': 'H', 'days': 'WEEKDAY', 'ap': 120, 'flags': []}], ['sampled case 2', 'qX14C', 'ERR_BASIS'], ['sampled case 3', 'THW', {'rbd': 'T', 'season': 'H', 'days': 'WEEKEND', 'ap': 0, 'flags': []}]], [['full basis', 'QLX9NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 9, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW120IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 120, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW4NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 4, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', '7W1', 'ERR_BASIS'], ['sampled case 2', 'q1', 'ERR_BASIS'], ['sampled case 3', 'qHXZZ', 'ERR_BASIS']], [['full basis', 'QLX10NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 10, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW130IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 130, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW5NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 5, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'VLXINC', 'ERR_TOKEN'], ['sampled case 2', 'QHW30CH', {'rbd': 'Q', 'season': 'H', 'days': 'WEEKEND', 'ap': 30, 'flags': ['CH']}], ['sampled case 3', 'B14CHIN', {'rbd': 'B', 'season': None, 'days': 'ANY', 'ap': 14, 'flags': ['CH', 'IN']}]], [['full basis', 'QLX11NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 11, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW140IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 140, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW6NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 6, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'MZZIN', 'ERR_TOKEN'], ['sampled case 2', 'MLC', 'ERR_TOKEN'], ['sampled case 3', 'THIN', {'rbd': 'T', 'season': 'H', 'days': 'ANY', 'ap': 0, 'flags': ['IN']}]], [['full basis', 'QLX12NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 12, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW150IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 150, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW7NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 7, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'LLWNRNR', {'rbd': 'L', 'season': 'L', 'days': 'WEEKEND', 'ap': 0, 'flags': ['NR', 'NR']}], ['sampled case 2', 'NHXNRZZ', 'ERR_TOKEN'], ['sampled case 3', 'TNR', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': ['NR']}]]]
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

N = 1
observations = []
def solve(x):
    s = x
    if not s or not ('A' <= s[0] <= 'Z'): return 'ERR_BASIS'
    out = {'rbd': s[0], 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}
    i = 1
    if i < len(s) and s[i] in 'HL':
        out['season'] = s[i]
        i += 1
    if i < len(s) and s[i] in 'WX':
        out['days'] = 'WEEKEND' if s[i] == 'W' else 'WEEKDAY'
        i += 1
    j = i
    while j < len(s) and s[j].isdigit() and j - i < 2:
        j += 1
    out['ap'] = int(s[i:j]) if j > i else 0
    rest = s[j:]
    if len(rest) % 2: return 'ERR_TOKEN'
    for k in range(0, len(rest), 2):
        tok = rest[k:k + 2]
        if tok not in ('CH', 'IN', 'NR'): return 'ERR_TOKEN'
        out['flags'].append(tok)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['full basis', 'QLX8NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 8, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW110IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 110, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW3NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 3, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'NHX120', {'rbd': 'N', 'season': 'H', 'days': 'WEEKDAY', 'ap': 120, 'flags': []}], ['sampled case 2', 'qX14C', 'ERR_BASIS'], ['sampled case 3', 'THW', {'rbd': 'T', 'season': 'H', 'days': 'WEEKEND', 'ap': 0, 'flags': []}]], [['full basis', 'QLX9NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 9, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW120IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 120, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW4NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 4, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', '7W1', 'ERR_BASIS'], ['sampled case 2', 'q1', 'ERR_BASIS'], ['sampled case 3', 'qHXZZ', 'ERR_BASIS']], [['full basis', 'QLX10NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 10, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW130IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 130, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW5NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 5, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'VLXINC', 'ERR_TOKEN'], ['sampled case 2', 'QHW30CH', {'rbd': 'Q', 'season': 'H', 'days': 'WEEKEND', 'ap': 30, 'flags': ['CH']}], ['sampled case 3', 'B14CHIN', {'rbd': 'B', 'season': None, 'days': 'ANY', 'ap': 14, 'flags': ['CH', 'IN']}]], [['full basis', 'QLX11NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 11, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW140IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 140, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW6NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 6, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'MZZIN', 'ERR_TOKEN'], ['sampled case 2', 'MLC', 'ERR_TOKEN'], ['sampled case 3', 'THIN', {'rbd': 'T', 'season': 'H', 'days': 'ANY', 'ap': 0, 'flags': ['IN']}]], [['full basis', 'QLX12NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 12, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW150IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 150, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW7NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 7, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'LLWNRNR', {'rbd': 'L', 'season': 'L', 'days': 'WEEKEND', 'ap': 0, 'flags': ['NR', 'NR']}], ['sampled case 2', 'NHXNRZZ', 'ERR_TOKEN'], ['sampled case 3', 'TNR', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': ['NR']}]]]
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:
QLX14NR decodes as a 1-day advance purchase followed by an invalid token.

Input: a fare basis string. Grammar: RBD letter A-Z (ASCII uppercase, else 'ERR_BASIS'), optional season H|L, optional day code W (WEEKEND) | X (WEEKDAY), optional advance purchase digits of any length (default 0), then two-letter tokens from CH, IN, NR (otherwise or odd length -> 'ERR_TOKEN'). Return {'rbd','season','days','ap','flags'}.

split: open-access


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

N = 1
observations = []
def solve(x):
    s = x
    if not s or not ('A' <= s[0] <= 'Z'): return 'ERR_BASIS'
    out = {'rbd': s[0], 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}
    i = 1
    if i < len(s) and s[i] in 'HL':
        out['season'] = s[i]
        i += 1
    if i < len(s) and s[i] in 'WX':
        out['days'] = 'WEEKEND' if s[i] == 'X' else 'WEEKDAY'
        i += 1
    j = i
    while j < len(s) and s[j].isdigit():
        j += 1
    out['ap'] = int(s[i:j]) if j > i else 0
    rest = s[j:]
    if len(rest) % 2: return 'ERR_TOKEN'
    for k in range(0, len(rest), 2):
        tok = rest[k:k + 2]
        if tok not in ('CH', 'IN', 'NR'): return 'ERR_TOKEN'
        out['flags'].append(tok)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['full basis', 'QLX8NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 8, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW110IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 110, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW3NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 3, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'NHX120', {'rbd': 'N', 'season': 'H', 'days': 'WEEKDAY', 'ap': 120, 'flags': []}], ['sampled case 2', 'qX14C', 'ERR_BASIS'], ['sampled case 3', 'THW', {'rbd': 'T', 'season': 'H', 'days': 'WEEKEND', 'ap': 0, 'flags': []}]], [['full basis', 'QLX9NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 9, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW120IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 120, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW4NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 4, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', '7W1', 'ERR_BASIS'], ['sampled case 2', 'q1', 'ERR_BASIS'], ['sampled case 3', 'qHXZZ', 'ERR_BASIS']], [['full basis', 'QLX10NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 10, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW130IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 130, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW5NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 5, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'VLXINC', 'ERR_TOKEN'], ['sampled case 2', 'QHW30CH', {'rbd': 'Q', 'season': 'H', 'days': 'WEEKEND', 'ap': 30, 'flags': ['CH']}], ['sampled case 3', 'B14CHIN', {'rbd': 'B', 'season': None, 'days': 'ANY', 'ap': 14, 'flags': ['CH', 'IN']}]], [['full basis', 'QLX11NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 11, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW140IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 140, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW6NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 6, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'MZZIN', 'ERR_TOKEN'], ['sampled case 2', 'MLC', 'ERR_TOKEN'], ['sampled case 3', 'THIN', {'rbd': 'T', 'season': 'H', 'days': 'ANY', 'ap': 0, 'flags': ['IN']}]], [['full basis', 'QLX12NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 12, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW150IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 150, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW7NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 7, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'LLWNRNR', {'rbd': 'L', 'season': 'L', 'days': 'WEEKEND', 'ap': 0, 'flags': ['NR', 'NR']}], ['sampled case 2', 'NHXNRZZ', 'ERR_TOKEN'], ['sampled case 3', 'TNR', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': ['NR']}]]]
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

N = 1
observations = []
def solve(x):
    s = x
    if not s or not ('A' <= s[0] <= 'Z'): return 'ERR_BASIS'
    out = {'rbd': s[0], 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}
    i = 1
    if i < len(s) and s[i] in 'HL':
        out['season'] = s[i]
        i += 1
    if i < len(s) and s[i] in 'WX':
        out['days'] = 'WEEKEND' if s[i] == 'W' else 'WEEKDAY'
    j = i
    while j < len(s) and s[j].isdigit():
        j += 1
    out['ap'] = int(s[i:j]) if j > i else 0
    rest = s[j:]
    if len(rest) % 2: return 'ERR_TOKEN'
    for k in range(0, len(rest), 2):
        tok = rest[k:k + 2]
        if tok not in ('CH', 'IN', 'NR'): return 'ERR_TOKEN'
        out['flags'].append(tok)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['full basis', 'QLX8NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 8, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW110IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 110, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW3NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 3, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'NHX120', {'rbd': 'N', 'season': 'H', 'days': 'WEEKDAY', 'ap': 120, 'flags': []}], ['sampled case 2', 'qX14C', 'ERR_BASIS'], ['sampled case 3', 'THW', {'rbd': 'T', 'season': 'H', 'days': 'WEEKEND', 'ap': 0, 'flags': []}]], [['full basis', 'QLX9NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 9, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW120IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 120, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW4NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 4, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', '7W1', 'ERR_BASIS'], ['sampled case 2', 'q1', 'ERR_BASIS'], ['sampled case 3', 'qHXZZ', 'ERR_BASIS']], [['full basis', 'QLX10NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 10, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW130IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 130, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW5NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 5, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'VLXINC', 'ERR_TOKEN'], ['sampled case 2', 'QHW30CH', {'rbd': 'Q', 'season': 'H', 'days': 'WEEKEND', 'ap': 30, 'flags': ['CH']}], ['sampled case 3', 'B14CHIN', {'rbd': 'B', 'season': None, 'days': 'ANY', 'ap': 14, 'flags': ['CH', 'IN']}]], [['full basis', 'QLX11NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 11, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW140IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 140, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW6NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 6, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'MZZIN', 'ERR_TOKEN'], ['sampled case 2', 'MLC', 'ERR_TOKEN'], ['sampled case 3', 'THIN', {'rbd': 'T', 'season': 'H', 'days': 'ANY', 'ap': 0, 'flags': ['IN']}]], [['full basis', 'QLX12NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 12, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW150IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 150, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW7NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 7, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'LLWNRNR', {'rbd': 'L', 'season': 'L', 'days': 'WEEKEND', 'ap': 0, 'flags': ['NR', 'NR']}], ['sampled case 2', 'NHXNRZZ', 'ERR_TOKEN'], ['sampled case 3', 'TNR', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': ['NR']}]]]
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:
Weekend fares are reported as weekday-only.

Input: a fare basis string. Grammar: RBD letter A-Z (ASCII uppercase, else 'ERR_BASIS'), optional season H|L, optional day code W (WEEKEND) | X (WEEKDAY), optional advance purchase digits of any length (default 0), then two-letter tokens from CH, IN, NR (otherwise or odd length -> 'ERR_TOKEN'). Return {'rbd','season','days','ap','flags'}.

split: open-access


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

N = 1
observations = []
def solve(x):
    s = x
    if not s or not ('A' <= s[0] <= 'Z'): return 'ERR_BASIS'
    out = {'rbd': s[0], 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}
    i = 1
    if i < len(s) and s[i] in 'HL':
        out['season'] = s[i]
        i += 1
    if i < len(s) and s[i] in 'WX':
        out['days'] = 'WEEKEND' if s[i] == 'W' else 'WEEKDAY'
        i += 1
    j = i
    while j < len(s) and s[j].isdigit():
        j += 1
    out['ap'] = int(s[i:j]) if j > i else 0
    rest = s[j:]
    if len(rest) % 2: return 'ERR_TOKEN'
    for k in range(0, len(rest), 2):
        tok = rest[k:k + 2]
        if tok not in ('CH', 'IN', 'NR'): continue
        out['flags'].append(tok)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['full basis', 'QLX8NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 8, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW110IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 110, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW3NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 3, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'NHX120', {'rbd': 'N', 'season': 'H', 'days': 'WEEKDAY', 'ap': 120, 'flags': []}], ['sampled case 2', 'qX14C', 'ERR_BASIS'], ['sampled case 3', 'THW', {'rbd': 'T', 'season': 'H', 'days': 'WEEKEND', 'ap': 0, 'flags': []}]], [['full basis', 'QLX9NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 9, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW120IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 120, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW4NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 4, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', '7W1', 'ERR_BASIS'], ['sampled case 2', 'q1', 'ERR_BASIS'], ['sampled case 3', 'qHXZZ', 'ERR_BASIS']], [['full basis', 'QLX10NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 10, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW130IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 130, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW5NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 5, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'VLXINC', 'ERR_TOKEN'], ['sampled case 2', 'QHW30CH', {'rbd': 'Q', 'season': 'H', 'days': 'WEEKEND', 'ap': 30, 'flags': ['CH']}], ['sampled case 3', 'B14CHIN', {'rbd': 'B', 'season': None, 'days': 'ANY', 'ap': 14, 'flags': ['CH', 'IN']}]], [['full basis', 'QLX11NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 11, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW140IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 140, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW6NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 6, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'MZZIN', 'ERR_TOKEN'], ['sampled case 2', 'MLC', 'ERR_TOKEN'], ['sampled case 3', 'THIN', {'rbd': 'T', 'season': 'H', 'days': 'ANY', 'ap': 0, 'flags': ['IN']}]], [['full basis', 'QLX12NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 12, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW150IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 150, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW7NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 7, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'LLWNRNR', {'rbd': 'L', 'season': 'L', 'days': 'WEEKEND', 'ap': 0, 'flags': ['NR', 'NR']}], ['sampled case 2', 'NHXNRZZ', 'ERR_TOKEN'], ['sampled case 3', 'TNR', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': ['NR']}]]]
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

N = 1
observations = []
def solve(x):
    s = x
    if not s or not ('A' <= s[0] <= 'Z'): return 'ERR_BASIS'
    out = {'rbd': s[0], 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}
    i = 1
    if i < len(s) and s[i] in 'HL':
        out['season'] = s[i]
        i += 1
    if i < len(s) and s[i] in 'WX':
        out['days'] = 'WEEKEND' if s[i] == 'W' else 'WEEKDAY'
        i += 1
    j = i
    while j < len(s) and s[j].isdigit():
        j += 1
    out['ap'] = int(s[i:j]) if j > i else 0
    rest = s[j:]
    if len(rest) % 2: return 'ERR_TOKEN'
    for k in range(0, len(rest), 2):
        tok = rest[k:k + 2]
        if any(ch.isdigit() for ch in tok): return 'ERR_TOKEN'
        out['flags'].append(tok)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['full basis', 'QLX8NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 8, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW110IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 110, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW3NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 3, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'NHX120', {'rbd': 'N', 'season': 'H', 'days': 'WEEKDAY', 'ap': 120, 'flags': []}], ['sampled case 2', 'qX14C', 'ERR_BASIS'], ['sampled case 3', 'THW', {'rbd': 'T', 'season': 'H', 'days': 'WEEKEND', 'ap': 0, 'flags': []}]], [['full basis', 'QLX9NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 9, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW120IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 120, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW4NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 4, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', '7W1', 'ERR_BASIS'], ['sampled case 2', 'q1', 'ERR_BASIS'], ['sampled case 3', 'qHXZZ', 'ERR_BASIS']], [['full basis', 'QLX10NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 10, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW130IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 130, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW5NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 5, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'VLXINC', 'ERR_TOKEN'], ['sampled case 2', 'QHW30CH', {'rbd': 'Q', 'season': 'H', 'days': 'WEEKEND', 'ap': 30, 'flags': ['CH']}], ['sampled case 3', 'B14CHIN', {'rbd': 'B', 'season': None, 'days': 'ANY', 'ap': 14, 'flags': ['CH', 'IN']}]], [['full basis', 'QLX11NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 11, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW140IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 140, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW6NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 6, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'MZZIN', 'ERR_TOKEN'], ['sampled case 2', 'MLC', 'ERR_TOKEN'], ['sampled case 3', 'THIN', {'rbd': 'T', 'season': 'H', 'days': 'ANY', 'ap': 0, 'flags': ['IN']}]], [['full basis', 'QLX12NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 12, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW150IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 150, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW7NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 7, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'LLWNRNR', {'rbd': 'L', 'season': 'L', 'days': 'WEEKEND', 'ap': 0, 'flags': ['NR', 'NR']}], ['sampled case 2', 'NHXNRZZ', 'ERR_TOKEN'], ['sampled case 3', 'TNR', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': ['NR']}]]]
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 corrupted basis such as MH14ZZ decodes as valid with no flags.

Input: a fare basis string. Grammar: RBD letter A-Z (ASCII uppercase, else 'ERR_BASIS'), optional season H|L, optional day code W (WEEKEND) | X (WEEKDAY), optional advance purchase digits of any length (default 0), then two-letter tokens from CH, IN, NR (otherwise or odd length -> 'ERR_TOKEN'). Return {'rbd','season','days','ap','flags'}.

split: open-access


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

N = 1
observations = []
def solve(x):
    s = x
    if not s or not ('A' <= s[0] <= 'Z'): return 'ERR_BASIS'
    out = {'rbd': s[0], 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}
    i = 1
    if i < len(s) and s[i].isalpha():
        out['season'] = s[i]
        i += 1
    if i < len(s) and s[i] in 'WX':
        out['days'] = 'WEEKEND' if s[i] == 'W' else 'WEEKDAY'
        i += 1
    j = i
    while j < len(s) and s[j].isdigit():
        j += 1
    out['ap'] = int(s[i:j]) if j > i else 0
    rest = s[j:]
    if len(rest) % 2: return 'ERR_TOKEN'
    for k in range(0, len(rest), 2):
        tok = rest[k:k + 2]
        if tok not in ('CH', 'IN', 'NR'): return 'ERR_TOKEN'
        out['flags'].append(tok)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['full basis', 'QLX8NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 8, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW110IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 110, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW3NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 3, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'NHX120', {'rbd': 'N', 'season': 'H', 'days': 'WEEKDAY', 'ap': 120, 'flags': []}], ['sampled case 2', 'qX14C', 'ERR_BASIS'], ['sampled case 3', 'THW', {'rbd': 'T', 'season': 'H', 'days': 'WEEKEND', 'ap': 0, 'flags': []}]], [['full basis', 'QLX9NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 9, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW120IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 120, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW4NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 4, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', '7W1', 'ERR_BASIS'], ['sampled case 2', 'q1', 'ERR_BASIS'], ['sampled case 3', 'qHXZZ', 'ERR_BASIS']], [['full basis', 'QLX10NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 10, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW130IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 130, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW5NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 5, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'VLXINC', 'ERR_TOKEN'], ['sampled case 2', 'QHW30CH', {'rbd': 'Q', 'season': 'H', 'days': 'WEEKEND', 'ap': 30, 'flags': ['CH']}], ['sampled case 3', 'B14CHIN', {'rbd': 'B', 'season': None, 'days': 'ANY', 'ap': 14, 'flags': ['CH', 'IN']}]], [['full basis', 'QLX11NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 11, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW140IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 140, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW6NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 6, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'MZZIN', 'ERR_TOKEN'], ['sampled case 2', 'MLC', 'ERR_TOKEN'], ['sampled case 3', 'THIN', {'rbd': 'T', 'season': 'H', 'days': 'ANY', 'ap': 0, 'flags': ['IN']}]], [['full basis', 'QLX12NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 12, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW150IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 150, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW7NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 7, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'LLWNRNR', {'rbd': 'L', 'season': 'L', 'days': 'WEEKEND', 'ap': 0, 'flags': ['NR', 'NR']}], ['sampled case 2', 'NHXNRZZ', 'ERR_TOKEN'], ['sampled case 3', 'TNR', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': ['NR']}]]]
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

N = 1
observations = []
def solve(x):
    s = x
    if not s or not ('A' <= s[0] <= 'Z'): return 'ERR_BASIS'
    out = {'rbd': s[0], 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}
    i = 1
    if i < len(s) and s[i] not in 'WX':
        out['season'] = s[i]
        i += 1
    if i < len(s) and s[i] in 'WX':
        out['days'] = 'WEEKEND' if s[i] == 'W' else 'WEEKDAY'
        i += 1
    j = i
    while j < len(s) and s[j].isdigit():
        j += 1
    out['ap'] = int(s[i:j]) if j > i else 0
    rest = s[j:]
    if len(rest) % 2: return 'ERR_TOKEN'
    for k in range(0, len(rest), 2):
        tok = rest[k:k + 2]
        if tok not in ('CH', 'IN', 'NR'): return 'ERR_TOKEN'
        out['flags'].append(tok)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['full basis', 'QLX8NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 8, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW110IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 110, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW3NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 3, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'NHX120', {'rbd': 'N', 'season': 'H', 'days': 'WEEKDAY', 'ap': 120, 'flags': []}], ['sampled case 2', 'qX14C', 'ERR_BASIS'], ['sampled case 3', 'THW', {'rbd': 'T', 'season': 'H', 'days': 'WEEKEND', 'ap': 0, 'flags': []}]], [['full basis', 'QLX9NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 9, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW120IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 120, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW4NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 4, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', '7W1', 'ERR_BASIS'], ['sampled case 2', 'q1', 'ERR_BASIS'], ['sampled case 3', 'qHXZZ', 'ERR_BASIS']], [['full basis', 'QLX10NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 10, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW130IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 130, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW5NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 5, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'VLXINC', 'ERR_TOKEN'], ['sampled case 2', 'QHW30CH', {'rbd': 'Q', 'season': 'H', 'days': 'WEEKEND', 'ap': 30, 'flags': ['CH']}], ['sampled case 3', 'B14CHIN', {'rbd': 'B', 'season': None, 'days': 'ANY', 'ap': 14, 'flags': ['CH', 'IN']}]], [['full basis', 'QLX11NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 11, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW140IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 140, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW6NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 6, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'MZZIN', 'ERR_TOKEN'], ['sampled case 2', 'MLC', 'ERR_TOKEN'], ['sampled case 3', 'THIN', {'rbd': 'T', 'season': 'H', 'days': 'ANY', 'ap': 0, 'flags': ['IN']}]], [['full basis', 'QLX12NRCH', {'rbd': 'Q', 'season': 'L', 'days': 'WEEKDAY', 'ap': 12, 'flags': ['NR', 'CH']}], ['three-digit advance purchase', 'VHW150IN', {'rbd': 'V', 'season': 'H', 'days': 'WEEKEND', 'ap': 150, 'flags': ['IN']}], ['rbd only', 'Y', {'rbd': 'Y', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': []}], ['weekend without season', 'KW7NR', {'rbd': 'K', 'season': None, 'days': 'WEEKEND', 'ap': 7, 'flags': ['NR']}], ['unknown suffix token', 'MH14ZZ', 'ERR_TOKEN'], ['odd suffix length', 'BL3NRC', 'ERR_TOKEN'], ['non-ASCII leading letter', 'ÉL7', 'ERR_BASIS'], ['lowercase basis', 'qlx7', 'ERR_BASIS'], ['digits right after rbd', 'T21CH', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 21, 'flags': ['CH']}], ['sampled case 1', 'LLWNRNR', {'rbd': 'L', 'season': 'L', 'days': 'WEEKEND', 'ap': 0, 'flags': ['NR', 'NR']}], ['sampled case 2', 'NHXNRZZ', 'ERR_TOKEN'], ['sampled case 3', 'TNR', {'rbd': 'T', 'season': None, 'days': 'ANY', 'ap': 0, 'flags': ['NR']}]]]
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:
KW3NR decodes season W and loses the weekend day code.

Input: a fare basis string. Grammar: RBD letter A-Z (ASCII uppercase, else 'ERR_BASIS'), optional season H|L, optional day code W (WEEKEND) | X (WEEKDAY), optional advance purchase digits of any length (default 0), then two-letter tokens from CH, IN, NR (otherwise or odd length -> 'ERR_TOKEN'). Return {'rbd','season','days','ap','flags'}.

split: open-access