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

N = 1
observations = []
def solve(x):
    if x['zero_emission']:
        return 0
    byday = {}
    for d, m in sorted(x['crossings']):
        byday.setdefault(d, []).append(m)
    total = 0
    for d, ms in byday.items():
        if x['weekend_free'] and d % 7 >= 5:
            continue
        last = None
        day_sum = 0
        for m in ms:
            if last is not None and m - last <= x['grace']:
                continue
            last = m
            peak = any(s <= m < e for s, e in x['peak'])
            day_sum += x['peak_fee'] if peak else x['offpeak_fee']
        total += day_sum
    return total
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'crossings': [[6, 520], [8, 430], [8, 435], [0, 1106], [0, 1013]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2500), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[6, 497], [3, 958], [1, 326], [6, 1096], [1, 331], [8, 1070]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 3000), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[0, 1287], [0, 1302], [0, 1307], [2, 1091], [4, 959], [8, 998], [3, 769], [4, 644], [7, 461]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 4500), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[2, 347], [2, 352], [5, 726], [2, 1038], [7, 922], [8, 903], [2, 332]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2200), ({'crossings': [[0, 1186], [0, 531], [0, 807], [8, 437], [0, 975], [0, 1159], [0, 1154]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 2900)], [({'crossings': [[2, 1073], [7, 669], [4, 1136], [8, 1182], [8, 391], [4, 492]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 3000), ({'crossings': [[2, 416], [1, 1238], [2, 1124], [2, 431], [8, 952], [3, 965], [3, 1300]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 3400), ({'crossings': [[7, 869], [3, 859], [0, 544], [0, 1122], [4, 1253], [3, 675], [1, 929], [0, 1142], [6, 420]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2750), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[6, 1035], [7, 844], [2, 726], [2, 1037]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 2500), ({'crossings': [[1, 1185], [2, 606], [6, 710], [6, 812], [1, 719], [6, 721], [6, 736], [8, 822], [9, 1267]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 2700)], [({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[8, 1127], [7, 1208], [3, 443], [8, 415], [8, 1132], [8, 1112]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2700), ({'crossings': [[9, 1283], [2, 592], [4, 827], [4, 842], [8, 922], [7, 1070], [9, 1194], [2, 341]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 3300), ({'crossings': [[4, 502], [0, 1272], [7, 731], [4, 344], [4, 492], [2, 337], [4, 512]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 2750), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[7, 586], [5, 897], [1, 745], [2, 423], [7, 357], [2, 777], [4, 503], [1, 1075], [7, 362]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 4600), ({'crossings': [[8, 962], [8, 974]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1500)], [({'crossings': [[0, 930], [9, 511], [3, 655], [4, 476], [3, 1099], [0, 471], [3, 665], [3, 645], [3, 1032], [5, 1136]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 5300), ({'crossings': [[1, 972], [1, 992]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 1500), ({'crossings': [[5, 821], [1, 1260], [3, 425], [1, 614], [1, 604], [7, 629], [0, 651], [4, 469]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2600), ({'crossings': [[9, 475], [4, 460], [2, 477], [5, 386], [4, 651], [9, 455], [7, 710], [9, 1205], [4, 992]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 4150), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[7, 475], [7, 455], [0, 1155], [1, 872]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2400), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900)], [({'crossings': [[3, 573], [3, 585]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1500), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[3, 1246], [3, 413], [4, 534], [3, 1261]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1800), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[5, 1280], [4, 1116], [7, 944], [4, 1096]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1750), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[6, 629], [6, 481], [5, 417], [5, 1096], [7, 856], [3, 1083], [6, 452], [4, 996]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 5400), ({'crossings': [[9, 418], [2, 613], [9, 470], [9, 480], [9, 788], [3, 753], [7, 486]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 3200)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    if x['zero_emission']:
        return 0
    byday = {}
    for d, m in sorted(x['crossings']):
        byday.setdefault(d, []).append(m)
    total = 0
    for d, ms in byday.items():
        if x['weekend_free'] and d % 7 >= 5:
            continue
        last = None
        day_sum = 0
        for m in ms:
            if last is not None and m - last <= x['grace']:
                continue
            last = m
            peak = any(s <= m < e for s, e in x['peak'])
            day_sum += x['peak_fee'] if peak else x['offpeak_fee']
        total = min(total + day_sum, x['daily_cap'])
    return total
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'crossings': [[6, 520], [8, 430], [8, 435], [0, 1106], [0, 1013]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2500), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[6, 497], [3, 958], [1, 326], [6, 1096], [1, 331], [8, 1070]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 3000), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[0, 1287], [0, 1302], [0, 1307], [2, 1091], [4, 959], [8, 998], [3, 769], [4, 644], [7, 461]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 4500), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[2, 347], [2, 352], [5, 726], [2, 1038], [7, 922], [8, 903], [2, 332]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2200), ({'crossings': [[0, 1186], [0, 531], [0, 807], [8, 437], [0, 975], [0, 1159], [0, 1154]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 2900)], [({'crossings': [[2, 1073], [7, 669], [4, 1136], [8, 1182], [8, 391], [4, 492]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 3000), ({'crossings': [[2, 416], [1, 1238], [2, 1124], [2, 431], [8, 952], [3, 965], [3, 1300]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 3400), ({'crossings': [[7, 869], [3, 859], [0, 544], [0, 1122], [4, 1253], [3, 675], [1, 929], [0, 1142], [6, 420]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2750), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[6, 1035], [7, 844], [2, 726], [2, 1037]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 2500), ({'crossings': [[1, 1185], [2, 606], [6, 710], [6, 812], [1, 719], [6, 721], [6, 736], [8, 822], [9, 1267]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 2700)], [({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[8, 1127], [7, 1208], [3, 443], [8, 415], [8, 1132], [8, 1112]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2700), ({'crossings': [[9, 1283], [2, 592], [4, 827], [4, 842], [8, 922], [7, 1070], [9, 1194], [2, 341]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 3300), ({'crossings': [[4, 502], [0, 1272], [7, 731], [4, 344], [4, 492], [2, 337], [4, 512]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 2750), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[7, 586], [5, 897], [1, 745], [2, 423], [7, 357], [2, 777], [4, 503], [1, 1075], [7, 362]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 4600), ({'crossings': [[8, 962], [8, 974]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1500)], [({'crossings': [[0, 930], [9, 511], [3, 655], [4, 476], [3, 1099], [0, 471], [3, 665], [3, 645], [3, 1032], [5, 1136]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 5300), ({'crossings': [[1, 972], [1, 992]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 1500), ({'crossings': [[5, 821], [1, 1260], [3, 425], [1, 614], [1, 604], [7, 629], [0, 651], [4, 469]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2600), ({'crossings': [[9, 475], [4, 460], [2, 477], [5, 386], [4, 651], [9, 455], [7, 710], [9, 1205], [4, 992]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 4150), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[7, 475], [7, 455], [0, 1155], [1, 872]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2400), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900)], [({'crossings': [[3, 573], [3, 585]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1500), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[3, 1246], [3, 413], [4, 534], [3, 1261]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1800), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[5, 1280], [4, 1116], [7, 944], [4, 1096]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1750), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[6, 629], [6, 481], [5, 417], [5, 1096], [7, 856], [3, 1083], [6, 452], [4, 996]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 5400), ({'crossings': [[9, 418], [2, 613], [9, 470], [9, 480], [9, 788], [3, 753], [7, 486]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 3200)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Cordon congestion charge returns a wrong result when the cap applies to the whole billing period.

Input {crossings: [[day, minute]] unordered, peak: [[start, end)] windows, peak_fee, offpeak_fee, daily_cap, weekend_free, zero_emission, grace}. Zero-emission vehicles pay 0. Days with day % 7 in {5, 6} are free when weekend_free. Within a day, a crossing no more than grace minutes after the last charged crossing is free (the grace anchor is the charged crossing). Each charged crossing pays the peak fee inside a window else off-peak; each day's sum is capped at daily_cap.

split: open-access


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

N = 1
observations = []
def solve(x):
    if x['zero_emission']:
        return 0
    byday = {}
    for d, m in x['crossings']:
        byday.setdefault(d, []).append(m)
    total = 0
    for d, ms in byday.items():
        if x['weekend_free'] and d % 7 >= 5:
            continue
        last = None
        day_sum = 0
        for m in ms:
            if last is not None and m - last <= x['grace']:
                continue
            last = m
            peak = any(s <= m < e for s, e in x['peak'])
            day_sum += x['peak_fee'] if peak else x['offpeak_fee']
        total += min(day_sum, x['daily_cap'])
    return total
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'crossings': [[0, 970], [0, 953], [0, 965], [5, 777], [2, 1162], [9, 1014], [4, 1288]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 3000), ({'crossings': [[6, 508]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 0), ({'crossings': [[8, 1192], [6, 306], [7, 851], [7, 861]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 400), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[7, 755], [6, 780], [1, 1106], [5, 1167], [1, 866], [5, 594], [2, 497], [6, 310]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 4500), ({'crossings': [[9, 979], [9, 974], [9, 974], [0, 425], [7, 853]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2300), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400)], [({'crossings': [[6, 303], [4, 918], [2, 1131], [5, 742], [5, 1017], [2, 1111], [6, 717], [8, 351]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1900), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[6, 1186], [0, 416], [5, 646]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 250), ({'crossings': [[5, 385], [0, 706], [7, 930], [9, 1289], [2, 1199], [6, 1148]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 800), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[0, 906], [9, 1196], [0, 891], [7, 410]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 900), ({'crossings': [[9, 1207], [2, 985], [2, 853], [1, 981], [0, 898], [3, 301]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 2600)], [({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[7, 1298]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 200), ({'crossings': [[7, 1007], [7, 992]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2000), ({'crossings': [[5, 1168], [6, 901], [0, 1249], [9, 457], [1, 1050], [5, 703], [6, 896]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 2800), ({'crossings': [[4, 1149], [4, 1154], [2, 1209]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 500), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[3, 651], [5, 578]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 1150)], [({'crossings': [[4, 745], [5, 823], [4, 760], [1, 336], [5, 407], [7, 1242], [0, 434]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1750), ({'crossings': [[3, 1047]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[9, 935], [2, 830], [9, 767]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[1, 1059], [0, 1260], [4, 714], [1, 746], [0, 300]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1800), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[4, 843], [1, 828], [7, 460], [1, 838], [2, 453], [0, 839], [5, 884], [9, 1033]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 3700), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900)], [({'crossings': [[0, 1024], [4, 670], [1, 887], [3, 323], [9, 1207], [4, 493], [4, 390]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 3000), ({'crossings': [[2, 455], [5, 726], [3, 1042], [4, 348], [6, 1294]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2200), ({'crossings': [[2, 379], [2, 359], [2, 374], [0, 311], [6, 458], [3, 930]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 800), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[6, 1297]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 0), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[6, 558], [0, 747], [1, 1030]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1200)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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):
    if x['zero_emission']:
        return 0
    byday = {}
    for d, m in sorted(x['crossings'], reverse=True):
        byday.setdefault(d, []).append(m)
    total = 0
    for d, ms in byday.items():
        if x['weekend_free'] and d % 7 >= 5:
            continue
        last = None
        day_sum = 0
        for m in ms:
            if last is not None and m - last <= x['grace']:
                continue
            last = m
            peak = any(s <= m < e for s, e in x['peak'])
            day_sum += x['peak_fee'] if peak else x['offpeak_fee']
        total += min(day_sum, x['daily_cap'])
    return total
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'crossings': [[0, 970], [0, 953], [0, 965], [5, 777], [2, 1162], [9, 1014], [4, 1288]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 3000), ({'crossings': [[6, 508]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 0), ({'crossings': [[8, 1192], [6, 306], [7, 851], [7, 861]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 400), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[7, 755], [6, 780], [1, 1106], [5, 1167], [1, 866], [5, 594], [2, 497], [6, 310]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 4500), ({'crossings': [[9, 979], [9, 974], [9, 974], [0, 425], [7, 853]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2300), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400)], [({'crossings': [[6, 303], [4, 918], [2, 1131], [5, 742], [5, 1017], [2, 1111], [6, 717], [8, 351]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1900), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[6, 1186], [0, 416], [5, 646]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 250), ({'crossings': [[5, 385], [0, 706], [7, 930], [9, 1289], [2, 1199], [6, 1148]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 800), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[0, 906], [9, 1196], [0, 891], [7, 410]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 900), ({'crossings': [[9, 1207], [2, 985], [2, 853], [1, 981], [0, 898], [3, 301]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 2600)], [({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[7, 1298]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 200), ({'crossings': [[7, 1007], [7, 992]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2000), ({'crossings': [[5, 1168], [6, 901], [0, 1249], [9, 457], [1, 1050], [5, 703], [6, 896]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 2800), ({'crossings': [[4, 1149], [4, 1154], [2, 1209]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 500), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[3, 651], [5, 578]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 1150)], [({'crossings': [[4, 745], [5, 823], [4, 760], [1, 336], [5, 407], [7, 1242], [0, 434]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1750), ({'crossings': [[3, 1047]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[9, 935], [2, 830], [9, 767]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[1, 1059], [0, 1260], [4, 714], [1, 746], [0, 300]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1800), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[4, 843], [1, 828], [7, 460], [1, 838], [2, 453], [0, 839], [5, 884], [9, 1033]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 3700), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900)], [({'crossings': [[0, 1024], [4, 670], [1, 887], [3, 323], [9, 1207], [4, 493], [4, 390]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 3000), ({'crossings': [[2, 455], [5, 726], [3, 1042], [4, 348], [6, 1294]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2200), ({'crossings': [[2, 379], [2, 359], [2, 374], [0, 311], [6, 458], [3, 930]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 800), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[6, 1297]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 0), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[6, 558], [0, 747], [1, 1030]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1200)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Cordon congestion charge returns a wrong result when crossings are processed in the order received.

Input {crossings: [[day, minute]] unordered, peak: [[start, end)] windows, peak_fee, offpeak_fee, daily_cap, weekend_free, zero_emission, grace}. Zero-emission vehicles pay 0. Days with day % 7 in {5, 6} are free when weekend_free. Within a day, a crossing no more than grace minutes after the last charged crossing is free (the grace anchor is the charged crossing). Each charged crossing pays the peak fee inside a window else off-peak; each day's sum is capped at daily_cap.

split: open-access


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

N = 1
observations = []
def solve(x):
    target = x['max_price']
    for upto, price in x['bands']:
        if x['density'] < upto:
            target = price
            break
    prev = x['prev_price']
    step = max(-x['max_step'], min(x['max_step'], target - prev))
    price = max(x['min_price'], min(x['max_price'], prev + step))
    if x['occupancy'] >= x['hov_free_min']:
        return [price, 0]
    if x['occupancy'] == 2:
        return [price, price * x['hov2_pct'] // 100 // 5 * 5]
    return [price, price]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 27, 'prev_price': 700, 'bands': [[13, 250], [14, 450], [27, 550], [34, 850]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 70}, [675, 0]), ({'density': 15, 'prev_price': 325, 'bands': [[10, 150], [15, 275], [33, 550], [36, 800]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 3, 'hov_free_min': 2, 'hov2_pct': 50}, [275, 0]), ({'density': 43, 'prev_price': 800, 'bands': [[25, 125], [40, 200], [42, 375], [43, 825]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 1, 'hov_free_min': 2, 'hov2_pct': 50}, [825, 825]), ({'density': 11, 'prev_price': 525, 'bands': [[11, 100], [14, 500], [16, 675], [33, 725]], 'max_step': 50, 'min_price': 50, 'max_price': 1200, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [475, 475]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 11, 'prev_price': 450, 'bands': [[10, 75], [11, 475], [15, 500], [26, 875]], 'max_step': 100, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 50}, [475, 235])], [({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 39, 'prev_price': 725, 'bands': [[20, 100], [24, 125], [38, 225], [39, 875]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 4, 'hov_free_min': 2, 'hov2_pct': 70}, [825, 0]), ({'density': 24, 'prev_price': 225, 'bands': [[17, 175], [24, 225], [25, 650], [42, 925]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 50}, [225, 110]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 38, 'prev_price': 400, 'bands': [[23, 200], [38, 300], [41, 400], [43, 725]], 'max_step': 50, 'min_price': 50, 'max_price': 800, 'occupancy': 2, 'hov_free_min': 4, 'hov2_pct': 50}, [350, 175]), ({'density': 34, 'prev_price': 400, 'bands': [[18, 225], [34, 375], [39, 700], [44, 1000]], 'max_step': 25, 'min_price': 50, 'max_price': 1200, 'occupancy': 4, 'hov_free_min': 2, 'hov2_pct': 50}, [375, 0]), ({'density': 34, 'prev_price': 850, 'bands': [[11, 75], [12, 100], [33, 400], [34, 825]], 'max_step': 100, 'min_price': 50, 'max_price': 1000, 'occupancy': 4, 'hov_free_min': 4, 'hov2_pct': 70}, [825, 0]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245])], [({'density': 15, 'prev_price': 425, 'bands': [[14, 200], [15, 475], [21, 500], [39, 625]], 'max_step': 50, 'min_price': 50, 'max_price': 1200, 'occupancy': 3, 'hov_free_min': 4, 'hov2_pct': 70}, [475, 475]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 15, 'prev_price': 275, 'bands': [[10, 175], [15, 200], [30, 300], [37, 875]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [225, 225]), ({'density': 24, 'prev_price': 375, 'bands': [[18, 50], [24, 200], [30, 400], [40, 850]], 'max_step': 50, 'min_price': 50, 'max_price': 1200, 'occupancy': 1, 'hov_free_min': 4, 'hov2_pct': 70}, [325, 325]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 31, 'prev_price': 425, 'bands': [[29, 50], [31, 275], [35, 750], [38, 900]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 50}, [325, 0]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 22, 'prev_price': 450, 'bands': [[21, 225], [22, 500], [42, 600], [43, 825]], 'max_step': 25, 'min_price': 50, 'max_price': 800, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 70}, [475, 0])], [({'density': 35, 'prev_price': 350, 'bands': [[31, 50], [32, 200], [34, 375], [35, 950]], 'max_step': 50, 'min_price': 50, 'max_price': 1200, 'occupancy': 2, 'hov_free_min': 2, 'hov2_pct': 70}, [400, 0]), ({'density': 29, 'prev_price': 325, 'bands': [[28, 50], [29, 325], [31, 800], [42, 850]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 4, 'hov2_pct': 50}, [325, 325]), ({'density': 16, 'prev_price': 275, 'bands': [[16, 250], [33, 275], [36, 325], [42, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 2, 'hov2_pct': 50}, [250, 250]), ({'density': 33, 'prev_price': 850, 'bands': [[17, 175], [26, 500], [27, 525], [33, 875]], 'max_step': 50, 'min_price': 50, 'max_price': 1200, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 50}, [875, 0]), ({'density': 19, 'prev_price': 425, 'bands': [[19, 200], [21, 400], [27, 425], [29, 450]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 2, 'hov2_pct': 50}, [375, 375]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245])], [({'density': 14, 'prev_price': 75, 'bands': [[13, 50], [14, 300], [17, 400], [38, 450]], 'max_step': 100, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [175, 175]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 32, 'prev_price': 725, 'bands': [[18, 225], [31, 550], [32, 825], [42, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [750, 750]), ({'density': 24, 'prev_price': 725, 'bands': [[11, 300], [18, 375], [24, 600], [35, 925]], 'max_step': 50, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [675, 675]), ({'density': 27, 'prev_price': 650, 'bands': [[19, 450], [27, 725], [33, 850], [40, 1000]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 1, 'hov_free_min': 4, 'hov2_pct': 70}, [725, 725]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 25, 'prev_price': 775, 'bands': [[10, 225], [11, 600], [25, 725], [39, 1000]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 50}, [725, 360]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    target = x['max_price']
    for upto, price in x['bands']:
        if x['density'] <= upto + 1:
            target = price
            break
    prev = x['prev_price']
    step = max(-x['max_step'], min(x['max_step'], target - prev))
    price = max(x['min_price'], min(x['max_price'], prev + step))
    if x['occupancy'] >= x['hov_free_min']:
        return [price, 0]
    if x['occupancy'] == 2:
        return [price, price * x['hov2_pct'] // 100 // 5 * 5]
    return [price, price]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 27, 'prev_price': 700, 'bands': [[13, 250], [14, 450], [27, 550], [34, 850]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 70}, [675, 0]), ({'density': 15, 'prev_price': 325, 'bands': [[10, 150], [15, 275], [33, 550], [36, 800]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 3, 'hov_free_min': 2, 'hov2_pct': 50}, [275, 0]), ({'density': 43, 'prev_price': 800, 'bands': [[25, 125], [40, 200], [42, 375], [43, 825]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 1, 'hov_free_min': 2, 'hov2_pct': 50}, [825, 825]), ({'density': 11, 'prev_price': 525, 'bands': [[11, 100], [14, 500], [16, 675], [33, 725]], 'max_step': 50, 'min_price': 50, 'max_price': 1200, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [475, 475]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 11, 'prev_price': 450, 'bands': [[10, 75], [11, 475], [15, 500], [26, 875]], 'max_step': 100, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 50}, [475, 235])], [({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 39, 'prev_price': 725, 'bands': [[20, 100], [24, 125], [38, 225], [39, 875]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 4, 'hov_free_min': 2, 'hov2_pct': 70}, [825, 0]), ({'density': 24, 'prev_price': 225, 'bands': [[17, 175], [24, 225], [25, 650], [42, 925]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 50}, [225, 110]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 38, 'prev_price': 400, 'bands': [[23, 200], [38, 300], [41, 400], [43, 725]], 'max_step': 50, 'min_price': 50, 'max_price': 800, 'occupancy': 2, 'hov_free_min': 4, 'hov2_pct': 50}, [350, 175]), ({'density': 34, 'prev_price': 400, 'bands': [[18, 225], [34, 375], [39, 700], [44, 1000]], 'max_step': 25, 'min_price': 50, 'max_price': 1200, 'occupancy': 4, 'hov_free_min': 2, 'hov2_pct': 50}, [375, 0]), ({'density': 34, 'prev_price': 850, 'bands': [[11, 75], [12, 100], [33, 400], [34, 825]], 'max_step': 100, 'min_price': 50, 'max_price': 1000, 'occupancy': 4, 'hov_free_min': 4, 'hov2_pct': 70}, [825, 0]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245])], [({'density': 15, 'prev_price': 425, 'bands': [[14, 200], [15, 475], [21, 500], [39, 625]], 'max_step': 50, 'min_price': 50, 'max_price': 1200, 'occupancy': 3, 'hov_free_min': 4, 'hov2_pct': 70}, [475, 475]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 15, 'prev_price': 275, 'bands': [[10, 175], [15, 200], [30, 300], [37, 875]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [225, 225]), ({'density': 24, 'prev_price': 375, 'bands': [[18, 50], [24, 200], [30, 400], [40, 850]], 'max_step': 50, 'min_price': 50, 'max_price': 1200, 'occupancy': 1, 'hov_free_min': 4, 'hov2_pct': 70}, [325, 325]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 31, 'prev_price': 425, 'bands': [[29, 50], [31, 275], [35, 750], [38, 900]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 50}, [325, 0]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 22, 'prev_price': 450, 'bands': [[21, 225], [22, 500], [42, 600], [43, 825]], 'max_step': 25, 'min_price': 50, 'max_price': 800, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 70}, [475, 0])], [({'density': 35, 'prev_price': 350, 'bands': [[31, 50], [32, 200], [34, 375], [35, 950]], 'max_step': 50, 'min_price': 50, 'max_price': 1200, 'occupancy': 2, 'hov_free_min': 2, 'hov2_pct': 70}, [400, 0]), ({'density': 29, 'prev_price': 325, 'bands': [[28, 50], [29, 325], [31, 800], [42, 850]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 4, 'hov2_pct': 50}, [325, 325]), ({'density': 16, 'prev_price': 275, 'bands': [[16, 250], [33, 275], [36, 325], [42, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 2, 'hov2_pct': 50}, [250, 250]), ({'density': 33, 'prev_price': 850, 'bands': [[17, 175], [26, 500], [27, 525], [33, 875]], 'max_step': 50, 'min_price': 50, 'max_price': 1200, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 50}, [875, 0]), ({'density': 19, 'prev_price': 425, 'bands': [[19, 200], [21, 400], [27, 425], [29, 450]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 2, 'hov2_pct': 50}, [375, 375]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245])], [({'density': 14, 'prev_price': 75, 'bands': [[13, 50], [14, 300], [17, 400], [38, 450]], 'max_step': 100, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [175, 175]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 32, 'prev_price': 725, 'bands': [[18, 225], [31, 550], [32, 825], [42, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [750, 750]), ({'density': 24, 'prev_price': 725, 'bands': [[11, 300], [18, 375], [24, 600], [35, 925]], 'max_step': 50, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [675, 675]), ({'density': 27, 'prev_price': 650, 'bands': [[19, 450], [27, 725], [33, 850], [40, 1000]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 1, 'hov_free_min': 4, 'hov2_pct': 70}, [725, 725]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 25, 'prev_price': 775, 'bands': [[10, 225], [11, 600], [25, 725], [39, 1000]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 50}, [725, 360]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Express lane dynamic price returns a wrong result when a density equal to the band limit falls into the next band.

Input {density, prev_price, bands: [[density upto, price]] ascending, max_step, min_price, max_price, occupancy, hov_free_min, hov2_pct}. The target is the first band whose upto is >= density, else max_price. The posted price moves from prev_price toward the target by at most max_step either way, then is clamped to [min_price, max_price]. Vehicles with occupancy >= hov_free_min pay 0; occupancy 2 (when not free) pays hov2_pct percent floored to 5 cents. Return [posted, charged].

split: open-access


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

N = 1
observations = []
def solve(x):
    target = x['max_price']
    for upto, price in x['bands']:
        if x['density'] <= upto:
            target = price
            break
    prev = x['prev_price']
    step = min(x['max_step'], target - prev)
    price = max(x['min_price'], min(x['max_price'], prev + step))
    if x['occupancy'] >= x['hov_free_min']:
        return [price, 0]
    if x['occupancy'] == 2:
        return [price, price * x['hov2_pct'] // 100 // 5 * 5]
    return [price, price]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 13, 'prev_price': 1250, 'bands': [[10, 50], [13, 550], [18, 750], [26, 975]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [800, 560]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 44, 'prev_price': 1050, 'bands': [[23, 125], [24, 150], [40, 350], [44, 450]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 3, 'hov_free_min': 2, 'hov2_pct': 70}, [1000, 0]), ({'density': 21, 'prev_price': 825, 'bands': [[21, 300], [28, 325], [35, 750], [36, 850]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 3, 'hov_free_min': 4, 'hov2_pct': 70}, [800, 800]), ({'density': 35, 'prev_price': 1150, 'bands': [[20, 100], [25, 150], [34, 625], [35, 800]], 'max_step': 100, 'min_price': 50, 'max_price': 1000, 'occupancy': 4, 'hov_free_min': 2, 'hov2_pct': 70}, [1000, 0]), ({'density': 15, 'prev_price': 875, 'bands': [[12, 150], [15, 475], [30, 550], [44, 600]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 4, 'hov2_pct': 50}, [850, 850]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50])], [({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 11, 'prev_price': 425, 'bands': [[11, 250], [17, 600], [38, 775], [41, 850]], 'max_step': 100, 'min_price': 50, 'max_price': 1000, 'occupancy': 4, 'hov_free_min': 3, 'hov2_pct': 70}, [325, 0]), ({'density': 44, 'prev_price': 375, 'bands': [[16, 250], [22, 325], [30, 675], [44, 750]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 4, 'hov_free_min': 3, 'hov2_pct': 50}, [400, 0]), ({'density': 24, 'prev_price': 1225, 'bands': [[24, 50], [28, 700], [30, 800], [44, 925]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 50}, [800, 0]), ({'density': 32, 'prev_price': 600, 'bands': [[12, 250], [13, 275], [21, 475], [32, 700]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 4, 'hov_free_min': 2, 'hov2_pct': 50}, [625, 0]), ({'density': 42, 'prev_price': 1225, 'bands': [[11, 125], [21, 325], [42, 850], [44, 1000]], 'max_step': 50, 'min_price': 50, 'max_price': 1200, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1175, 1175]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245])], [({'density': 25, 'prev_price': 1100, 'bands': [[13, 175], [18, 325], [20, 350], [37, 650]], 'max_step': 100, 'min_price': 50, 'max_price': 1000, 'occupancy': 3, 'hov_free_min': 4, 'hov2_pct': 50}, [1000, 1000]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 23, 'prev_price': 525, 'bands': [[11, 225], [17, 450], [23, 625], [27, 925]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 4, 'hov_free_min': 3, 'hov2_pct': 50}, [625, 0]), ({'density': 38, 'prev_price': 1125, 'bands': [[19, 375], [23, 775], [36, 900], [38, 975]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [1025, 1025]), ({'density': 3, 'prev_price': 425, 'bands': [[12, 275], [34, 850], [38, 875], [40, 975]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 2, 'hov2_pct': 50}, [325, 325]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 37, 'prev_price': 700, 'bands': [[16, 175], [17, 200], [22, 300], [37, 675]], 'max_step': 50, 'min_price': 50, 'max_price': 1200, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 70}, [675, 0])], [({'density': 17, 'prev_price': 100, 'bands': [[10, 125], [17, 325], [30, 675], [41, 750]], 'max_step': 50, 'min_price': 50, 'max_price': 800, 'occupancy': 2, 'hov_free_min': 4, 'hov2_pct': 70}, [150, 105]), ({'density': 15, 'prev_price': 975, 'bands': [[15, 125], [18, 250], [42, 525], [43, 975]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [800, 560]), ({'density': 23, 'prev_price': 1050, 'bands': [[14, 100], [15, 175], [23, 575], [32, 700]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 70}, [800, 0]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 27, 'prev_price': 625, 'bands': [[19, 75], [27, 250], [33, 450], [36, 775]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [525, 525]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 23, 'prev_price': 725, 'bands': [[20, 275], [23, 350], [34, 675], [35, 750]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 4, 'hov2_pct': 70}, [675, 675]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245])], [({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 30, 'prev_price': 175, 'bands': [[18, 325], [27, 425], [28, 575], [42, 875]], 'max_step': 100, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [275, 275]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 42, 'prev_price': 375, 'bands': [[11, 175], [26, 375], [32, 650], [42, 950]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 4, 'hov_free_min': 2, 'hov2_pct': 70}, [475, 0]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 23, 'prev_price': 750, 'bands': [[13, 325], [23, 450], [39, 850], [44, 875]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 2, 'hov_free_min': 4, 'hov2_pct': 50}, [650, 325]), ({'density': 21, 'prev_price': 900, 'bands': [[17, 75], [21, 100], [25, 400], [35, 625]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 4, 'hov_free_min': 3, 'hov2_pct': 70}, [800, 0]), ({'density': 20, 'prev_price': 900, 'bands': [[20, 50], [26, 400], [28, 525], [43, 750]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 4, 'hov_free_min': 4, 'hov2_pct': 70}, [800, 0])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    target = x['max_price']
    for upto, price in x['bands']:
        if x['density'] <= upto:
            target = price
            break
    prev = x['prev_price']
    step = max(-x['max_step'], min(x['max_step'], abs(target - prev)))
    price = max(x['min_price'], min(x['max_price'], prev + step))
    if x['occupancy'] >= x['hov_free_min']:
        return [price, 0]
    if x['occupancy'] == 2:
        return [price, price * x['hov2_pct'] // 100 // 5 * 5]
    return [price, price]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 13, 'prev_price': 1250, 'bands': [[10, 50], [13, 550], [18, 750], [26, 975]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [800, 560]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 44, 'prev_price': 1050, 'bands': [[23, 125], [24, 150], [40, 350], [44, 450]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 3, 'hov_free_min': 2, 'hov2_pct': 70}, [1000, 0]), ({'density': 21, 'prev_price': 825, 'bands': [[21, 300], [28, 325], [35, 750], [36, 850]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 3, 'hov_free_min': 4, 'hov2_pct': 70}, [800, 800]), ({'density': 35, 'prev_price': 1150, 'bands': [[20, 100], [25, 150], [34, 625], [35, 800]], 'max_step': 100, 'min_price': 50, 'max_price': 1000, 'occupancy': 4, 'hov_free_min': 2, 'hov2_pct': 70}, [1000, 0]), ({'density': 15, 'prev_price': 875, 'bands': [[12, 150], [15, 475], [30, 550], [44, 600]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 4, 'hov2_pct': 50}, [850, 850]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50])], [({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 11, 'prev_price': 425, 'bands': [[11, 250], [17, 600], [38, 775], [41, 850]], 'max_step': 100, 'min_price': 50, 'max_price': 1000, 'occupancy': 4, 'hov_free_min': 3, 'hov2_pct': 70}, [325, 0]), ({'density': 44, 'prev_price': 375, 'bands': [[16, 250], [22, 325], [30, 675], [44, 750]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 4, 'hov_free_min': 3, 'hov2_pct': 50}, [400, 0]), ({'density': 24, 'prev_price': 1225, 'bands': [[24, 50], [28, 700], [30, 800], [44, 925]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 50}, [800, 0]), ({'density': 32, 'prev_price': 600, 'bands': [[12, 250], [13, 275], [21, 475], [32, 700]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 4, 'hov_free_min': 2, 'hov2_pct': 50}, [625, 0]), ({'density': 42, 'prev_price': 1225, 'bands': [[11, 125], [21, 325], [42, 850], [44, 1000]], 'max_step': 50, 'min_price': 50, 'max_price': 1200, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1175, 1175]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245])], [({'density': 25, 'prev_price': 1100, 'bands': [[13, 175], [18, 325], [20, 350], [37, 650]], 'max_step': 100, 'min_price': 50, 'max_price': 1000, 'occupancy': 3, 'hov_free_min': 4, 'hov2_pct': 50}, [1000, 1000]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 23, 'prev_price': 525, 'bands': [[11, 225], [17, 450], [23, 625], [27, 925]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 4, 'hov_free_min': 3, 'hov2_pct': 50}, [625, 0]), ({'density': 38, 'prev_price': 1125, 'bands': [[19, 375], [23, 775], [36, 900], [38, 975]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [1025, 1025]), ({'density': 3, 'prev_price': 425, 'bands': [[12, 275], [34, 850], [38, 875], [40, 975]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 2, 'hov2_pct': 50}, [325, 325]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 37, 'prev_price': 700, 'bands': [[16, 175], [17, 200], [22, 300], [37, 675]], 'max_step': 50, 'min_price': 50, 'max_price': 1200, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 70}, [675, 0])], [({'density': 17, 'prev_price': 100, 'bands': [[10, 125], [17, 325], [30, 675], [41, 750]], 'max_step': 50, 'min_price': 50, 'max_price': 800, 'occupancy': 2, 'hov_free_min': 4, 'hov2_pct': 70}, [150, 105]), ({'density': 15, 'prev_price': 975, 'bands': [[15, 125], [18, 250], [42, 525], [43, 975]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [800, 560]), ({'density': 23, 'prev_price': 1050, 'bands': [[14, 100], [15, 175], [23, 575], [32, 700]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 70}, [800, 0]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 27, 'prev_price': 625, 'bands': [[19, 75], [27, 250], [33, 450], [36, 775]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [525, 525]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 23, 'prev_price': 725, 'bands': [[20, 275], [23, 350], [34, 675], [35, 750]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 4, 'hov2_pct': 70}, [675, 675]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245])], [({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 30, 'prev_price': 175, 'bands': [[18, 325], [27, 425], [28, 575], [42, 875]], 'max_step': 100, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [275, 275]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 42, 'prev_price': 375, 'bands': [[11, 175], [26, 375], [32, 650], [42, 950]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 4, 'hov_free_min': 2, 'hov2_pct': 70}, [475, 0]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 23, 'prev_price': 750, 'bands': [[13, 325], [23, 450], [39, 850], [44, 875]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 2, 'hov_free_min': 4, 'hov2_pct': 50}, [650, 325]), ({'density': 21, 'prev_price': 900, 'bands': [[17, 75], [21, 100], [25, 400], [35, 625]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 4, 'hov_free_min': 3, 'hov2_pct': 70}, [800, 0]), ({'density': 20, 'prev_price': 900, 'bands': [[20, 50], [26, 400], [28, 525], [43, 750]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 4, 'hov_free_min': 4, 'hov2_pct': 70}, [800, 0])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Express lane dynamic price returns a wrong result when price decreases are not rate limited.

Input {density, prev_price, bands: [[density upto, price]] ascending, max_step, min_price, max_price, occupancy, hov_free_min, hov2_pct}. The target is the first band whose upto is >= density, else max_price. The posted price moves from prev_price toward the target by at most max_step either way, then is clamped to [min_price, max_price]. Vehicles with occupancy >= hov_free_min pay 0; occupancy 2 (when not free) pays hov2_pct percent floored to 5 cents. Return [posted, charged].

split: open-access


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

N = 1
observations = []
def solve(x):
    target = x['max_price']
    for upto, price in x['bands']:
        if x['density'] <= upto:
            target = price
            break
    prev = x['prev_price']
    step = max(-x['max_step'], min(x['max_step'], target - prev))
    price = prev + step
    if x['occupancy'] >= x['hov_free_min']:
        return [price, 0]
    if x['occupancy'] == 2:
        return [price, price * x['hov2_pct'] // 100 // 5 * 5]
    return [price, price]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'density': 37, 'prev_price': 650, 'bands': [[13, 475], [36, 650], [37, 800], [42, 1000]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 70}, [750, 0]), ({'density': 19, 'prev_price': 625, 'bands': [[13, 125], [19, 725], [23, 750], [36, 925]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 50}, [675, 335]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 21, 'prev_price': 1250, 'bands': [[18, 225], [21, 250], [22, 350], [43, 525]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [800, 800]), ({'density': 44, 'prev_price': 1200, 'bands': [[19, 450], [40, 525], [41, 650], [44, 925]], 'max_step': 50, 'min_price': 50, 'max_price': 1200, 'occupancy': 4, 'hov_free_min': 3, 'hov2_pct': 50}, [1150, 0]), ({'density': 11, 'prev_price': 1250, 'bands': [[11, 275], [17, 500], [21, 700], [44, 825]], 'max_step': 50, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [800, 800])], [({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 19, 'prev_price': 1250, 'bands': [[19, 275], [23, 475], [24, 575], [38, 825]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 0]), ({'density': 23, 'prev_price': 0, 'bands': [[13, 175], [19, 475], [23, 700], [29, 850]], 'max_step': 25, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 4, 'hov2_pct': 50}, [50, 50]), ({'density': 35, 'prev_price': 700, 'bands': [[23, 150], [33, 450], [38, 725], [41, 950]], 'max_step': 25, 'min_price': 50, 'max_price': 1200, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 50}, [725, 360]), ({'density': 17, 'prev_price': 625, 'bands': [[17, 300], [28, 500], [30, 700], [36, 925]], 'max_step': 25, 'min_price': 50, 'max_price': 800, 'occupancy': 3, 'hov_free_min': 4, 'hov2_pct': 70}, [600, 600]), ({'density': 3, 'prev_price': 250, 'bands': [[15, 425], [20, 600], [24, 775], [27, 975]], 'max_step': 50, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 4, 'hov2_pct': 50}, [300, 300])], [({'density': 42, 'prev_price': 0, 'bands': [[14, 225], [16, 675], [30, 775], [42, 925]], 'max_step': 25, 'min_price': 50, 'max_price': 1200, 'occupancy': 4, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 0]), ({'density': 10, 'prev_price': 225, 'bands': [[10, 75], [16, 300], [36, 725], [44, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [200, 200]), ({'density': 16, 'prev_price': 1200, 'bands': [[13, 50], [16, 450], [17, 725], [39, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1200, 'occupancy': 1, 'hov_free_min': 2, 'hov2_pct': 70}, [1175, 1175]), ({'density': 34, 'prev_price': 1175, 'bands': [[16, 225], [27, 325], [39, 400], [40, 475]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [1000, 1000]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 22, 'prev_price': 500, 'bands': [[10, 350], [19, 425], [22, 450], [24, 650]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 4, 'hov2_pct': 50}, [450, 450]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50])], [({'density': 18, 'prev_price': 850, 'bands': [[18, 100], [20, 175], [35, 250], [44, 800]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 50}, [825, 0]), ({'density': 16, 'prev_price': 25, 'bands': [[16, 50], [23, 350], [26, 700], [36, 725]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 4, 'hov_free_min': 4, 'hov2_pct': 70}, [50, 0]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 49, 'prev_price': 0, 'bands': [[12, 350], [33, 475], [34, 500], [41, 800]], 'max_step': 25, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [50, 50]), ({'density': 19, 'prev_price': 250, 'bands': [[19, 275], [31, 450], [37, 675], [40, 700]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 50}, [275, 135]), ({'density': 35, 'prev_price': 1300, 'bands': [[31, 175], [38, 200], [40, 400], [42, 800]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 0]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245])], [({'density': 14, 'prev_price': 925, 'bands': [[10, 150], [12, 525], [14, 750], [40, 850]], 'max_step': 25, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 2, 'hov2_pct': 70}, [800, 800]), ({'density': 34, 'prev_price': 0, 'bands': [[27, 450], [29, 525], [34, 550], [42, 950]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 4, 'hov2_pct': 50}, [50, 50]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 34, 'prev_price': 250, 'bands': [[16, 325], [33, 400], [34, 475], [38, 1000]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 3, 'hov_free_min': 2, 'hov2_pct': 50}, [350, 0]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 37, 'prev_price': 850, 'bands': [[22, 525], [30, 800], [37, 825], [44, 975]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 4, 'hov_free_min': 2, 'hov2_pct': 70}, [825, 0]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 41, 'prev_price': 350, 'bands': [[29, 225], [33, 525], [41, 575], [44, 625]], 'max_step': 50, 'min_price': 50, 'max_price': 1200, 'occupancy': 4, 'hov_free_min': 4, 'hov2_pct': 50}, [400, 0])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    target = x['max_price']
    for upto, price in x['bands']:
        if x['density'] <= upto:
            target = price
            break
    prev = x['prev_price']
    step = max(-x['max_step'], min(x['max_step'], target - prev))
    price = min(x['max_price'], prev + step)
    if x['occupancy'] >= x['hov_free_min']:
        return [price, 0]
    if x['occupancy'] == 2:
        return [price, price * x['hov2_pct'] // 100 // 5 * 5]
    return [price, price]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'density': 37, 'prev_price': 650, 'bands': [[13, 475], [36, 650], [37, 800], [42, 1000]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 70}, [750, 0]), ({'density': 19, 'prev_price': 625, 'bands': [[13, 125], [19, 725], [23, 750], [36, 925]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 50}, [675, 335]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 21, 'prev_price': 1250, 'bands': [[18, 225], [21, 250], [22, 350], [43, 525]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [800, 800]), ({'density': 44, 'prev_price': 1200, 'bands': [[19, 450], [40, 525], [41, 650], [44, 925]], 'max_step': 50, 'min_price': 50, 'max_price': 1200, 'occupancy': 4, 'hov_free_min': 3, 'hov2_pct': 50}, [1150, 0]), ({'density': 11, 'prev_price': 1250, 'bands': [[11, 275], [17, 500], [21, 700], [44, 825]], 'max_step': 50, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [800, 800])], [({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 19, 'prev_price': 1250, 'bands': [[19, 275], [23, 475], [24, 575], [38, 825]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 0]), ({'density': 23, 'prev_price': 0, 'bands': [[13, 175], [19, 475], [23, 700], [29, 850]], 'max_step': 25, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 4, 'hov2_pct': 50}, [50, 50]), ({'density': 35, 'prev_price': 700, 'bands': [[23, 150], [33, 450], [38, 725], [41, 950]], 'max_step': 25, 'min_price': 50, 'max_price': 1200, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 50}, [725, 360]), ({'density': 17, 'prev_price': 625, 'bands': [[17, 300], [28, 500], [30, 700], [36, 925]], 'max_step': 25, 'min_price': 50, 'max_price': 800, 'occupancy': 3, 'hov_free_min': 4, 'hov2_pct': 70}, [600, 600]), ({'density': 3, 'prev_price': 250, 'bands': [[15, 425], [20, 600], [24, 775], [27, 975]], 'max_step': 50, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 4, 'hov2_pct': 50}, [300, 300])], [({'density': 42, 'prev_price': 0, 'bands': [[14, 225], [16, 675], [30, 775], [42, 925]], 'max_step': 25, 'min_price': 50, 'max_price': 1200, 'occupancy': 4, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 0]), ({'density': 10, 'prev_price': 225, 'bands': [[10, 75], [16, 300], [36, 725], [44, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [200, 200]), ({'density': 16, 'prev_price': 1200, 'bands': [[13, 50], [16, 450], [17, 725], [39, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1200, 'occupancy': 1, 'hov_free_min': 2, 'hov2_pct': 70}, [1175, 1175]), ({'density': 34, 'prev_price': 1175, 'bands': [[16, 225], [27, 325], [39, 400], [40, 475]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [1000, 1000]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 22, 'prev_price': 500, 'bands': [[10, 350], [19, 425], [22, 450], [24, 650]], 'max_step': 100, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 4, 'hov2_pct': 50}, [450, 450]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50])], [({'density': 18, 'prev_price': 850, 'bands': [[18, 100], [20, 175], [35, 250], [44, 800]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 50}, [825, 0]), ({'density': 16, 'prev_price': 25, 'bands': [[16, 50], [23, 350], [26, 700], [36, 725]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 4, 'hov_free_min': 4, 'hov2_pct': 70}, [50, 0]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 49, 'prev_price': 0, 'bands': [[12, 350], [33, 475], [34, 500], [41, 800]], 'max_step': 25, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [50, 50]), ({'density': 19, 'prev_price': 250, 'bands': [[19, 275], [31, 450], [37, 675], [40, 700]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 50}, [275, 135]), ({'density': 35, 'prev_price': 1300, 'bands': [[31, 175], [38, 200], [40, 400], [42, 800]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 3, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 0]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245])], [({'density': 14, 'prev_price': 925, 'bands': [[10, 150], [12, 525], [14, 750], [40, 850]], 'max_step': 25, 'min_price': 50, 'max_price': 800, 'occupancy': 1, 'hov_free_min': 2, 'hov2_pct': 70}, [800, 800]), ({'density': 34, 'prev_price': 0, 'bands': [[27, 450], [29, 525], [34, 550], [42, 950]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 4, 'hov2_pct': 50}, [50, 50]), ({'density': 25, 'prev_price': 0, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 50}, [50, 50]), ({'density': 34, 'prev_price': 250, 'bands': [[16, 325], [33, 400], [34, 475], [38, 1000]], 'max_step': 100, 'min_price': 50, 'max_price': 1200, 'occupancy': 3, 'hov_free_min': 2, 'hov2_pct': 50}, [350, 0]), ({'density': 45, 'prev_price': 1100, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 1, 'hov_free_min': 3, 'hov2_pct': 70}, [1000, 1000]), ({'density': 37, 'prev_price': 850, 'bands': [[22, 525], [30, 800], [37, 825], [44, 975]], 'max_step': 25, 'min_price': 50, 'max_price': 1000, 'occupancy': 4, 'hov_free_min': 2, 'hov2_pct': 70}, [825, 0]), ({'density': 20, 'prev_price': 300, 'bands': [[12, 100], [20, 400], [30, 700], [40, 900]], 'max_step': 50, 'min_price': 50, 'max_price': 1000, 'occupancy': 2, 'hov_free_min': 3, 'hov2_pct': 70}, [350, 245]), ({'density': 41, 'prev_price': 350, 'bands': [[29, 225], [33, 525], [41, 575], [44, 625]], 'max_step': 50, 'min_price': 50, 'max_price': 1200, 'occupancy': 4, 'hov_free_min': 4, 'hov2_pct': 50}, [400, 0])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Express lane dynamic price returns a wrong result when the posted price is not floored at the minimum.

Input {density, prev_price, bands: [[density upto, price]] ascending, max_step, min_price, max_price, occupancy, hov_free_min, hov2_pct}. The target is the first band whose upto is >= density, else max_price. The posted price moves from prev_price toward the target by at most max_step either way, then is clamped to [min_price, max_price]. Vehicles with occupancy >= hov_free_min pay 0; occupancy 2 (when not free) pays hov2_pct percent floored to 5 cents. Return [posted, charged].

split: open-access