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 = min(x['fee'], x['fee_pct'] * paid / 100)
    collect = max(0.0, 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)

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 = x['fee'] + x['fee_pct'] * paid / 100
    collect = max(0.0, 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:
Cheap tickets are charged a tiny percentage fee instead of the minimum flat fee.

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'] * new / 100)
    collect = max(0.0, 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'] * max(paid, new) / 100)
    collect = max(0.0, 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:
Upgrading to an expensive fare inflates the change penalty.

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 = max(0.0, 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)

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 int(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'] == '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:
A change made exactly 24 hours after ticketing is charged the full fee.

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 = max(0.0, 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)

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 - fee) 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 collect nothing even though the contract always collects the fee.

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