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

N = 1
observations = []
def solve(x):
    paid, new = x['paid'], x['new_fare']
    if x['hours_since_ticket'] <= x['waiver_h']:
        fee = 0.0
    elif x['fee_rule'] == 'FLAT':
        fee = x['fee']
    else:
        fee = max(x['fee'], x['fee_pct'] * paid / 100)
    collect = max(0.0, new - paid) + fee
    credit = max(0.0, paid - new) if x['residual'] != 'NONE' else 0.0
    return [round(collect, 2), round(credit, 2)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1101.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [291.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 51}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 421.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 310.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 0.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 945.21, 'new_fare': 746.1, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 397}, [141.78, 0.0]], ['sampled case 2', {'paid': 616.49, 'new_fare': 852.38, 'fee': 150.0, 'fee_pct': 10, 'fee_rule': 'FLAT', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 48}, [385.89, 0.0]], ['sampled case 3', {'paid': 832.44, 'new_fare': 589.1, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'FLAT', 'residual': 'FORFEIT', 'waiver_h': 48, 'hours_since_ticket': 24}, [0.0, 0.0]]], [['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1102.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [292.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 52}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 422.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 320.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 10.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 187.06, 'new_fare': 196.65, 'fee': 150.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 24}, [9.59, 0.0]], ['sampled case 2', {'paid': 1518.15, 'new_fare': 1549.03, 'fee': 150.0, 'fee_pct': 20, 'fee_rule': 'FLAT', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 24}, [30.88, 0.0]], ['sampled case 3', {'paid': 1212.02, 'new_fare': 1432.47, 'fee': 100.0, 'fee_pct': 5, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 48, 'hours_since_ticket': 49}, [320.45, 0.0]]], [['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1103.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [293.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 53}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 423.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 330.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 20.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 1440.92, 'new_fare': 1296.99, 'fee': 75.0, 'fee_pct': 20, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'waiver_h': 48, 'hours_since_ticket': 24}, [0.0, 143.93]], ['sampled case 2', {'paid': 1622.18, 'new_fare': 873.9, 'fee': 150.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 48}, [243.33, 0.0]], ['sampled case 3', {'paid': 1642.66, 'new_fare': 1568.49, 'fee': 75.0, 'fee_pct': 20, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 48, 'hours_since_ticket': 48}, [0.0, 0.0]]], [['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1104.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [294.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 54}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 424.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 340.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 30.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 1227.57, 'new_fare': 1031.14, 'fee': 75.0, 'fee_pct': 20, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 48}, [245.51, 0.0]], ['sampled case 2', {'paid': 762.01, 'new_fare': 1039.32, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 24}, [277.31, 0.0]], ['sampled case 3', {'paid': 1675.54, 'new_fare': 1027.22, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'waiver_h': 24, 'hours_since_ticket': 24}, [0.0, 648.32]]], [['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1105.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [295.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 55}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 425.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 350.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 40.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 938.24, 'new_fare': 955.89, 'fee': 100.0, 'fee_pct': 15, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'waiver_h': 48, 'hours_since_ticket': 57.2}, [117.65, 0.0]], ['sampled case 2', {'paid': 1989.4, 'new_fare': 2128.3, 'fee': 150.0, 'fee_pct': 10, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 12.8}, [138.9, 0.0]], ['sampled case 3', {'paid': 1315.4, 'new_fare': 1527.5, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'FLAT', 'residual': 'FORFEIT', 'waiver_h': 48, 'hours_since_ticket': 24}, [212.1, 0.0]]]]
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):
    paid, new = x['paid'], x['new_fare']
    if x['hours_since_ticket'] <= x['waiver_h']:
        fee = 0.0
    elif x['fee_rule'] == 'FLAT':
        fee = x['fee']
    else:
        fee = max(x['fee'], x['fee_pct'] * paid / 100)
    collect = max(0.0, new - paid) + fee
    credit = max(0.0, paid - new) if x['residual'] else 0.0
    return [round(collect, 2), round(credit, 2)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1101.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [291.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 51}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 421.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 310.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 0.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 945.21, 'new_fare': 746.1, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 397}, [141.78, 0.0]], ['sampled case 2', {'paid': 616.49, 'new_fare': 852.38, 'fee': 150.0, 'fee_pct': 10, 'fee_rule': 'FLAT', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 48}, [385.89, 0.0]], ['sampled case 3', {'paid': 832.44, 'new_fare': 589.1, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'FLAT', 'residual': 'FORFEIT', 'waiver_h': 48, 'hours_since_ticket': 24}, [0.0, 0.0]]], [['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1102.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [292.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 52}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 422.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 320.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 10.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 187.06, 'new_fare': 196.65, 'fee': 150.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 24}, [9.59, 0.0]], ['sampled case 2', {'paid': 1518.15, 'new_fare': 1549.03, 'fee': 150.0, 'fee_pct': 20, 'fee_rule': 'FLAT', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 24}, [30.88, 0.0]], ['sampled case 3', {'paid': 1212.02, 'new_fare': 1432.47, 'fee': 100.0, 'fee_pct': 5, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 48, 'hours_since_ticket': 49}, [320.45, 0.0]]], [['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1103.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [293.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 53}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 423.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 330.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 20.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 1440.92, 'new_fare': 1296.99, 'fee': 75.0, 'fee_pct': 20, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'waiver_h': 48, 'hours_since_ticket': 24}, [0.0, 143.93]], ['sampled case 2', {'paid': 1622.18, 'new_fare': 873.9, 'fee': 150.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 48}, [243.33, 0.0]], ['sampled case 3', {'paid': 1642.66, 'new_fare': 1568.49, 'fee': 75.0, 'fee_pct': 20, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 48, 'hours_since_ticket': 48}, [0.0, 0.0]]], [['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1104.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [294.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 54}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 424.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 340.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 30.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 1227.57, 'new_fare': 1031.14, 'fee': 75.0, 'fee_pct': 20, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 48}, [245.51, 0.0]], ['sampled case 2', {'paid': 762.01, 'new_fare': 1039.32, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 24}, [277.31, 0.0]], ['sampled case 3', {'paid': 1675.54, 'new_fare': 1027.22, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'waiver_h': 24, 'hours_since_ticket': 24}, [0.0, 648.32]]], [['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1105.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [295.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 55}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 425.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 350.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 40.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 938.24, 'new_fare': 955.89, 'fee': 100.0, 'fee_pct': 15, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'waiver_h': 48, 'hours_since_ticket': 57.2}, [117.65, 0.0]], ['sampled case 2', {'paid': 1989.4, 'new_fare': 2128.3, 'fee': 150.0, 'fee_pct': 10, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 12.8}, [138.9, 0.0]], ['sampled case 3', {'paid': 1315.4, 'new_fare': 1527.5, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'FLAT', 'residual': 'FORFEIT', 'waiver_h': 48, 'hours_since_ticket': 24}, [212.1, 0.0]]]]
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:
Non-refundable downgrades produce a travel credit.

