FA-66541 / Airline fare rule evaluation / Open access
Closed booking classes still priced · case 01
The lowest quote uses a class with no seats left.
ROOT CAUSE
The applicability filter does not check the booking class against open inventory.
THE FAILURE
The applicability filter does not check the booking class against open inventory.
Unsuccessful approach: Checking availability only for one-way fares still sells closed RT classes.
Case contract
Input {'fares':[[basis, amount, rbd, min AP days, 'OW'|'RT']],'trip','ap_days','rbd_open'}. A fare applies if its AP requirement <= ap_days and its booking class is open. OW trips use OW fares only; RT trips use an RT fare or two of the same OW fare. Pick the lowest total; ties prefer the booking class earlier in 'YBMHQVLKTN'. Return [[bases], total] or 'NO_FARE'.
Why this case matters
Fare shopping filters by rule applicability and inventory, compares round-trip fares against doubled one-way fares, and needs a deterministic tie rule.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
ap = x['ap_days']
open_ = set(x['rbd_open'])
order = 'YBMHQVLKTN'
ok = [f for f in x['fares'] if f[3] <= ap]
opts = []
for basis, amt, rbd, minap, kind in ok:
if x['trip'] == 'OW' and kind == 'OW':
opts.append((amt, order.index(rbd), [basis]))
if x['trip'] == 'RT' and kind == 'RT':
opts.append((amt, order.index(rbd), [basis]))
if x['trip'] == 'RT' and kind == 'OW':
opts.append((2 * amt, order.index(rbd), [basis, basis]))
if not opts: return 'NO_FARE'
opts.sort(key=lambda o: (o[0], o[1]))
return [opts[0][2], opts[0][0]]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['RT beats doubled OW', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 15, 'rbd_open': ['Y', 'B', 'M', 'H', 'Q', 'V', 'L', 'K', 'T']}, [['VOW7', 'VOW7'], 640]], ['doubled OW beats RT', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'M', 'V', 'H']}, [['VOW7', 'VOW7'], 640]], ['exactly AP days', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['VOW7'], 320]], ['one day short of AP', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 6, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['HOW3'], 390]], ['closed cheap class', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 11, 'rbd_open': ['Y', 'B', 'H']}, [['HOW3'], 390]], ['price tie between classes', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 30, 'rbd_open': ['Y', 'B', 'M', 'K', 'L']}, [['LRT21'], 640]], ['nothing sellable', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 1, 'rbd_open': ['Q', 'L', 'K']}, 'NO_FARE'], ['OW trip ignores RT fares', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 21, 'rbd_open': ['Y', 'Q', 'L', 'K']}, [['YOW'], 900]], ['sampled case 1', {'fares': [['BOW0', 1090, 'B', 3, 'OW'], ['TRT1', 1190, 'T', 7, 'RT'], ['TRT2', 570, 'T', 0, 'RT'], ['MOW3', 1370, 'M', 3, 'OW']], 'trip': 'RT', 'ap_days': 0, 'rbd_open': ['B', 'H', 'K', 'L', 'M', 'N', 'T', 'Y']}, [['TRT2'], 570]], ['sampled case 2', {'fares': [['TRT0', 970, 'T', 0, 'RT'], ['TOW1', 780, 'T', 3, 'OW'], ['LRT2', 800, 'L', 7, 'RT'], ['VRT3', 1290, 'V', 14, 'RT'], ['BOW4', 1450, 'B', 21, 'OW']], 'trip': 'OW', 'ap_days': 30, 'rbd_open': ['Y']}, 'NO_FARE'], ['sampled case 3', {'fares': [['KRT0', 550, 'K', 3, 'RT'], ['HRT1', 1290, 'H', 3, 'RT'], ['TOW2', 1300, 'T', 7, 'OW'], ['MOW3', 480, 'M', 21, 'OW']], 'trip': 'OW', 'ap_days': 7, 'rbd_open': ['B', 'H', 'M', 'T', 'Y']}, [['TOW2'], 1300]], ['regression: booking class availability', {'fares': [['YRT0', 160, 'Y', 3, 'RT'], ['BRT1', 650, 'B', 3, 'RT'], ['BOW2', 1310, 'B', 0, 'OW'], ['BRT3', 1490, 'B', 7, 'RT'], ['LOW4', 460, 'L', 3, 'OW'], ['NOW5', 730, 'N', 3, 'OW']], 'trip': 'RT', 'ap_days': 21, 'rbd_open': ['H', 'K', 'M', 'N', 'Q', 'T']}, [['NOW5', 'NOW5'], 1460]]], [['RT beats doubled OW', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 16, 'rbd_open': ['Y', 'B', 'M', 'H', 'Q', 'V', 'L', 'K', 'T']}, [['VOW7', 'VOW7'], 640]], ['doubled OW beats RT', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'M', 'V', 'H']}, [['VOW7', 'VOW7'], 640]], ['exactly AP days', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['VOW7'], 320]], ['one day short of AP', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 6, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['HOW3'], 390]], ['closed cheap class', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 12, 'rbd_open': ['Y', 'B', 'H']}, [['HOW3'], 390]], ['price tie between classes', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 30, 'rbd_open': ['Y', 'B', 'M', 'K', 'L']}, [['LRT21'], 640]], ['nothing sellable', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 1, 'rbd_open': ['Q', 'L', 'K']}, 'NO_FARE'], ['OW trip ignores RT fares', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 21, 'rbd_open': ['Y', 'Q', 'L', 'K']}, [['YOW'], 900]], ['sampled case 1', {'fares': [['NOW0', 1290, 'N', 0, 'OW'], ['YRT1', 1250, 'Y', 0, 'RT'], ['LOW2', 190, 'L', 7, 'OW']], 'trip': 'OW', 'ap_days': 7, 'rbd_open': ['K', 'T']}, 'NO_FARE'], ['sampled case 2', {'fares': [['TRT0', 1050, 'T', 3, 'RT'], ['KOW1', 890, 'K', 21, 'OW'], ['TOW2', 1070, 'T', 3, 'OW'], ['HOW3', 880, 'H', 14, 'OW'], ['VOW4', 480, 'V', 0, 'OW']], 'trip': 'RT', 'ap_days': 3, 'rbd_open': ['B', 'H', 'K', 'L', 'N', 'Q', 'V', 'Y']}, [['VOW4', 'VOW4'], 960]], ['sampled case 3', {'fares': [['QOW0', 1370, 'Q', 14, 'OW'], ['HRT1', 320, 'H', 3, 'RT'], ['BOW2', 860, 'B', 21, 'OW'], ['LRT3', 1490, 'L', 3, 'RT'], ['LOW4', 1320, 'L', 0, 'OW']], 'trip': 'RT', 'ap_days': 3, 'rbd_open': ['H', 'K', 'L', 'M', 'N', 'Q', 'T', 'V', 'Y']}, [['HRT1'], 320]], ['regression: booking class availability', {'fares': [['BRT0', 940, 'B', 21, 'RT'], ['HRT1', 1070, 'H', 3, 'RT'], ['VRT2', 1170, 'V', 14, 'RT'], ['KOW3', 1240, 'K', 3, 'OW'], ['KOW4', 1280, 'K', 7, 'OW']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['V']}, 'NO_FARE']], [['RT beats doubled OW', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 17, 'rbd_open': ['Y', 'B', 'M', 'H', 'Q', 'V', 'L', 'K', 'T']}, [['VOW7', 'VOW7'], 640]], ['doubled OW beats RT', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'M', 'V', 'H']}, [['VOW7', 'VOW7'], 640]], ['exactly AP days', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['VOW7'], 320]], ['one day short of AP', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 6, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['HOW3'], 390]], ['closed cheap class', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 13, 'rbd_open': ['Y', 'B', 'H']}, [['HOW3'], 390]], ['price tie between classes', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 30, 'rbd_open': ['Y', 'B', 'M', 'K', 'L']}, [['LRT21'], 640]], ['nothing sellable', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 1, 'rbd_open': ['Q', 'L', 'K']}, 'NO_FARE'], ['OW trip ignores RT fares', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 21, 'rbd_open': ['Y', 'Q', 'L', 'K']}, [['YOW'], 900]], ['sampled case 1', {'fares': [['KOW0', 1090, 'K', 21, 'OW'], ['YRT1', 1120, 'Y', 14, 'RT'], ['YOW2', 200, 'Y', 14, 'OW'], ['TOW3', 770, 'T', 3, 'OW'], ['QRT4', 600, 'Q', 3, 'RT'], ['MOW5', 360, 'M', 0, 'OW']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['K', 'L', 'M', 'Q', 'T']}, [['QRT4'], 600]], ['sampled case 2', {'fares': [['QOW0', 280, 'Q', 21, 'OW'], ['TRT1', 1200, 'T', 3, 'RT'], ['MOW2', 110, 'M', 14, 'OW']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['H']}, 'NO_FARE'], ['sampled case 3', {'fares': [['YRT0', 1040, 'Y', 0, 'RT'], ['HRT1', 1310, 'H', 14, 'RT'], ['QRT2', 450, 'Q', 3, 'RT'], ['BOW3', 1430, 'B', 0, 'OW'], ['BRT4', 760, 'B', 3, 'RT']], 'trip': 'OW', 'ap_days': 14, 'rbd_open': ['B', 'H', 'M', 'V', 'Y']}, [['BOW3'], 1430]]], [['RT beats doubled OW', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 18, 'rbd_open': ['Y', 'B', 'M', 'H', 'Q', 'V', 'L', 'K', 'T']}, [['VOW7', 'VOW7'], 640]], ['doubled OW beats RT', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'M', 'V', 'H']}, [['VOW7', 'VOW7'], 640]], ['exactly AP days', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['VOW7'], 320]], ['one day short of AP', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 6, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['HOW3'], 390]], ['closed cheap class', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 14, 'rbd_open': ['Y', 'B', 'H']}, [['HOW3'], 390]], ['price tie between classes', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 30, 'rbd_open': ['Y', 'B', 'M', 'K', 'L']}, [['LRT21'], 640]], ['nothing sellable', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 1, 'rbd_open': ['Q', 'L', 'K']}, 'NO_FARE'], ['OW trip ignores RT fares', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 21, 'rbd_open': ['Y', 'Q', 'L', 'K']}, [['YOW'], 900]], ['sampled case 1', {'fares': [['NRT0', 450, 'N', 21, 'RT'], ['KOW1', 1370, 'K', 21, 'OW'], ['KOW2', 1250, 'K', 21, 'OW'], ['LOW3', 610, 'L', 0, 'OW'], ['NOW4', 1400, 'N', 7, 'OW']], 'trip': 'RT', 'ap_days': 10, 'rbd_open': ['B', 'M', 'N', 'Q', 'V', 'Y']}, [['NOW4', 'NOW4'], 2800]], ['sampled case 2', {'fares': [['BRT0', 1180, 'B', 0, 'RT'], ['LOW1', 850, 'L', 7, 'OW'], ['MRT2', 120, 'M', 3, 'RT']], 'trip': 'RT', 'ap_days': 3, 'rbd_open': ['H', 'M', 'N', 'V', 'Y']}, [['MRT2'], 120]], ['sampled case 3', {'fares': [['NOW0', 1490, 'N', 7, 'OW'], ['QRT1', 590, 'Q', 7, 'RT'], ['KOW2', 580, 'K', 14, 'OW']], 'trip': 'OW', 'ap_days': 3, 'rbd_open': ['H', 'L', 'M', 'N', 'Q', 'T', 'V', 'Y']}, 'NO_FARE'], ['regression: booking class availability', {'fares': [['QOW0', 1010, 'Q', 3, 'OW'], ['YRT1', 1290, 'Y', 7, 'RT'], ['TOW2', 1090, 'T', 14, 'OW']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['K', 'L', 'Q', 'V']}, [['QOW0', 'QOW0'], 2020]]], [['RT beats doubled OW', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 19, 'rbd_open': ['Y', 'B', 'M', 'H', 'Q', 'V', 'L', 'K', 'T']}, [['VOW7', 'VOW7'], 640]], ['doubled OW beats RT', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'M', 'V', 'H']}, [['VOW7', 'VOW7'], 640]], ['exactly AP days', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['VOW7'], 320]], ['one day short of AP', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 6, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['HOW3'], 390]], ['closed cheap class', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 15, 'rbd_open': ['Y', 'B', 'H']}, [['HOW3'], 390]], ['price tie between classes', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 30, 'rbd_open': ['Y', 'B', 'M', 'K', 'L']}, [['LRT21'], 640]], ['nothing sellable', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 1, 'rbd_open': ['Q', 'L', 'K']}, 'NO_FARE'], ['OW trip ignores RT fares', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 21, 'rbd_open': ['Y', 'Q', 'L', 'K']}, [['YOW'], 900]], ['sampled case 1', {'fares': [['KOW0', 390, 'K', 3, 'OW'], ['QOW1', 520, 'Q', 3, 'OW'], ['HRT2', 930, 'H', 0, 'RT'], ['YOW3', 280, 'Y', 14, 'OW']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['Q', 'T']}, [['QOW1', 'QOW1'], 1040]], ['sampled case 2', {'fares': [['HOW0', 550, 'H', 14, 'OW'], ['TOW1', 1070, 'T', 3, 'OW'], ['MRT2', 770, 'M', 0, 'RT'], ['BRT3', 290, 'B', 14, 'RT']], 'trip': 'OW', 'ap_days': 10, 'rbd_open': ['B']}, 'NO_FARE'], ['sampled case 3', {'fares': [['KOW0', 800, 'K', 21, 'OW'], ['NOW1', 1390, 'N', 21, 'OW'], ['VOW2', 780, 'V', 21, 'OW'], ['YOW3', 200, 'Y', 0, 'OW']], 'trip': 'RT', 'ap_days': 3, 'rbd_open': ['H', 'L', 'Q', 'V', 'Y']}, [['YOW3', 'YOW3'], 400]]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| RT beats doubled OW | [['VOW7', 'VOW7'], 640] | [['VOW7', 'VOW7'], 640] | Passed |
| doubled OW beats RT | [['VOW7', 'VOW7'], 640] | [['VOW7', 'VOW7'], 640] | Passed |
| exactly AP days | [['VOW7'], 320] | [['VOW7'], 320] | Passed |
| one day short of AP | [['HOW3'], 390] | [['HOW3'], 390] | Passed |
| closed cheap class | [['VOW7'], 320] | [['HOW3'], 390] | Failed |
| price tie between classes | [['VOW7', 'VOW7'], 640] | [['LRT21'], 640] | Failed |
| nothing sellable | [['BOW'], 610] | NO_FARE | Failed |
| OW trip ignores RT fares | [['VOW7'], 320] | [['YOW'], 900] | Failed |
| sampled case 1 | [['TRT2'], 570] | [['TRT2'], 570] | Passed |
| sampled case 2 | [['TOW1'], 780] | NO_FARE | Failed |
| sampled case 3 | [['TOW2'], 1300] | [['TOW2'], 1300] | Passed |
| regression: booking class availability | [['YRT0'], 160] | [['NOW5', 'NOW5'], 1460] | Failed |
SHA-256 / ab15ce253294e258c6ed7fbc69d921867f05dd58899a1d90c16365671798b2fa
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
ap = x['ap_days']
open_ = set(x['rbd_open'])
order = 'YBMHQVLKTN'
ok = [f for f in x['fares'] if f[3] <= ap and (f[2] in open_ or f[4] == 'RT')]
opts = []
for basis, amt, rbd, minap, kind in ok:
if x['trip'] == 'OW' and kind == 'OW':
opts.append((amt, order.index(rbd), [basis]))
if x['trip'] == 'RT' and kind == 'RT':
opts.append((amt, order.index(rbd), [basis]))
if x['trip'] == 'RT' and kind == 'OW':
opts.append((2 * amt, order.index(rbd), [basis, basis]))
if not opts: return 'NO_FARE'
opts.sort(key=lambda o: (o[0], o[1]))
return [opts[0][2], opts[0][0]]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['RT beats doubled OW', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 15, 'rbd_open': ['Y', 'B', 'M', 'H', 'Q', 'V', 'L', 'K', 'T']}, [['VOW7', 'VOW7'], 640]], ['doubled OW beats RT', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'M', 'V', 'H']}, [['VOW7', 'VOW7'], 640]], ['exactly AP days', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['VOW7'], 320]], ['one day short of AP', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 6, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['HOW3'], 390]], ['closed cheap class', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 11, 'rbd_open': ['Y', 'B', 'H']}, [['HOW3'], 390]], ['price tie between classes', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 30, 'rbd_open': ['Y', 'B', 'M', 'K', 'L']}, [['LRT21'], 640]], ['nothing sellable', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 1, 'rbd_open': ['Q', 'L', 'K']}, 'NO_FARE'], ['OW trip ignores RT fares', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 21, 'rbd_open': ['Y', 'Q', 'L', 'K']}, [['YOW'], 900]], ['sampled case 1', {'fares': [['BOW0', 1090, 'B', 3, 'OW'], ['TRT1', 1190, 'T', 7, 'RT'], ['TRT2', 570, 'T', 0, 'RT'], ['MOW3', 1370, 'M', 3, 'OW']], 'trip': 'RT', 'ap_days': 0, 'rbd_open': ['B', 'H', 'K', 'L', 'M', 'N', 'T', 'Y']}, [['TRT2'], 570]], ['sampled case 2', {'fares': [['TRT0', 970, 'T', 0, 'RT'], ['TOW1', 780, 'T', 3, 'OW'], ['LRT2', 800, 'L', 7, 'RT'], ['VRT3', 1290, 'V', 14, 'RT'], ['BOW4', 1450, 'B', 21, 'OW']], 'trip': 'OW', 'ap_days': 30, 'rbd_open': ['Y']}, 'NO_FARE'], ['sampled case 3', {'fares': [['KRT0', 550, 'K', 3, 'RT'], ['HRT1', 1290, 'H', 3, 'RT'], ['TOW2', 1300, 'T', 7, 'OW'], ['MOW3', 480, 'M', 21, 'OW']], 'trip': 'OW', 'ap_days': 7, 'rbd_open': ['B', 'H', 'M', 'T', 'Y']}, [['TOW2'], 1300]], ['regression: booking class availability', {'fares': [['YRT0', 160, 'Y', 3, 'RT'], ['BRT1', 650, 'B', 3, 'RT'], ['BOW2', 1310, 'B', 0, 'OW'], ['BRT3', 1490, 'B', 7, 'RT'], ['LOW4', 460, 'L', 3, 'OW'], ['NOW5', 730, 'N', 3, 'OW']], 'trip': 'RT', 'ap_days': 21, 'rbd_open': ['H', 'K', 'M', 'N', 'Q', 'T']}, [['NOW5', 'NOW5'], 1460]]], [['RT beats doubled OW', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 16, 'rbd_open': ['Y', 'B', 'M', 'H', 'Q', 'V', 'L', 'K', 'T']}, [['VOW7', 'VOW7'], 640]], ['doubled OW beats RT', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'M', 'V', 'H']}, [['VOW7', 'VOW7'], 640]], ['exactly AP days', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['VOW7'], 320]], ['one day short of AP', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 6, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['HOW3'], 390]], ['closed cheap class', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 12, 'rbd_open': ['Y', 'B', 'H']}, [['HOW3'], 390]], ['price tie between classes', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 30, 'rbd_open': ['Y', 'B', 'M', 'K', 'L']}, [['LRT21'], 640]], ['nothing sellable', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 1, 'rbd_open': ['Q', 'L', 'K']}, 'NO_FARE'], ['OW trip ignores RT fares', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 21, 'rbd_open': ['Y', 'Q', 'L', 'K']}, [['YOW'], 900]], ['sampled case 1', {'fares': [['NOW0', 1290, 'N', 0, 'OW'], ['YRT1', 1250, 'Y', 0, 'RT'], ['LOW2', 190, 'L', 7, 'OW']], 'trip': 'OW', 'ap_days': 7, 'rbd_open': ['K', 'T']}, 'NO_FARE'], ['sampled case 2', {'fares': [['TRT0', 1050, 'T', 3, 'RT'], ['KOW1', 890, 'K', 21, 'OW'], ['TOW2', 1070, 'T', 3, 'OW'], ['HOW3', 880, 'H', 14, 'OW'], ['VOW4', 480, 'V', 0, 'OW']], 'trip': 'RT', 'ap_days': 3, 'rbd_open': ['B', 'H', 'K', 'L', 'N', 'Q', 'V', 'Y']}, [['VOW4', 'VOW4'], 960]], ['sampled case 3', {'fares': [['QOW0', 1370, 'Q', 14, 'OW'], ['HRT1', 320, 'H', 3, 'RT'], ['BOW2', 860, 'B', 21, 'OW'], ['LRT3', 1490, 'L', 3, 'RT'], ['LOW4', 1320, 'L', 0, 'OW']], 'trip': 'RT', 'ap_days': 3, 'rbd_open': ['H', 'K', 'L', 'M', 'N', 'Q', 'T', 'V', 'Y']}, [['HRT1'], 320]], ['regression: booking class availability', {'fares': [['BRT0', 940, 'B', 21, 'RT'], ['HRT1', 1070, 'H', 3, 'RT'], ['VRT2', 1170, 'V', 14, 'RT'], ['KOW3', 1240, 'K', 3, 'OW'], ['KOW4', 1280, 'K', 7, 'OW']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['V']}, 'NO_FARE']], [['RT beats doubled OW', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 17, 'rbd_open': ['Y', 'B', 'M', 'H', 'Q', 'V', 'L', 'K', 'T']}, [['VOW7', 'VOW7'], 640]], ['doubled OW beats RT', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'M', 'V', 'H']}, [['VOW7', 'VOW7'], 640]], ['exactly AP days', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['VOW7'], 320]], ['one day short of AP', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 6, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['HOW3'], 390]], ['closed cheap class', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 13, 'rbd_open': ['Y', 'B', 'H']}, [['HOW3'], 390]], ['price tie between classes', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 30, 'rbd_open': ['Y', 'B', 'M', 'K', 'L']}, [['LRT21'], 640]], ['nothing sellable', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 1, 'rbd_open': ['Q', 'L', 'K']}, 'NO_FARE'], ['OW trip ignores RT fares', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 21, 'rbd_open': ['Y', 'Q', 'L', 'K']}, [['YOW'], 900]], ['sampled case 1', {'fares': [['KOW0', 1090, 'K', 21, 'OW'], ['YRT1', 1120, 'Y', 14, 'RT'], ['YOW2', 200, 'Y', 14, 'OW'], ['TOW3', 770, 'T', 3, 'OW'], ['QRT4', 600, 'Q', 3, 'RT'], ['MOW5', 360, 'M', 0, 'OW']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['K', 'L', 'M', 'Q', 'T']}, [['QRT4'], 600]], ['sampled case 2', {'fares': [['QOW0', 280, 'Q', 21, 'OW'], ['TRT1', 1200, 'T', 3, 'RT'], ['MOW2', 110, 'M', 14, 'OW']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['H']}, 'NO_FARE'], ['sampled case 3', {'fares': [['YRT0', 1040, 'Y', 0, 'RT'], ['HRT1', 1310, 'H', 14, 'RT'], ['QRT2', 450, 'Q', 3, 'RT'], ['BOW3', 1430, 'B', 0, 'OW'], ['BRT4', 760, 'B', 3, 'RT']], 'trip': 'OW', 'ap_days': 14, 'rbd_open': ['B', 'H', 'M', 'V', 'Y']}, [['BOW3'], 1430]]], [['RT beats doubled OW', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 18, 'rbd_open': ['Y', 'B', 'M', 'H', 'Q', 'V', 'L', 'K', 'T']}, [['VOW7', 'VOW7'], 640]], ['doubled OW beats RT', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'M', 'V', 'H']}, [['VOW7', 'VOW7'], 640]], ['exactly AP days', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['VOW7'], 320]], ['one day short of AP', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 6, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['HOW3'], 390]], ['closed cheap class', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 14, 'rbd_open': ['Y', 'B', 'H']}, [['HOW3'], 390]], ['price tie between classes', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 30, 'rbd_open': ['Y', 'B', 'M', 'K', 'L']}, [['LRT21'], 640]], ['nothing sellable', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 1, 'rbd_open': ['Q', 'L', 'K']}, 'NO_FARE'], ['OW trip ignores RT fares', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 21, 'rbd_open': ['Y', 'Q', 'L', 'K']}, [['YOW'], 900]], ['sampled case 1', {'fares': [['NRT0', 450, 'N', 21, 'RT'], ['KOW1', 1370, 'K', 21, 'OW'], ['KOW2', 1250, 'K', 21, 'OW'], ['LOW3', 610, 'L', 0, 'OW'], ['NOW4', 1400, 'N', 7, 'OW']], 'trip': 'RT', 'ap_days': 10, 'rbd_open': ['B', 'M', 'N', 'Q', 'V', 'Y']}, [['NOW4', 'NOW4'], 2800]], ['sampled case 2', {'fares': [['BRT0', 1180, 'B', 0, 'RT'], ['LOW1', 850, 'L', 7, 'OW'], ['MRT2', 120, 'M', 3, 'RT']], 'trip': 'RT', 'ap_days': 3, 'rbd_open': ['H', 'M', 'N', 'V', 'Y']}, [['MRT2'], 120]], ['sampled case 3', {'fares': [['NOW0', 1490, 'N', 7, 'OW'], ['QRT1', 590, 'Q', 7, 'RT'], ['KOW2', 580, 'K', 14, 'OW']], 'trip': 'OW', 'ap_days': 3, 'rbd_open': ['H', 'L', 'M', 'N', 'Q', 'T', 'V', 'Y']}, 'NO_FARE'], ['regression: booking class availability', {'fares': [['QOW0', 1010, 'Q', 3, 'OW'], ['YRT1', 1290, 'Y', 7, 'RT'], ['TOW2', 1090, 'T', 14, 'OW']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['K', 'L', 'Q', 'V']}, [['QOW0', 'QOW0'], 2020]]], [['RT beats doubled OW', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 19, 'rbd_open': ['Y', 'B', 'M', 'H', 'Q', 'V', 'L', 'K', 'T']}, [['VOW7', 'VOW7'], 640]], ['doubled OW beats RT', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'M', 'V', 'H']}, [['VOW7', 'VOW7'], 640]], ['exactly AP days', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 7, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['VOW7'], 320]], ['one day short of AP', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 6, 'rbd_open': ['Y', 'B', 'V', 'H']}, [['HOW3'], 390]], ['closed cheap class', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 15, 'rbd_open': ['Y', 'B', 'H']}, [['HOW3'], 390]], ['price tie between classes', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'RT', 'ap_days': 30, 'rbd_open': ['Y', 'B', 'M', 'K', 'L']}, [['LRT21'], 640]], ['nothing sellable', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 1, 'rbd_open': ['Q', 'L', 'K']}, 'NO_FARE'], ['OW trip ignores RT fares', {'fares': [['YOW', 900, 'Y', 0, 'OW'], ['BOW', 610, 'B', 0, 'OW'], ['QRT14', 780, 'Q', 14, 'RT'], ['MRT', 1150, 'M', 0, 'RT'], ['VOW7', 320, 'V', 7, 'OW'], ['LRT21', 640, 'L', 21, 'RT'], ['HOW3', 390, 'H', 3, 'OW'], ['KRT7', 640, 'K', 7, 'RT']], 'trip': 'OW', 'ap_days': 21, 'rbd_open': ['Y', 'Q', 'L', 'K']}, [['YOW'], 900]], ['sampled case 1', {'fares': [['KOW0', 390, 'K', 3, 'OW'], ['QOW1', 520, 'Q', 3, 'OW'], ['HRT2', 930, 'H', 0, 'RT'], ['YOW3', 280, 'Y', 14, 'OW']], 'trip': 'RT', 'ap_days': 7, 'rbd_open': ['Q', 'T']}, [['QOW1', 'QOW1'], 1040]], ['sampled case 2', {'fares': [['HOW0', 550, 'H', 14, 'OW'], ['TOW1', 1070, 'T', 3, 'OW'], ['MRT2', 770, 'M', 0, 'RT'], ['BRT3', 290, 'B', 14, 'RT']], 'trip': 'OW', 'ap_days': 10, 'rbd_open': ['B']}, 'NO_FARE'], ['sampled case 3', {'fares': [['KOW0', 800, 'K', 21, 'OW'], ['NOW1', 1390, 'N', 21, 'OW'], ['VOW2', 780, 'V', 21, 'OW'], ['YOW3', 200, 'Y', 0, 'OW']], 'trip': 'RT', 'ap_days': 3, 'rbd_open': ['H', 'L', 'Q', 'V', 'Y']}, [['YOW3', 'YOW3'], 400]]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| RT beats doubled OW | [['VOW7', 'VOW7'], 640] | [['VOW7', 'VOW7'], 640] | Passed |
| doubled OW beats RT | [['VOW7', 'VOW7'], 640] | [['VOW7', 'VOW7'], 640] | Passed |
| exactly AP days | [['VOW7'], 320] | [['VOW7'], 320] | Passed |
| one day short of AP | [['HOW3'], 390] | [['HOW3'], 390] | Passed |
| closed cheap class | [['HOW3'], 390] | [['HOW3'], 390] | Passed |
| price tie between classes | [['LRT21'], 640] | [['LRT21'], 640] | Passed |
| nothing sellable | NO_FARE | NO_FARE | Passed |
| OW trip ignores RT fares | [['YOW'], 900] | [['YOW'], 900] | Passed |
| sampled case 1 | [['TRT2'], 570] | [['TRT2'], 570] | Passed |
| sampled case 2 | NO_FARE | NO_FARE | Passed |
| sampled case 3 | [['TOW2'], 1300] | [['TOW2'], 1300] | Passed |
| regression: booking class availability | [['YRT0'], 160] | [['NOW5', 'NOW5'], 1460] | Failed |
SHA-256 / 23c1ec040fdc76432829bf3ea0363a073d8161649b0fbb9ac819c9526be9e51b
HELD IN THE MEMBER ARCHIVE
The verified repair and its recorded checks are member-only.
This mechanism has 12 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.
Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.
Member access is invitation-based. Sign in with your invited account to inspect the repair.
Sign in to the archive ↗Verification & scope
A stipulated toy fare-rule contract with invented constants; it is not an ATPCO or carrier tariff implementation and makes no claim of industry-standard conformance. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:47:44.771432+00:00.
Case digest / ec5ac2926fcc12ad3aa2fc97c7a8a7ba44ae9dfc022d3acaef61b12c1bd8df0c