Input {'paid','new_fare','fee','fee_pct','fee_rule' FLAT|HIGHER,'residual' CREDIT|FORFEIT,'waiver_h','hours_since_ticket'}. Fee waived when hours_since_ticket <= waiver_h; FLAT fee = fee; HIGHER = max(fee, fee_pct% of the original paid fare). Collect = max(0, new-paid) + fee; residual credit = max(0, paid-new) only when residual is CREDIT (the fee is never netted against credit). Return [collect, credit] rounded 2.

split: open-access


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

N = 1
observations = []
def solve(x):
    paid, new = x['paid'], x['new_fare']
    if x['hours_since_ticket'] <= x['waiver_h']:
        fee = 0.0
    elif x['fee_rule'] == 'FLAT':
        fee = x['fee']
    else:
        fee = max(x['fee'], x['fee_pct'] * paid / 100)
    collect = (new - paid) + fee
    credit = max(0.0, paid - new) if x['residual'] == 'CREDIT' else 0.0
    return [round(collect, 2), round(credit, 2)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1101.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [291.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 51}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 421.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 310.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 0.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 945.21, 'new_fare': 746.1, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 397}, [141.78, 0.0]], ['sampled case 2', {'paid': 616.49, 'new_fare': 852.38, 'fee': 150.0, 'fee_pct': 10, 'fee_rule': 'FLAT', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 48}, [385.89, 0.0]], ['sampled case 3', {'paid': 832.44, 'new_fare': 589.1, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'FLAT', 'residual': 'FORFEIT', 'waiver_h': 48, 'hours_since_ticket': 24}, [0.0, 0.0]]], [['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1102.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [292.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 52}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 422.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 320.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 10.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 187.06, 'new_fare': 196.65, 'fee': 150.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 24}, [9.59, 0.0]], ['sampled case 2', {'paid': 1518.15, 'new_fare': 1549.03, 'fee': 150.0, 'fee_pct': 20, 'fee_rule': 'FLAT', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 24}, [30.88, 0.0]], ['sampled case 3', {'paid': 1212.02, 'new_fare': 1432.47, 'fee': 100.0, 'fee_pct': 5, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 48, 'hours_since_ticket': 49}, [320.45, 0.0]]], [['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1103.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [293.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 53}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 423.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 330.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 20.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 1440.92, 'new_fare': 1296.99, 'fee': 75.0, 'fee_pct': 20, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'waiver_h': 48, 'hours_since_ticket': 24}, [0.0, 143.93]], ['sampled case 2', {'paid': 1622.18, 'new_fare': 873.9, 'fee': 150.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 48}, [243.33, 0.0]], ['sampled case 3', {'paid': 1642.66, 'new_fare': 1568.49, 'fee': 75.0, 'fee_pct': 20, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 48, 'hours_since_ticket': 48}, [0.0, 0.0]]], [['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1104.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [294.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 54}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 424.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 340.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 30.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 1227.57, 'new_fare': 1031.14, 'fee': 75.0, 'fee_pct': 20, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 48}, [245.51, 0.0]], ['sampled case 2', {'paid': 762.01, 'new_fare': 1039.32, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 24}, [277.31, 0.0]], ['sampled case 3', {'paid': 1675.54, 'new_fare': 1027.22, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'waiver_h': 24, 'hours_since_ticket': 24}, [0.0, 648.32]]], [['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1105.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [295.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 55}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 425.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 350.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 40.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 938.24, 'new_fare': 955.89, 'fee': 100.0, 'fee_pct': 15, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'waiver_h': 48, 'hours_since_ticket': 57.2}, [117.65, 0.0]], ['sampled case 2', {'paid': 1989.4, 'new_fare': 2128.3, 'fee': 150.0, 'fee_pct': 10, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 12.8}, [138.9, 0.0]], ['sampled case 3', {'paid': 1315.4, 'new_fare': 1527.5, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'FLAT', 'residual': 'FORFEIT', 'waiver_h': 48, 'hours_since_ticket': 24}, [212.1, 0.0]]]]
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

N = 1
observations = []
def solve(x):
    paid, new = x['paid'], x['new_fare']
    if x['hours_since_ticket'] <= x['waiver_h']:
        fee = 0.0
    elif x['fee_rule'] == 'FLAT':
        fee = x['fee']
    else:
        fee = max(x['fee'], x['fee_pct'] * paid / 100)
    collect = abs(new - paid) + fee
    credit = max(0.0, paid - new) if x['residual'] == 'CREDIT' else 0.0
    return [round(collect, 2), round(credit, 2)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1101.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [291.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 51}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 421.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 310.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 0.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 945.21, 'new_fare': 746.1, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 397}, [141.78, 0.0]], ['sampled case 2', {'paid': 616.49, 'new_fare': 852.38, 'fee': 150.0, 'fee_pct': 10, 'fee_rule': 'FLAT', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 48}, [385.89, 0.0]], ['sampled case 3', {'paid': 832.44, 'new_fare': 589.1, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'FLAT', 'residual': 'FORFEIT', 'waiver_h': 48, 'hours_since_ticket': 24}, [0.0, 0.0]]], [['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1102.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [292.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 52}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 422.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 320.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 10.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 187.06, 'new_fare': 196.65, 'fee': 150.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 24}, [9.59, 0.0]], ['sampled case 2', {'paid': 1518.15, 'new_fare': 1549.03, 'fee': 150.0, 'fee_pct': 20, 'fee_rule': 'FLAT', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 24}, [30.88, 0.0]], ['sampled case 3', {'paid': 1212.02, 'new_fare': 1432.47, 'fee': 100.0, 'fee_pct': 5, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 48, 'hours_since_ticket': 49}, [320.45, 0.0]]], [['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1103.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [293.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 53}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 423.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 330.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 20.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 1440.92, 'new_fare': 1296.99, 'fee': 75.0, 'fee_pct': 20, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'waiver_h': 48, 'hours_since_ticket': 24}, [0.0, 143.93]], ['sampled case 2', {'paid': 1622.18, 'new_fare': 873.9, 'fee': 150.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 48}, [243.33, 0.0]], ['sampled case 3', {'paid': 1642.66, 'new_fare': 1568.49, 'fee': 75.0, 'fee_pct': 20, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 48, 'hours_since_ticket': 48}, [0.0, 0.0]]], [['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1104.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [294.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 54}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 424.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 340.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 30.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 1227.57, 'new_fare': 1031.14, 'fee': 75.0, 'fee_pct': 20, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 48}, [245.51, 0.0]], ['sampled case 2', {'paid': 762.01, 'new_fare': 1039.32, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 24}, [277.31, 0.0]], ['sampled case 3', {'paid': 1675.54, 'new_fare': 1027.22, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'waiver_h': 24, 'hours_since_ticket': 24}, [0.0, 648.32]]], [['upgrade HIGHER rule', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 900.0, 'new_fare': 1105.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 100}, [295.0, 0.0]], ['downgrade with credit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 450.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 55}, [75.0, 150.0]], ['downgrade forfeit', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 600.0, 'new_fare': 425.0, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'hours_since_ticket': 72}, [75.0, 0.0]], ['exactly 24h after ticketing', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 520.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 24}, [20.0, 0.0]], ['cheap fare minimum fee', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 350.0, 'new_fare': 310.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 30}, [75.0, 40.0]], ['pct fee exceeds flat', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 1500.0, 'new_fare': 1200.0, 'fee_rule': 'HIGHER', 'residual': 'CREDIT', 'hours_since_ticket': 200}, [150.0, 300.0]], ['fee larger than residual', {'waiver_h': 24, 'fee': 75.0, 'fee_pct': 10, 'paid': 500.0, 'new_fare': 460.0, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'hours_since_ticket': 48}, [75.0, 40.0]], ['sampled case 1', {'paid': 938.24, 'new_fare': 955.89, 'fee': 100.0, 'fee_pct': 15, 'fee_rule': 'FLAT', 'residual': 'CREDIT', 'waiver_h': 48, 'hours_since_ticket': 57.2}, [117.65, 0.0]], ['sampled case 2', {'paid': 1989.4, 'new_fare': 2128.3, 'fee': 150.0, 'fee_pct': 10, 'fee_rule': 'HIGHER', 'residual': 'FORFEIT', 'waiver_h': 24, 'hours_since_ticket': 12.8}, [138.9, 0.0]], ['sampled case 3', {'paid': 1315.4, 'new_fare': 1527.5, 'fee': 50.0, 'fee_pct': 15, 'fee_rule': 'FLAT', 'residual': 'FORFEIT', 'waiver_h': 48, 'hours_since_ticket': 24}, [212.1, 0.0]]]]
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:
Downgrades report a collection below the fee, sometimes negative.

Input {'paid','new_fare','fee','fee_pct','fee_rule' FLAT|HIGHER,'residual' CREDIT|FORFEIT,'waiver_h','hours_since_ticket'}. Fee waived when hours_since_ticket <= waiver_h; FLAT fee = fee; HIGHER = max(fee, fee_pct% of the original paid fare). Collect = max(0, new-paid) + fee; residual credit = max(0, paid-new) only when residual is CREDIT (the fee is never netted against credit). Return [collect, credit] rounded 2.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import decimal
N = 1
observations = []
def solve(x):
    b = datetime.date.fromisoformat(x['birth'])
    d = datetime.date.fromisoformat(x['depart'])
    try:
        bday = b.replace(year=d.year)
    except ValueError:
        bday = datetime.date(d.year, 3, 1)
    age = d.year - b.year
    if age < 2: ptc, pct = 'INF', 10
    elif age < 12: ptc, pct = 'CHD', 75
    else: ptc, pct = 'ADT', 100
    amt = (decimal.Decimal(str(x['fare'])) * pct / 100).quantize(decimal.Decimal('0.01'), rounding=decimal.ROUND_HALF_UP)
    return [ptc, float(amt)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['child day before 12th birthday', {'birth': '2016-05-11', 'depart': '2028-05-10', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 413.5}, ['ADT', 413.5]], ['infant turns two on travel day', {'birth': '2026-03-01', 'depart': '2028-03-01', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 301.0}, ['INF', 30.1]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-11', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-01', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2015-02-22', 'depart': '2027-02-15', 'fare': 171.9}, ['CHD', 128.93]], ['sampled case 2', {'birth': '2023-11-19', 'depart': '2029-03-25', 'fare': 1444.58}, ['CHD', 1083.44]], ['sampled case 3', {'birth': '2027-08-22', 'depart': '2029-08-21', 'fare': 608.88}, ['INF', 60.89]]], [['child day before 12th birthday', {'birth': '2016-05-12', 'depart': '2028-05-11', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 414.5}, ['ADT', 414.5]], ['infant turns two on travel day', {'birth': '2026-03-02', 'depart': '2028-03-02', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 302.0}, ['INF', 30.2]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-12', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-02', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2025-04-03', 'depart': '2027-04-02', 'fare': 516.1}, ['INF', 51.61]], ['sampled case 2', {'birth': '2026-06-08', 'depart': '2028-06-06', 'fare': 952.7}, ['INF', 95.27]], ['sampled case 3', {'birth': '2017-05-05', 'depart': '2029-05-02', 'fare': 942.13}, ['CHD', 706.6]]], [['child day before 12th birthday', {'birth': '2016-05-13', 'depart': '2028-05-12', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 415.5}, ['ADT', 415.5]], ['infant turns two on travel day', {'birth': '2026-03-03', 'depart': '2028-03-03', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 303.0}, ['INF', 30.3]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-13', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-03', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2017-10-23', 'depart': '2029-10-19', 'fare': 1447.34}, ['CHD', 1085.51]], ['sampled case 2', {'birth': '2016-03-06', 'depart': '2028-02-28', 'fare': 1074.9}, ['CHD', 806.18]], ['sampled case 3', {'birth': '2015-06-23', 'depart': '2027-06-20', 'fare': 768.6}, ['CHD', 576.45]]], [['child day before 12th birthday', {'birth': '2016-05-14', 'depart': '2028-05-13', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 416.5}, ['ADT', 416.5]], ['infant turns two on travel day', {'birth': '2026-03-04', 'depart': '2028-03-04', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 304.0}, ['INF', 30.4]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-14', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-04', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2028-06-21', 'depart': '2029-08-22', 'fare': 642.31}, ['INF', 64.23]], ['sampled case 2', {'birth': '2019-06-26', 'depart': '2027-12-23', 'fare': 211.9}, ['CHD', 158.93]], ['sampled case 3', {'birth': '2025-09-18', 'depart': '2027-09-19', 'fare': 1456.7}, ['CHD', 1092.53]]], [['child day before 12th birthday', {'birth': '2016-05-15', 'depart': '2028-05-14', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 417.5}, ['ADT', 417.5]], ['infant turns two on travel day', {'birth': '2026-03-05', 'depart': '2028-03-05', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 305.0}, ['INF', 30.5]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-15', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-05', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2026-08-03', 'depart': '2028-07-31', 'fare': 265.0}, ['INF', 26.5]], ['sampled case 2', {'birth': '2026-08-19', 'depart': '2028-08-19', 'fare': 820.15}, ['CHD', 615.11]], ['sampled case 3', {'birth': '2017-09-28', 'depart': '2029-09-26', 'fare': 855.8}, ['CHD', 641.85]]]]
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 datetime
import decimal
N = 1
observations = []
def solve(x):
    b = datetime.date.fromisoformat(x['birth'])
    d = datetime.date.fromisoformat(x['depart'])
    try:
        bday = b.replace(year=d.year)
    except ValueError:
        bday = datetime.date(d.year, 3, 1)
    age = d.year - b.year - (1 if d.month < b.month else 0)
    if age < 2: ptc, pct = 'INF', 10
    elif age < 12: ptc, pct = 'CHD', 75
    else: ptc, pct = 'ADT', 100
    amt = (decimal.Decimal(str(x['fare'])) * pct / 100).quantize(decimal.Decimal('0.01'), rounding=decimal.ROUND_HALF_UP)
    return [ptc, float(amt)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['child day before 12th birthday', {'birth': '2016-05-11', 'depart': '2028-05-10', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 413.5}, ['ADT', 413.5]], ['infant turns two on travel day', {'birth': '2026-03-01', 'depart': '2028-03-01', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 301.0}, ['INF', 30.1]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-11', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-01', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2015-02-22', 'depart': '2027-02-15', 'fare': 171.9}, ['CHD', 128.93]], ['sampled case 2', {'birth': '2023-11-19', 'depart': '2029-03-25', 'fare': 1444.58}, ['CHD', 1083.44]], ['sampled case 3', {'birth': '2027-08-22', 'depart': '2029-08-21', 'fare': 608.88}, ['INF', 60.89]]], [['child day before 12th birthday', {'birth': '2016-05-12', 'depart': '2028-05-11', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 414.5}, ['ADT', 414.5]], ['infant turns two on travel day', {'birth': '2026-03-02', 'depart': '2028-03-02', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 302.0}, ['INF', 30.2]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-12', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-02', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2025-04-03', 'depart': '2027-04-02', 'fare': 516.1}, ['INF', 51.61]], ['sampled case 2', {'birth': '2026-06-08', 'depart': '2028-06-06', 'fare': 952.7}, ['INF', 95.27]], ['sampled case 3', {'birth': '2017-05-05', 'depart': '2029-05-02', 'fare': 942.13}, ['CHD', 706.6]]], [['child day before 12th birthday', {'birth': '2016-05-13', 'depart': '2028-05-12', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 415.5}, ['ADT', 415.5]], ['infant turns two on travel day', {'birth': '2026-03-03', 'depart': '2028-03-03', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 303.0}, ['INF', 30.3]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-13', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-03', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2017-10-23', 'depart': '2029-10-19', 'fare': 1447.34}, ['CHD', 1085.51]], ['sampled case 2', {'birth': '2016-03-06', 'depart': '2028-02-28', 'fare': 1074.9}, ['CHD', 806.18]], ['sampled case 3', {'birth': '2015-06-23', 'depart': '2027-06-20', 'fare': 768.6}, ['CHD', 576.45]]], [['child day before 12th birthday', {'birth': '2016-05-14', 'depart': '2028-05-13', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 416.5}, ['ADT', 416.5]], ['infant turns two on travel day', {'birth': '2026-03-04', 'depart': '2028-03-04', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 304.0}, ['INF', 30.4]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-14', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-04', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2028-06-21', 'depart': '2029-08-22', 'fare': 642.31}, ['INF', 64.23]], ['sampled case 2', {'birth': '2019-06-26', 'depart': '2027-12-23', 'fare': 211.9}, ['CHD', 158.93]], ['sampled case 3', {'birth': '2025-09-18', 'depart': '2027-09-19', 'fare': 1456.7}, ['CHD', 1092.53]]], [['child day before 12th birthday', {'birth': '2016-05-15', 'depart': '2028-05-14', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 417.5}, ['ADT', 417.5]], ['infant turns two on travel day', {'birth': '2026-03-05', 'depart': '2028-03-05', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 305.0}, ['INF', 30.5]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-15', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-05', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2026-08-03', 'depart': '2028-07-31', 'fare': 265.0}, ['INF', 26.5]], ['sampled case 2', {'birth': '2026-08-19', 'depart': '2028-08-19', 'fare': 820.15}, ['CHD', 615.11]], ['sampled case 3', {'birth': '2017-09-28', 'depart': '2029-09-26', 'fare': 855.8}, ['CHD', 641.85]]]]
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 child travelling the day before the 12th birthday is priced as an adult.

Input {'birth','depart' ISO dates,'fare'}. Age is completed years on the departure date; a 29 February birthday falls on 1 March in non-leap years. Under 2 -> INF 10%; 2 to 11 -> CHD 75%; otherwise ADT 100%. Amount = fare*pct/100 rounded half-up to cents. Return [ptc, amount].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import decimal
N = 1
observations = []
def solve(x):
    b = datetime.date.fromisoformat(x['birth'])
    d = datetime.date.fromisoformat(x['depart'])
    try:
        bday = b.replace(year=d.year)
    except ValueError:
        bday = datetime.date(d.year, 3, 1)
    age = d.year - b.year - (1 if d < bday else 0)
    if age < 2: ptc, pct = 'INF', 10
    elif age <= 12: ptc, pct = 'CHD', 75
    else: ptc, pct = 'ADT', 100
    amt = (decimal.Decimal(str(x['fare'])) * pct / 100).quantize(decimal.Decimal('0.01'), rounding=decimal.ROUND_HALF_UP)
    return [ptc, float(amt)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['child day before 12th birthday', {'birth': '2016-05-11', 'depart': '2028-05-10', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 413.5}, ['ADT', 413.5]], ['infant turns two on travel day', {'birth': '2026-03-01', 'depart': '2028-03-01', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 301.0}, ['INF', 30.1]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-11', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-01', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2015-02-22', 'depart': '2027-02-15', 'fare': 171.9}, ['CHD', 128.93]], ['sampled case 2', {'birth': '2023-11-19', 'depart': '2029-03-25', 'fare': 1444.58}, ['CHD', 1083.44]], ['sampled case 3', {'birth': '2027-08-22', 'depart': '2029-08-21', 'fare': 608.88}, ['INF', 60.89]]], [['child day before 12th birthday', {'birth': '2016-05-12', 'depart': '2028-05-11', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 414.5}, ['ADT', 414.5]], ['infant turns two on travel day', {'birth': '2026-03-02', 'depart': '2028-03-02', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 302.0}, ['INF', 30.2]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-12', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-02', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2025-04-03', 'depart': '2027-04-02', 'fare': 516.1}, ['INF', 51.61]], ['sampled case 2', {'birth': '2026-06-08', 'depart': '2028-06-06', 'fare': 952.7}, ['INF', 95.27]], ['sampled case 3', {'birth': '2017-05-05', 'depart': '2029-05-02', 'fare': 942.13}, ['CHD', 706.6]]], [['child day before 12th birthday', {'birth': '2016-05-13', 'depart': '2028-05-12', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 415.5}, ['ADT', 415.5]], ['infant turns two on travel day', {'birth': '2026-03-03', 'depart': '2028-03-03', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 303.0}, ['INF', 30.3]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-13', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-03', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2017-10-23', 'depart': '2029-10-19', 'fare': 1447.34}, ['CHD', 1085.51]], ['sampled case 2', {'birth': '2016-03-06', 'depart': '2028-02-28', 'fare': 1074.9}, ['CHD', 806.18]], ['sampled case 3', {'birth': '2015-06-23', 'depart': '2027-06-20', 'fare': 768.6}, ['CHD', 576.45]]], [['child day before 12th birthday', {'birth': '2016-05-14', 'depart': '2028-05-13', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 416.5}, ['ADT', 416.5]], ['infant turns two on travel day', {'birth': '2026-03-04', 'depart': '2028-03-04', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 304.0}, ['INF', 30.4]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-14', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-04', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2028-06-21', 'depart': '2029-08-22', 'fare': 642.31}, ['INF', 64.23]], ['sampled case 2', {'birth': '2019-06-26', 'depart': '2027-12-23', 'fare': 211.9}, ['CHD', 158.93]], ['sampled case 3', {'birth': '2025-09-18', 'depart': '2027-09-19', 'fare': 1456.7}, ['CHD', 1092.53]]], [['child day before 12th birthday', {'birth': '2016-05-15', 'depart': '2028-05-14', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 417.5}, ['ADT', 417.5]], ['infant turns two on travel day', {'birth': '2026-03-05', 'depart': '2028-03-05', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 305.0}, ['INF', 30.5]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-15', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-05', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2026-08-03', 'depart': '2028-07-31', 'fare': 265.0}, ['INF', 26.5]], ['sampled case 2', {'birth': '2026-08-19', 'depart': '2028-08-19', 'fare': 820.15}, ['CHD', 615.11]], ['sampled case 3', {'birth': '2017-09-28', 'depart': '2029-09-26', 'fare': 855.8}, ['CHD', 641.85]]]]
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 datetime
import decimal
N = 1
observations = []
def solve(x):
    b = datetime.date.fromisoformat(x['birth'])
    d = datetime.date.fromisoformat(x['depart'])
    try:
        bday = b.replace(year=d.year)
    except ValueError:
        bday = datetime.date(d.year, 3, 1)
    age = d.year - b.year - (1 if d < bday else 0)
    if age < 2: ptc, pct = 'INF', 10
    elif (d - b).days < 12 * 365: ptc, pct = 'CHD', 75
    else: ptc, pct = 'ADT', 100
    amt = (decimal.Decimal(str(x['fare'])) * pct / 100).quantize(decimal.Decimal('0.01'), rounding=decimal.ROUND_HALF_UP)
    return [ptc, float(amt)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['child day before 12th birthday', {'birth': '2016-05-11', 'depart': '2028-05-10', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 413.5}, ['ADT', 413.5]], ['infant turns two on travel day', {'birth': '2026-03-01', 'depart': '2028-03-01', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 301.0}, ['INF', 30.1]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-11', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-01', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2015-02-22', 'depart': '2027-02-15', 'fare': 171.9}, ['CHD', 128.93]], ['sampled case 2', {'birth': '2023-11-19', 'depart': '2029-03-25', 'fare': 1444.58}, ['CHD', 1083.44]], ['sampled case 3', {'birth': '2027-08-22', 'depart': '2029-08-21', 'fare': 608.88}, ['INF', 60.89]]], [['child day before 12th birthday', {'birth': '2016-05-12', 'depart': '2028-05-11', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 414.5}, ['ADT', 414.5]], ['infant turns two on travel day', {'birth': '2026-03-02', 'depart': '2028-03-02', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 302.0}, ['INF', 30.2]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-12', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-02', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2025-04-03', 'depart': '2027-04-02', 'fare': 516.1}, ['INF', 51.61]], ['sampled case 2', {'birth': '2026-06-08', 'depart': '2028-06-06', 'fare': 952.7}, ['INF', 95.27]], ['sampled case 3', {'birth': '2017-05-05', 'depart': '2029-05-02', 'fare': 942.13}, ['CHD', 706.6]]], [['child day before 12th birthday', {'birth': '2016-05-13', 'depart': '2028-05-12', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 415.5}, ['ADT', 415.5]], ['infant turns two on travel day', {'birth': '2026-03-03', 'depart': '2028-03-03', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 303.0}, ['INF', 30.3]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-13', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-03', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2017-10-23', 'depart': '2029-10-19', 'fare': 1447.34}, ['CHD', 1085.51]], ['sampled case 2', {'birth': '2016-03-06', 'depart': '2028-02-28', 'fare': 1074.9}, ['CHD', 806.18]], ['sampled case 3', {'birth': '2015-06-23', 'depart': '2027-06-20', 'fare': 768.6}, ['CHD', 576.45]]], [['child day before 12th birthday', {'birth': '2016-05-14', 'depart': '2028-05-13', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 416.5}, ['ADT', 416.5]], ['infant turns two on travel day', {'birth': '2026-03-04', 'depart': '2028-03-04', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 304.0}, ['INF', 30.4]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-14', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-04', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2028-06-21', 'depart': '2029-08-22', 'fare': 642.31}, ['INF', 64.23]], ['sampled case 2', {'birth': '2019-06-26', 'depart': '2027-12-23', 'fare': 211.9}, ['CHD', 158.93]], ['sampled case 3', {'birth': '2025-09-18', 'depart': '2027-09-19', 'fare': 1456.7}, ['CHD', 1092.53]]], [['child day before 12th birthday', {'birth': '2016-05-15', 'depart': '2028-05-14', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 417.5}, ['ADT', 417.5]], ['infant turns two on travel day', {'birth': '2026-03-05', 'depart': '2028-03-05', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 305.0}, ['INF', 30.5]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-15', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-05', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2026-08-03', 'depart': '2028-07-31', 'fare': 265.0}, ['INF', 26.5]], ['sampled case 2', {'birth': '2026-08-19', 'depart': '2028-08-19', 'fare': 820.15}, ['CHD', 615.11]], ['sampled case 3', {'birth': '2017-09-28', 'depart': '2029-09-26', 'fare': 855.8}, ['CHD', 641.85]]]]
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:
Travellers on or after their 12th birthday still receive the child discount.

Input {'birth','depart' ISO dates,'fare'}. Age is completed years on the departure date; a 29 February birthday falls on 1 March in non-leap years. Under 2 -> INF 10%; 2 to 11 -> CHD 75%; otherwise ADT 100%. Amount = fare*pct/100 rounded half-up to cents. Return [ptc, amount].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import decimal
N = 1
observations = []
def solve(x):
    b = datetime.date.fromisoformat(x['birth'])
    d = datetime.date.fromisoformat(x['depart'])
    try:
        bday = b.replace(year=d.year)
    except ValueError:
        bday = datetime.date(d.year, 3, 1)
    age = d.year - b.year - (1 if d < bday else 0)
    if age < 12: ptc, pct = 'CHD', 75
    elif age < 2: ptc, pct = 'INF', 10
    else: ptc, pct = 'ADT', 100
    amt = (decimal.Decimal(str(x['fare'])) * pct / 100).quantize(decimal.Decimal('0.01'), rounding=decimal.ROUND_HALF_UP)
    return [ptc, float(amt)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['child day before 12th birthday', {'birth': '2016-05-11', 'depart': '2028-05-10', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 413.5}, ['ADT', 413.5]], ['infant turns two on travel day', {'birth': '2026-03-01', 'depart': '2028-03-01', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 301.0}, ['INF', 30.1]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-11', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-01', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2015-02-22', 'depart': '2027-02-15', 'fare': 171.9}, ['CHD', 128.93]], ['sampled case 2', {'birth': '2023-11-19', 'depart': '2029-03-25', 'fare': 1444.58}, ['CHD', 1083.44]], ['sampled case 3', {'birth': '2027-08-22', 'depart': '2029-08-21', 'fare': 608.88}, ['INF', 60.89]]], [['child day before 12th birthday', {'birth': '2016-05-12', 'depart': '2028-05-11', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 414.5}, ['ADT', 414.5]], ['infant turns two on travel day', {'birth': '2026-03-02', 'depart': '2028-03-02', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 302.0}, ['INF', 30.2]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-12', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-02', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2025-04-03', 'depart': '2027-04-02', 'fare': 516.1}, ['INF', 51.61]], ['sampled case 2', {'birth': '2026-06-08', 'depart': '2028-06-06', 'fare': 952.7}, ['INF', 95.27]], ['sampled case 3', {'birth': '2017-05-05', 'depart': '2029-05-02', 'fare': 942.13}, ['CHD', 706.6]]], [['child day before 12th birthday', {'birth': '2016-05-13', 'depart': '2028-05-12', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 415.5}, ['ADT', 415.5]], ['infant turns two on travel day', {'birth': '2026-03-03', 'depart': '2028-03-03', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 303.0}, ['INF', 30.3]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-13', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-03', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2017-10-23', 'depart': '2029-10-19', 'fare': 1447.34}, ['CHD', 1085.51]], ['sampled case 2', {'birth': '2016-03-06', 'depart': '2028-02-28', 'fare': 1074.9}, ['CHD', 806.18]], ['sampled case 3', {'birth': '2015-06-23', 'depart': '2027-06-20', 'fare': 768.6}, ['CHD', 576.45]]], [['child day before 12th birthday', {'birth': '2016-05-14', 'depart': '2028-05-13', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 416.5}, ['ADT', 416.5]], ['infant turns two on travel day', {'birth': '2026-03-04', 'depart': '2028-03-04', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 304.0}, ['INF', 30.4]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-14', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-04', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2028-06-21', 'depart': '2029-08-22', 'fare': 642.31}, ['INF', 64.23]], ['sampled case 2', {'birth': '2019-06-26', 'depart': '2027-12-23', 'fare': 211.9}, ['CHD', 158.93]], ['sampled case 3', {'birth': '2025-09-18', 'depart': '2027-09-19', 'fare': 1456.7}, ['CHD', 1092.53]]], [['child day before 12th birthday', {'birth': '2016-05-15', 'depart': '2028-05-14', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 417.5}, ['ADT', 417.5]], ['infant turns two on travel day', {'birth': '2026-03-05', 'depart': '2028-03-05', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 305.0}, ['INF', 30.5]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-15', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-05', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2026-08-03', 'depart': '2028-07-31', 'fare': 265.0}, ['INF', 26.5]], ['sampled case 2', {'birth': '2026-08-19', 'depart': '2028-08-19', 'fare': 820.15}, ['CHD', 615.11]], ['sampled case 3', {'birth': '2017-09-28', 'depart': '2029-09-26', 'fare': 855.8}, ['CHD', 641.85]]]]
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 datetime
import decimal
N = 1
observations = []
def solve(x):
    b = datetime.date.fromisoformat(x['birth'])
    d = datetime.date.fromisoformat(x['depart'])
    try:
        bday = b.replace(year=d.year)
    except ValueError:
        bday = datetime.date(d.year, 3, 1)
    age = d.year - b.year - (1 if d < bday else 0)
    if 2 <= age < 12: ptc, pct = 'CHD', 75
    elif age < 1: ptc, pct = 'INF', 10
    else: ptc, pct = 'ADT', 100
    amt = (decimal.Decimal(str(x['fare'])) * pct / 100).quantize(decimal.Decimal('0.01'), rounding=decimal.ROUND_HALF_UP)
    return [ptc, float(amt)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['child day before 12th birthday', {'birth': '2016-05-11', 'depart': '2028-05-10', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 413.5}, ['ADT', 413.5]], ['infant turns two on travel day', {'birth': '2026-03-01', 'depart': '2028-03-01', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 301.0}, ['INF', 30.1]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-11', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-01', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2015-02-22', 'depart': '2027-02-15', 'fare': 171.9}, ['CHD', 128.93]], ['sampled case 2', {'birth': '2023-11-19', 'depart': '2029-03-25', 'fare': 1444.58}, ['CHD', 1083.44]], ['sampled case 3', {'birth': '2027-08-22', 'depart': '2029-08-21', 'fare': 608.88}, ['INF', 60.89]]], [['child day before 12th birthday', {'birth': '2016-05-12', 'depart': '2028-05-11', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 414.5}, ['ADT', 414.5]], ['infant turns two on travel day', {'birth': '2026-03-02', 'depart': '2028-03-02', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 302.0}, ['INF', 30.2]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-12', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-02', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2025-04-03', 'depart': '2027-04-02', 'fare': 516.1}, ['INF', 51.61]], ['sampled case 2', {'birth': '2026-06-08', 'depart': '2028-06-06', 'fare': 952.7}, ['INF', 95.27]], ['sampled case 3', {'birth': '2017-05-05', 'depart': '2029-05-02', 'fare': 942.13}, ['CHD', 706.6]]], [['child day before 12th birthday', {'birth': '2016-05-13', 'depart': '2028-05-12', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 415.5}, ['ADT', 415.5]], ['infant turns two on travel day', {'birth': '2026-03-03', 'depart': '2028-03-03', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 303.0}, ['INF', 30.3]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-13', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-03', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2017-10-23', 'depart': '2029-10-19', 'fare': 1447.34}, ['CHD', 1085.51]], ['sampled case 2', {'birth': '2016-03-06', 'depart': '2028-02-28', 'fare': 1074.9}, ['CHD', 806.18]], ['sampled case 3', {'birth': '2015-06-23', 'depart': '2027-06-20', 'fare': 768.6}, ['CHD', 576.45]]], [['child day before 12th birthday', {'birth': '2016-05-14', 'depart': '2028-05-13', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 416.5}, ['ADT', 416.5]], ['infant turns two on travel day', {'birth': '2026-03-04', 'depart': '2028-03-04', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 304.0}, ['INF', 30.4]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-14', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-04', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2028-06-21', 'depart': '2029-08-22', 'fare': 642.31}, ['INF', 64.23]], ['sampled case 2', {'birth': '2019-06-26', 'depart': '2027-12-23', 'fare': 211.9}, ['CHD', 158.93]], ['sampled case 3', {'birth': '2025-09-18', 'depart': '2027-09-19', 'fare': 1456.7}, ['CHD', 1092.53]]], [['child day before 12th birthday', {'birth': '2016-05-15', 'depart': '2028-05-14', 'fare': 412.5}, ['CHD', 309.38]], ['12th birthday on departure', {'birth': '2016-05-10', 'depart': '2028-05-10', 'fare': 417.5}, ['ADT', 417.5]], ['infant turns two on travel day', {'birth': '2026-03-05', 'depart': '2028-03-05', 'fare': 399.9}, ['CHD', 299.93]], ['infant one day before second birthday', {'birth': '2026-03-15', 'depart': '2028-03-14', 'fare': 250.05}, ['INF', 25.01]], ['leap day birthday on Feb 28', {'birth': '2016-02-29', 'depart': '2028-02-28', 'fare': 300.0}, ['CHD', 225.0]], ['leap day infant in non-leap year', {'birth': '2024-02-29', 'depart': '2026-02-28', 'fare': 305.0}, ['INF', 30.5]], ['leap day infant on 1 March', {'birth': '2024-02-29', 'depart': '2026-03-01', 'fare': 310.0}, ['CHD', 232.5]], ['half-cent child fare', {'birth': '2020-07-01', 'depart': '2027-01-15', 'fare': 100.1}, ['CHD', 75.08]], ['adult later in year', {'birth': '1990-11-30', 'depart': '2027-06-05', 'fare': 823.33}, ['ADT', 823.33]], ['sampled case 1', {'birth': '2026-08-03', 'depart': '2028-07-31', 'fare': 265.0}, ['INF', 26.5]], ['sampled case 2', {'birth': '2026-08-19', 'depart': '2028-08-19', 'fare': 820.15}, ['CHD', 615.11]], ['sampled case 3', {'birth': '2017-09-28', 'depart': '2029-09-26', 'fare': 855.8}, ['CHD', 641.85]]]]
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:
Lap infants are quoted at 75% instead of 10%.

Input {'birth','depart' ISO dates,'fare'}. Age is completed years on the departure date; a 29 February birthday falls on 1 March in non-leap years. Under 2 -> INF 10%; 2 to 11 -> CHD 75%; otherwise ADT 100%. Amount = fare*pct/100 rounded half-up to cents. Return [ptc, amount].

split: open-access