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

N = 1
observations = []
def solve(x):
    bal = x['balance']
    n = 0
    first = None
    amt = min(x['min_replenish'], -(-x['usage_30d'] // 2000) * 500)
    for i, c in enumerate(x['charges']):
        bal -= c
        if bal < x['threshold'] and x['card_ok']:
            bal += amt
            n += 1
        if bal < 0 and first is None:
            first = i
    return {'balance': bal, 'replenished': n, 'first_negative': first}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1707, 'charges': [1200, 275, 1200, 3000, 400, 650, 1200, 400], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 8158, 'card_ok': True}, {'balance': 882, 'replenished': 3, 'first_negative': None}), ({'balance': 3418, 'charges': [1200, 650], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 8208, 'card_ok': True}, {'balance': 1568, 'replenished': 0, 'first_negative': None}), ({'balance': 2115, 'charges': [275, 650], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9524, 'card_ok': True}, {'balance': 1190, 'replenished': 0, 'first_negative': None}), ({'balance': -378, 'charges': [150, 650], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 3777, 'card_ok': True}, {'balance': 2822, 'replenished': 2, 'first_negative': None}), ({'balance': 2921, 'charges': [650, 400, 3000, 650, 275], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 6113, 'card_ok': True}, {'balance': 1946, 'replenished': 2, 'first_negative': None})], [({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 3451, 'charges': [275, 150, 3000, 275, 3000, 275, 275], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 5768, 'card_ok': False}, {'balance': -3799, 'replenished': 0, 'first_negative': 3}), ({'balance': 1654, 'charges': [3000, 275, 150, 150, 275, 3000, 150, 3000], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 17737, 'card_ok': False}, {'balance': -8346, 'replenished': 0, 'first_negative': 0}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 245, 'charges': [400], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 19631, 'card_ok': True}, {'balance': 4845, 'replenished': 1, 'first_negative': None}), ({'balance': 586, 'charges': [275, 1200, 150, 1200], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 10288, 'card_ok': True}, {'balance': 3761, 'replenished': 2, 'first_negative': None}), ({'balance': 3891, 'charges': [400, 400, 3000], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 4479, 'card_ok': True}, {'balance': 1591, 'replenished': 1, 'first_negative': None})], [({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2953, 'charges': [150, 275, 400, 3000, 275], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 2114, 'card_ok': False}, {'balance': -1147, 'replenished': 0, 'first_negative': 3}), ({'balance': 1665, 'charges': [275, 1200, 650, 150, 400, 650, 1200, 400], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 4211, 'card_ok': True}, {'balance': 1740, 'replenished': 2, 'first_negative': None}), ({'balance': 2509, 'charges': [275], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 14637, 'card_ok': True}, {'balance': 2234, 'replenished': 0, 'first_negative': None}), ({'balance': 3938, 'charges': [150, 1200], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 160, 'card_ok': True}, {'balance': 2588, 'replenished': 0, 'first_negative': None}), ({'balance': 1796, 'charges': [650, 400, 1200, 150, 3000, 150, 275, 1200], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 17989, 'card_ok': True}, {'balance': 3771, 'replenished': 2, 'first_negative': None})], [({'balance': 2033, 'charges': [3000, 650, 1200, 275, 3000, 3000, 650, 400], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 18614, 'card_ok': True}, {'balance': 4858, 'replenished': 3, 'first_negative': None}), ({'balance': 2484, 'charges': [650, 150, 1200, 1200, 400, 150, 650, 150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 18653, 'card_ok': False}, {'balance': -2066, 'replenished': 0, 'first_negative': 3}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 2629, 'charges': [3000, 275, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 12751, 'card_ok': True}, {'balance': 2704, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 3615, 'charges': [650, 400, 1200, 150, 650], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 16149, 'card_ok': True}, {'balance': 5065, 'replenished': 1, 'first_negative': None}), ({'balance': 725, 'charges': [150, 1200, 3000, 275], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 12916, 'card_ok': False}, {'balance': -3900, 'replenished': 0, 'first_negative': 1}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None})], [({'balance': 1270, 'charges': [1200, 150, 3000, 400, 650, 150, 650, 1200], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 16340, 'card_ok': False}, {'balance': -6130, 'replenished': 0, 'first_negative': 1}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 3058, 'charges': [150, 1200, 275, 1200], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 19841, 'card_ok': True}, {'balance': 5233, 'replenished': 1, 'first_negative': None}), ({'balance': 2750, 'charges': [275, 150, 400, 3000, 150], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 6142, 'card_ok': True}, {'balance': 2775, 'replenished': 2, 'first_negative': None}), ({'balance': 1212, 'charges': [275, 400, 400], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 9849, 'card_ok': False}, {'balance': 137, 'replenished': 0, 'first_negative': None}), ({'balance': 1525, 'charges': [275, 1200, 650, 400, 1200, 3000], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 8087, 'card_ok': True}, {'balance': 2300, 'replenished': 3, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None})]]
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):
    bal = x['balance']
    n = 0
    first = None
    amt = (x['min_replenish'] + -(-x['usage_30d'] // 2000) * 500)
    for i, c in enumerate(x['charges']):
        bal -= c
        if bal < x['threshold'] and x['card_ok']:
            bal += amt
            n += 1
        if bal < 0 and first is None:
            first = i
    return {'balance': bal, 'replenished': n, 'first_negative': first}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1707, 'charges': [1200, 275, 1200, 3000, 400, 650, 1200, 400], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 8158, 'card_ok': True}, {'balance': 882, 'replenished': 3, 'first_negative': None}), ({'balance': 3418, 'charges': [1200, 650], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 8208, 'card_ok': True}, {'balance': 1568, 'replenished': 0, 'first_negative': None}), ({'balance': 2115, 'charges': [275, 650], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9524, 'card_ok': True}, {'balance': 1190, 'replenished': 0, 'first_negative': None}), ({'balance': -378, 'charges': [150, 650], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 3777, 'card_ok': True}, {'balance': 2822, 'replenished': 2, 'first_negative': None}), ({'balance': 2921, 'charges': [650, 400, 3000, 650, 275], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 6113, 'card_ok': True}, {'balance': 1946, 'replenished': 2, 'first_negative': None})], [({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 3451, 'charges': [275, 150, 3000, 275, 3000, 275, 275], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 5768, 'card_ok': False}, {'balance': -3799, 'replenished': 0, 'first_negative': 3}), ({'balance': 1654, 'charges': [3000, 275, 150, 150, 275, 3000, 150, 3000], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 17737, 'card_ok': False}, {'balance': -8346, 'replenished': 0, 'first_negative': 0}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 245, 'charges': [400], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 19631, 'card_ok': True}, {'balance': 4845, 'replenished': 1, 'first_negative': None}), ({'balance': 586, 'charges': [275, 1200, 150, 1200], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 10288, 'card_ok': True}, {'balance': 3761, 'replenished': 2, 'first_negative': None}), ({'balance': 3891, 'charges': [400, 400, 3000], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 4479, 'card_ok': True}, {'balance': 1591, 'replenished': 1, 'first_negative': None})], [({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2953, 'charges': [150, 275, 400, 3000, 275], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 2114, 'card_ok': False}, {'balance': -1147, 'replenished': 0, 'first_negative': 3}), ({'balance': 1665, 'charges': [275, 1200, 650, 150, 400, 650, 1200, 400], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 4211, 'card_ok': True}, {'balance': 1740, 'replenished': 2, 'first_negative': None}), ({'balance': 2509, 'charges': [275], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 14637, 'card_ok': True}, {'balance': 2234, 'replenished': 0, 'first_negative': None}), ({'balance': 3938, 'charges': [150, 1200], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 160, 'card_ok': True}, {'balance': 2588, 'replenished': 0, 'first_negative': None}), ({'balance': 1796, 'charges': [650, 400, 1200, 150, 3000, 150, 275, 1200], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 17989, 'card_ok': True}, {'balance': 3771, 'replenished': 2, 'first_negative': None})], [({'balance': 2033, 'charges': [3000, 650, 1200, 275, 3000, 3000, 650, 400], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 18614, 'card_ok': True}, {'balance': 4858, 'replenished': 3, 'first_negative': None}), ({'balance': 2484, 'charges': [650, 150, 1200, 1200, 400, 150, 650, 150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 18653, 'card_ok': False}, {'balance': -2066, 'replenished': 0, 'first_negative': 3}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 2629, 'charges': [3000, 275, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 12751, 'card_ok': True}, {'balance': 2704, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 3615, 'charges': [650, 400, 1200, 150, 650], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 16149, 'card_ok': True}, {'balance': 5065, 'replenished': 1, 'first_negative': None}), ({'balance': 725, 'charges': [150, 1200, 3000, 275], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 12916, 'card_ok': False}, {'balance': -3900, 'replenished': 0, 'first_negative': 1}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None})], [({'balance': 1270, 'charges': [1200, 150, 3000, 400, 650, 150, 650, 1200], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 16340, 'card_ok': False}, {'balance': -6130, 'replenished': 0, 'first_negative': 1}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 3058, 'charges': [150, 1200, 275, 1200], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 19841, 'card_ok': True}, {'balance': 5233, 'replenished': 1, 'first_negative': None}), ({'balance': 2750, 'charges': [275, 150, 400, 3000, 150], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 6142, 'card_ok': True}, {'balance': 2775, 'replenished': 2, 'first_negative': None}), ({'balance': 1212, 'charges': [275, 400, 400], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 9849, 'card_ok': False}, {'balance': 137, 'replenished': 0, 'first_negative': None}), ({'balance': 1525, 'charges': [275, 1200, 650, 400, 1200, 3000], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 8087, 'card_ok': True}, {'balance': 2300, 'replenished': 3, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None})]]
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:
Prepaid toll account auto-replenishment returns a wrong result when the minimum replenishment acts as a ceiling.

Input {balance, charges, threshold, min_replenish, usage_30d, card_ok}. The replenish amount is max(min_replenish, ceil(usage_30d/4) rounded up to a multiple of 500). After each charge, if the balance is strictly below threshold and the card works, one replenishment is added. first_negative is the index of the first charge after which the balance is negative (or null). Return {balance, replenished, first_negative}.

split: open-access


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

N = 1
observations = []
def solve(x):
    bal = x['balance']
    n = 0
    first = None
    amt = max(x['min_replenish'], -(-x['usage_30d'] // 2000) * 500)
    for i, c in enumerate(x['charges']):
        bal -= c
        if bal < x['threshold'] and x['card_ok']:
            bal += amt
            n += 1
        if bal < 0:
            first = i
    return {'balance': bal, 'replenished': n, 'first_negative': first}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'balance': 1322, 'charges': [650], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 18596, 'card_ok': True}, {'balance': 5672, 'replenished': 1, 'first_negative': None}), ({'balance': 994, 'charges': [3000, 400, 3000, 650, 3000, 3000, 275], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 16149, 'card_ok': True}, {'balance': 1169, 'replenished': 3, 'first_negative': None}), ({'balance': 921, 'charges': [1200, 650, 650, 150, 1200, 400, 1200, 150], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 11909, 'card_ok': False}, {'balance': -4679, 'replenished': 0, 'first_negative': 0}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 3320, 'charges': [3000, 3000, 3000, 400, 3000], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 7303, 'card_ok': False}, {'balance': -9080, 'replenished': 0, 'first_negative': 1}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 2429, 'charges': [275, 150, 275, 150, 150, 400, 1200], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 6810, 'card_ok': True}, {'balance': 2329, 'replenished': 1, 'first_negative': None})], [({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 753, 'charges': [650, 3000], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 2408, 'card_ok': False}, {'balance': -2897, 'replenished': 0, 'first_negative': 1}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 1987, 'charges': [275, 1200, 150, 400], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 17952, 'card_ok': True}, {'balance': 4462, 'replenished': 1, 'first_negative': None}), ({'balance': 3568, 'charges': [150, 1200, 150, 3000, 275, 650], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 16196, 'card_ok': False}, {'balance': -1857, 'replenished': 0, 'first_negative': 3}), ({'balance': 616, 'charges': [1200, 275, 275, 650, 275], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 5115, 'card_ok': False}, {'balance': -2059, 'replenished': 0, 'first_negative': 0}), ({'balance': 1428, 'charges': [275, 3000, 1200, 650, 3000, 3000, 1200], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 12671, 'card_ok': True}, {'balance': 3103, 'replenished': 4, 'first_negative': None})], [({'balance': 390, 'charges': [400, 1200], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 1137, 'card_ok': False}, {'balance': -1210, 'replenished': 0, 'first_negative': 0}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 1694, 'charges': [275, 1200, 275, 275, 650], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 904, 'card_ok': False}, {'balance': -981, 'replenished': 0, 'first_negative': 2}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 2427, 'charges': [400, 400, 400, 3000, 650], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 2179, 'card_ok': True}, {'balance': -423, 'replenished': 2, 'first_negative': 3}), ({'balance': 1802, 'charges': [650], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 19640, 'card_ok': True}, {'balance': 1152, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 155, 'charges': [400, 650, 275, 650], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 2650, 'card_ok': True}, {'balance': 3180, 'replenished': 2, 'first_negative': None})], [({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 1910, 'charges': [275, 400, 3000, 1200, 400], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 12496, 'card_ok': True}, {'balance': 3635, 'replenished': 2, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2190, 'charges': [275], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 15361, 'card_ok': True}, {'balance': 1915, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 3344, 'charges': [650, 3000, 1200, 1200, 3000], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 104, 'card_ok': True}, {'balance': -1706, 'replenished': 4, 'first_negative': 4}), ({'balance': -397, 'charges': [1200, 1200, 400, 1200, 1200, 275, 150], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 452, 'card_ok': False}, {'balance': -6022, 'replenished': 0, 'first_negative': 0}), ({'balance': 2655, 'charges': [650, 3000, 275], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 9407, 'card_ok': False}, {'balance': -1270, 'replenished': 0, 'first_negative': 1})], [({'balance': 2215, 'charges': [3000, 150, 275], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 16466, 'card_ok': False}, {'balance': -1210, 'replenished': 0, 'first_negative': 0}), ({'balance': 261, 'charges': [3000, 1200, 1200], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 11452, 'card_ok': True}, {'balance': 861, 'replenished': 2, 'first_negative': None}), ({'balance': -14, 'charges': [1200, 275, 400, 650, 650, 650], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 6151, 'card_ok': True}, {'balance': 2161, 'replenished': 3, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 3175, 'charges': [1200, 650, 400, 650, 275, 400, 3000], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 15568, 'card_ok': False}, {'balance': -3400, 'replenished': 0, 'first_negative': 5}), ({'balance': -156, 'charges': [275, 1200], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 11597, 'card_ok': False}, {'balance': -1631, 'replenished': 0, 'first_negative': 0}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 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)

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):
    bal = x['balance']
    n = 0
    first = None
    amt = max(x['min_replenish'], -(-x['usage_30d'] // 2000) * 500)
    for i, c in enumerate(x['charges']):
        bal -= c
        if bal < x['threshold'] and x['card_ok']:
            bal += amt
            n += 1
        if bal <= 0 and first is None:
            first = i
    return {'balance': bal, 'replenished': n, 'first_negative': first}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'balance': 1322, 'charges': [650], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 18596, 'card_ok': True}, {'balance': 5672, 'replenished': 1, 'first_negative': None}), ({'balance': 994, 'charges': [3000, 400, 3000, 650, 3000, 3000, 275], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 16149, 'card_ok': True}, {'balance': 1169, 'replenished': 3, 'first_negative': None}), ({'balance': 921, 'charges': [1200, 650, 650, 150, 1200, 400, 1200, 150], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 11909, 'card_ok': False}, {'balance': -4679, 'replenished': 0, 'first_negative': 0}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 3320, 'charges': [3000, 3000, 3000, 400, 3000], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 7303, 'card_ok': False}, {'balance': -9080, 'replenished': 0, 'first_negative': 1}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 2429, 'charges': [275, 150, 275, 150, 150, 400, 1200], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 6810, 'card_ok': True}, {'balance': 2329, 'replenished': 1, 'first_negative': None})], [({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 753, 'charges': [650, 3000], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 2408, 'card_ok': False}, {'balance': -2897, 'replenished': 0, 'first_negative': 1}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 1987, 'charges': [275, 1200, 150, 400], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 17952, 'card_ok': True}, {'balance': 4462, 'replenished': 1, 'first_negative': None}), ({'balance': 3568, 'charges': [150, 1200, 150, 3000, 275, 650], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 16196, 'card_ok': False}, {'balance': -1857, 'replenished': 0, 'first_negative': 3}), ({'balance': 616, 'charges': [1200, 275, 275, 650, 275], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 5115, 'card_ok': False}, {'balance': -2059, 'replenished': 0, 'first_negative': 0}), ({'balance': 1428, 'charges': [275, 3000, 1200, 650, 3000, 3000, 1200], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 12671, 'card_ok': True}, {'balance': 3103, 'replenished': 4, 'first_negative': None})], [({'balance': 390, 'charges': [400, 1200], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 1137, 'card_ok': False}, {'balance': -1210, 'replenished': 0, 'first_negative': 0}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 1694, 'charges': [275, 1200, 275, 275, 650], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 904, 'card_ok': False}, {'balance': -981, 'replenished': 0, 'first_negative': 2}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 2427, 'charges': [400, 400, 400, 3000, 650], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 2179, 'card_ok': True}, {'balance': -423, 'replenished': 2, 'first_negative': 3}), ({'balance': 1802, 'charges': [650], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 19640, 'card_ok': True}, {'balance': 1152, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 155, 'charges': [400, 650, 275, 650], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 2650, 'card_ok': True}, {'balance': 3180, 'replenished': 2, 'first_negative': None})], [({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 1910, 'charges': [275, 400, 3000, 1200, 400], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 12496, 'card_ok': True}, {'balance': 3635, 'replenished': 2, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2190, 'charges': [275], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 15361, 'card_ok': True}, {'balance': 1915, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 3344, 'charges': [650, 3000, 1200, 1200, 3000], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 104, 'card_ok': True}, {'balance': -1706, 'replenished': 4, 'first_negative': 4}), ({'balance': -397, 'charges': [1200, 1200, 400, 1200, 1200, 275, 150], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 452, 'card_ok': False}, {'balance': -6022, 'replenished': 0, 'first_negative': 0}), ({'balance': 2655, 'charges': [650, 3000, 275], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 9407, 'card_ok': False}, {'balance': -1270, 'replenished': 0, 'first_negative': 1})], [({'balance': 2215, 'charges': [3000, 150, 275], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 16466, 'card_ok': False}, {'balance': -1210, 'replenished': 0, 'first_negative': 0}), ({'balance': 261, 'charges': [3000, 1200, 1200], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 11452, 'card_ok': True}, {'balance': 861, 'replenished': 2, 'first_negative': None}), ({'balance': -14, 'charges': [1200, 275, 400, 650, 650, 650], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 6151, 'card_ok': True}, {'balance': 2161, 'replenished': 3, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 3175, 'charges': [1200, 650, 400, 650, 275, 400, 3000], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 15568, 'card_ok': False}, {'balance': -3400, 'replenished': 0, 'first_negative': 5}), ({'balance': -156, 'charges': [275, 1200], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 11597, 'card_ok': False}, {'balance': -1631, 'replenished': 0, 'first_negative': 0}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 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:
Prepaid toll account auto-replenishment returns a wrong result when the negative index is overwritten by later charges.

Input {balance, charges, threshold, min_replenish, usage_30d, card_ok}. The replenish amount is max(min_replenish, ceil(usage_30d/4) rounded up to a multiple of 500). After each charge, if the balance is strictly below threshold and the card works, one replenishment is added. first_negative is the index of the first charge after which the balance is negative (or null). Return {balance, replenished, first_negative}.

split: open-access


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

N = 1
observations = []
def solve(x):
    bal = x['balance']
    n = 0
    first = None
    amt = max(x['min_replenish'], -(-x['usage_30d'] // 2000) * 500)
    for i, c in enumerate(x['charges']):
        bal -= c
        if bal < x['threshold'] :
            bal += amt
            n += 1
        if bal < 0 and first is None:
            first = i
    return {'balance': bal, 'replenished': n, 'first_negative': first}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 1042, 'charges': [150, 400, 400, 275, 1200, 400, 1200, 650], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 3603, 'card_ok': False}, {'balance': -3633, 'replenished': 0, 'first_negative': 3}), ({'balance': 3098, 'charges': [275], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 8704, 'card_ok': True}, {'balance': 2823, 'replenished': 0, 'first_negative': None}), ({'balance': 2083, 'charges': [400, 3000, 1200, 150, 3000, 150, 275, 400], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 15358, 'card_ok': True}, {'balance': 1508, 'replenished': 2, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2570, 'charges': [1200, 150], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 14152, 'card_ok': True}, {'balance': 1220, 'replenished': 0, 'first_negative': None}), ({'balance': -415, 'charges': [3000, 400, 150, 400, 3000, 650, 650, 275], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 13000, 'card_ok': False}, {'balance': -8940, 'replenished': 0, 'first_negative': 0})], [({'balance': 960, 'charges': [150, 400], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 1855, 'card_ok': True}, {'balance': 2410, 'replenished': 1, 'first_negative': None}), ({'balance': 2103, 'charges': [400, 275, 1200, 3000], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 12226, 'card_ok': False}, {'balance': -2772, 'replenished': 0, 'first_negative': 3}), ({'balance': 2015, 'charges': [150], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 308, 'card_ok': True}, {'balance': 1865, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 2113, 'charges': [650, 3000, 400, 650, 1200, 400], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 3260, 'card_ok': False}, {'balance': -4187, 'replenished': 0, 'first_negative': 1}), ({'balance': 3967, 'charges': [150, 275, 3000, 1200, 1200, 275], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 8777, 'card_ok': True}, {'balance': 2867, 'replenished': 2, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None})], [({'balance': 397, 'charges': [400, 3000, 650], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 3118, 'card_ok': False}, {'balance': -3653, 'replenished': 0, 'first_negative': 0}), ({'balance': 173, 'charges': [1200, 400, 3000, 150], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 12679, 'card_ok': True}, {'balance': 2423, 'replenished': 2, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 3708, 'charges': [1200, 1200, 650, 1200, 650], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 11407, 'card_ok': True}, {'balance': 1808, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2856, 'charges': [150, 150, 1200, 150], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 8265, 'card_ok': True}, {'balance': 1206, 'replenished': 0, 'first_negative': None}), ({'balance': 2101, 'charges': [650, 150, 400, 1200, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 2791, 'card_ok': False}, {'balance': -574, 'replenished': 0, 'first_negative': 3})], [({'balance': 581, 'charges': [150, 3000, 400, 400], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 6330, 'card_ok': False}, {'balance': -3369, 'replenished': 0, 'first_negative': 1}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 30, 'charges': [150, 275, 400, 3000, 650], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 6576, 'card_ok': True}, {'balance': 3055, 'replenished': 3, 'first_negative': None}), ({'balance': 1352, 'charges': [1200], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 18621, 'card_ok': True}, {'balance': 5152, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2093, 'charges': [1200, 400], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 228, 'card_ok': False}, {'balance': 493, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 2533, 'charges': [150, 650, 150, 400, 3000, 150, 3000], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 11845, 'card_ok': True}, {'balance': 4033, 'replenished': 3, 'first_negative': None})], [({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 3426, 'charges': [1200, 400], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 13777, 'card_ok': True}, {'balance': 1826, 'replenished': 0, 'first_negative': None}), ({'balance': 841, 'charges': [1200, 150], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 6647, 'card_ok': True}, {'balance': 1491, 'replenished': 1, 'first_negative': None}), ({'balance': 2207, 'charges': [3000, 3000, 1200, 275], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 3869, 'card_ok': True}, {'balance': 2232, 'replenished': 3, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1085, 'charges': [150, 3000, 275, 650, 275, 150, 275, 3000], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 2619, 'card_ok': False}, {'balance': -6690, 'replenished': 0, 'first_negative': 1}), ({'balance': -472, 'charges': [1200, 3000, 275, 650], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 16057, 'card_ok': False}, {'balance': -5597, 'replenished': 0, 'first_negative': 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):
    bal = x['balance']
    n = 0
    first = None
    amt = max(x['min_replenish'], -(-x['usage_30d'] // 2000) * 500)
    for i, c in enumerate(x['charges']):
        bal -= c
        if bal < x['threshold'] and (x['card_ok'] or n == 0):
            bal += amt
            n += 1
        if bal < 0 and first is None:
            first = i
    return {'balance': bal, 'replenished': n, 'first_negative': first}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 1042, 'charges': [150, 400, 400, 275, 1200, 400, 1200, 650], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 3603, 'card_ok': False}, {'balance': -3633, 'replenished': 0, 'first_negative': 3}), ({'balance': 3098, 'charges': [275], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 8704, 'card_ok': True}, {'balance': 2823, 'replenished': 0, 'first_negative': None}), ({'balance': 2083, 'charges': [400, 3000, 1200, 150, 3000, 150, 275, 400], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 15358, 'card_ok': True}, {'balance': 1508, 'replenished': 2, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2570, 'charges': [1200, 150], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 14152, 'card_ok': True}, {'balance': 1220, 'replenished': 0, 'first_negative': None}), ({'balance': -415, 'charges': [3000, 400, 150, 400, 3000, 650, 650, 275], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 13000, 'card_ok': False}, {'balance': -8940, 'replenished': 0, 'first_negative': 0})], [({'balance': 960, 'charges': [150, 400], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 1855, 'card_ok': True}, {'balance': 2410, 'replenished': 1, 'first_negative': None}), ({'balance': 2103, 'charges': [400, 275, 1200, 3000], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 12226, 'card_ok': False}, {'balance': -2772, 'replenished': 0, 'first_negative': 3}), ({'balance': 2015, 'charges': [150], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 308, 'card_ok': True}, {'balance': 1865, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 2113, 'charges': [650, 3000, 400, 650, 1200, 400], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 3260, 'card_ok': False}, {'balance': -4187, 'replenished': 0, 'first_negative': 1}), ({'balance': 3967, 'charges': [150, 275, 3000, 1200, 1200, 275], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 8777, 'card_ok': True}, {'balance': 2867, 'replenished': 2, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None})], [({'balance': 397, 'charges': [400, 3000, 650], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 3118, 'card_ok': False}, {'balance': -3653, 'replenished': 0, 'first_negative': 0}), ({'balance': 173, 'charges': [1200, 400, 3000, 150], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 12679, 'card_ok': True}, {'balance': 2423, 'replenished': 2, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 3708, 'charges': [1200, 1200, 650, 1200, 650], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 11407, 'card_ok': True}, {'balance': 1808, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2856, 'charges': [150, 150, 1200, 150], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 8265, 'card_ok': True}, {'balance': 1206, 'replenished': 0, 'first_negative': None}), ({'balance': 2101, 'charges': [650, 150, 400, 1200, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 2791, 'card_ok': False}, {'balance': -574, 'replenished': 0, 'first_negative': 3})], [({'balance': 581, 'charges': [150, 3000, 400, 400], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 6330, 'card_ok': False}, {'balance': -3369, 'replenished': 0, 'first_negative': 1}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 30, 'charges': [150, 275, 400, 3000, 650], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 6576, 'card_ok': True}, {'balance': 3055, 'replenished': 3, 'first_negative': None}), ({'balance': 1352, 'charges': [1200], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 18621, 'card_ok': True}, {'balance': 5152, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2093, 'charges': [1200, 400], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 228, 'card_ok': False}, {'balance': 493, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 2533, 'charges': [150, 650, 150, 400, 3000, 150, 3000], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 11845, 'card_ok': True}, {'balance': 4033, 'replenished': 3, 'first_negative': None})], [({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 3426, 'charges': [1200, 400], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 13777, 'card_ok': True}, {'balance': 1826, 'replenished': 0, 'first_negative': None}), ({'balance': 841, 'charges': [1200, 150], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 6647, 'card_ok': True}, {'balance': 1491, 'replenished': 1, 'first_negative': None}), ({'balance': 2207, 'charges': [3000, 3000, 1200, 275], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 3869, 'card_ok': True}, {'balance': 2232, 'replenished': 3, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1085, 'charges': [150, 3000, 275, 650, 275, 150, 275, 3000], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 2619, 'card_ok': False}, {'balance': -6690, 'replenished': 0, 'first_negative': 1}), ({'balance': -472, 'charges': [1200, 3000, 275, 650], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 16057, 'card_ok': False}, {'balance': -5597, 'replenished': 0, 'first_negative': 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:
Prepaid toll account auto-replenishment returns a wrong result when replenishment is attempted with a declined card.

Input {balance, charges, threshold, min_replenish, usage_30d, card_ok}. The replenish amount is max(min_replenish, ceil(usage_30d/4) rounded up to a multiple of 500). After each charge, if the balance is strictly below threshold and the card works, one replenishment is added. first_negative is the index of the first charge after which the balance is negative (or null). Return {balance, replenished, first_negative}.

split: open-access


prompt:
One-way bridge toll with frequent-user discount returns a wrong result when the tolled direction is hard-coded westbound.

Input {trips: [[month index, direction, occupancy]], toll_dir, base, threshold, discount_pct, carpool_min}. Only trips in toll_dir are tolled. Carpools (occupancy >= carpool_min) are free and do not count. Paid trips are counted per month index (no carry-over between months); trips beyond threshold in a month pay floor(base*(100-discount)/100).

split: open-access


prompt:
One-way bridge toll with frequent-user discount returns a wrong result when carpools of exactly the minimum occupancy are charged.

Input {trips: [[month index, direction, occupancy]], toll_dir, base, threshold, discount_pct, carpool_min}. Only trips in toll_dir are tolled. Carpools (occupancy >= carpool_min) are free and do not count. Paid trips are counted per month index (no carry-over between months); trips beyond threshold in a month pay floor(base*(100-discount)/100).

split: open-access


prompt:
One-way bridge toll with frequent-user discount returns a wrong result when the frequency counter never resets between months.

Input {trips: [[month index, direction, occupancy]], toll_dir, base, threshold, discount_pct, carpool_min}. Only trips in toll_dir are tolled. Carpools (occupancy >= carpool_min) are free and do not count. Paid trips are counted per month index (no carry-over between months); trips beyond threshold in a month pay floor(base*(100-discount)/100).

split: open-access


prompt:
One-way bridge toll with frequent-user discount returns a wrong result when the threshold trip itself is discounted.

Input {trips: [[month index, direction, occupancy]], toll_dir, base, threshold, discount_pct, carpool_min}. Only trips in toll_dir are tolled. Carpools (occupancy >= carpool_min) are free and do not count. Paid trips are counted per month index (no carry-over between months); trips beyond threshold in a month pay floor(base*(100-discount)/100).

split: open-access


prompt:
One-way bridge toll with frequent-user discount returns a wrong result when the discounted price is rounded to nearest.

Input {trips: [[month index, direction, occupancy]], toll_dir, base, threshold, discount_pct, carpool_min}. Only trips in toll_dir are tolled. Carpools (occupancy >= carpool_min) are free and do not count. Paid trips are counted per month index (no carry-over between months); trips beyond threshold in a month pay floor(base*(100-discount)/100).

split: open-access


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

N = 1
observations = []
def solve(x):
    free = sum(min(v, x['max_free_min']) for k, v in x['validations'] if k == 'free_min')
    bill = max(0, x['minutes'] - free)
    fee = min(x['daily_max'], -(-bill // 60) * x['hourly'])
    pcts = [v for k, v in x['validations'] if k == 'pct']
    if pcts:
        fee -= fee * max(pcts) // 100
    flat = sum(v for k, v in x['validations'] if k == 'flat')
    return max(0, fee - flat)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 242, 'validations': [['free_min', 60], ['free_min', 15]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 60}, 800), ({'minutes': 405, 'validations': [['free_min', 90], ['free_min', 15], ['free_min', 60], ['pct', 25]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 60}, 1350), ({'minutes': 1305, 'validations': [['free_min', 30], ['free_min', 15], ['pct', 25]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 180}, 1800), ({'minutes': 527, 'validations': [['flat', 250]], 'hourly': 200, 'daily_max': 3000, 'max_free_min': 60}, 1550), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 850, 'validations': [['pct', 10], ['free_min', 60], ['free_min', 30], ['flat', 250]], 'hourly': 200, 'daily_max': 3000, 'max_free_min': 180}, 2090)], [({'minutes': 761, 'validations': [['free_min', 120], ['free_min', 120], ['free_min', 60]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 120}, 1800), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 967, 'validations': [['free_min', 120]], 'hourly': 300, 'daily_max': 3000, 'max_free_min': 60}, 3000), ({'minutes': 212, 'validations': [['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 60}, 900), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 203, 'validations': [['free_min', 120], ['flat', 250], ['pct', 10], ['free_min', 120]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 180}, 20), ({'minutes': 999, 'validations': [['free_min', 120], ['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 2400)], [({'minutes': 188, 'validations': [['free_min', 120], ['free_min', 30]], 'hourly': 200, 'daily_max': 3000, 'max_free_min': 60}, 600), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 583, 'validations': [], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 60}, 1800), ({'minutes': 598, 'validations': [['flat', 100]], 'hourly': 350, 'daily_max': 3000, 'max_free_min': 120}, 2900), ({'minutes': 72, 'validations': [['free_min', 15], ['flat', 250], ['free_min', 60], ['free_min', 30]], 'hourly': 300, 'daily_max': 1800, 'max_free_min': 60}, 50), ({'minutes': 282, 'validations': [['pct', 10], ['free_min', 30], ['free_min', 30]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 120}, 720)], [({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 431, 'validations': [], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 60}, 1600), ({'minutes': 580, 'validations': [['flat', 500], ['free_min', 60], ['pct', 50]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 60}, 400), ({'minutes': 1309, 'validations': [['free_min', 30], ['pct', 10], ['pct', 25]], 'hourly': 200, 'daily_max': 3000, 'max_free_min': 120}, 2250), ({'minutes': 596, 'validations': [['pct', 10], ['free_min', 90], ['free_min', 120], ['free_min', 90]], 'hourly': 350, 'daily_max': 3000, 'max_free_min': 60}, 2700), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 361, 'validations': [['free_min', 120], ['pct', 50], ['free_min', 15], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 750)], [({'minutes': 143, 'validations': [['free_min', 15], ['pct', 25], ['flat', 500], ['pct', 10]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 120}, 0), ({'minutes': 449, 'validations': [['free_min', 15]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 2400), ({'minutes': 328, 'validations': [['free_min', 15], ['flat', 250], ['flat', 100], ['free_min', 30]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 180}, 1150), ({'minutes': 302, 'validations': [['free_min', 30], ['free_min', 15], ['free_min', 90]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 60}, 1500), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 244, 'validations': [['free_min', 30], ['flat', 500], ['free_min', 60], ['free_min', 15]], 'hourly': 300, 'daily_max': 1800, 'max_free_min': 60}, 700), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300)]]
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):
    free = max([0] + [v for k, v in x['validations'] if k == 'free_min'])
    bill = max(0, x['minutes'] - free)
    fee = min(x['daily_max'], -(-bill // 60) * x['hourly'])
    pcts = [v for k, v in x['validations'] if k == 'pct']
    if pcts:
        fee -= fee * max(pcts) // 100
    flat = sum(v for k, v in x['validations'] if k == 'flat')
    return max(0, fee - flat)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 242, 'validations': [['free_min', 60], ['free_min', 15]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 60}, 800), ({'minutes': 405, 'validations': [['free_min', 90], ['free_min', 15], ['free_min', 60], ['pct', 25]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 60}, 1350), ({'minutes': 1305, 'validations': [['free_min', 30], ['free_min', 15], ['pct', 25]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 180}, 1800), ({'minutes': 527, 'validations': [['flat', 250]], 'hourly': 200, 'daily_max': 3000, 'max_free_min': 60}, 1550), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 850, 'validations': [['pct', 10], ['free_min', 60], ['free_min', 30], ['flat', 250]], 'hourly': 200, 'daily_max': 3000, 'max_free_min': 180}, 2090)], [({'minutes': 761, 'validations': [['free_min', 120], ['free_min', 120], ['free_min', 60]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 120}, 1800), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 967, 'validations': [['free_min', 120]], 'hourly': 300, 'daily_max': 3000, 'max_free_min': 60}, 3000), ({'minutes': 212, 'validations': [['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 60}, 900), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 203, 'validations': [['free_min', 120], ['flat', 250], ['pct', 10], ['free_min', 120]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 180}, 20), ({'minutes': 999, 'validations': [['free_min', 120], ['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 2400)], [({'minutes': 188, 'validations': [['free_min', 120], ['free_min', 30]], 'hourly': 200, 'daily_max': 3000, 'max_free_min': 60}, 600), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 583, 'validations': [], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 60}, 1800), ({'minutes': 598, 'validations': [['flat', 100]], 'hourly': 350, 'daily_max': 3000, 'max_free_min': 120}, 2900), ({'minutes': 72, 'validations': [['free_min', 15], ['flat', 250], ['free_min', 60], ['free_min', 30]], 'hourly': 300, 'daily_max': 1800, 'max_free_min': 60}, 50), ({'minutes': 282, 'validations': [['pct', 10], ['free_min', 30], ['free_min', 30]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 120}, 720)], [({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 431, 'validations': [], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 60}, 1600), ({'minutes': 580, 'validations': [['flat', 500], ['free_min', 60], ['pct', 50]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 60}, 400), ({'minutes': 1309, 'validations': [['free_min', 30], ['pct', 10], ['pct', 25]], 'hourly': 200, 'daily_max': 3000, 'max_free_min': 120}, 2250), ({'minutes': 596, 'validations': [['pct', 10], ['free_min', 90], ['free_min', 120], ['free_min', 90]], 'hourly': 350, 'daily_max': 3000, 'max_free_min': 60}, 2700), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 361, 'validations': [['free_min', 120], ['pct', 50], ['free_min', 15], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 750)], [({'minutes': 143, 'validations': [['free_min', 15], ['pct', 25], ['flat', 500], ['pct', 10]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 120}, 0), ({'minutes': 449, 'validations': [['free_min', 15]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 2400), ({'minutes': 328, 'validations': [['free_min', 15], ['flat', 250], ['flat', 100], ['free_min', 30]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 180}, 1150), ({'minutes': 302, 'validations': [['free_min', 30], ['free_min', 15], ['free_min', 90]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 60}, 1500), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 244, 'validations': [['free_min', 30], ['flat', 500], ['free_min', 60], ['free_min', 15]], 'hourly': 300, 'daily_max': 1800, 'max_free_min': 60}, 700), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300)]]
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:
Merchant parking validations returns a wrong result when the free-minute cap is applied per validation.

Input {minutes (single day), validations: [[free_min|pct|flat, value]], hourly, daily_max, max_free_min}. Free minutes from all validations are summed, capped at max_free_min and deducted from the stay before rating. The fee is started hours * hourly capped at daily_max. Only the largest percentage validation applies (discount floored to cents), then all flat validations are subtracted, never below zero.

split: open-access


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

N = 1
observations = []
def solve(x):
    free = min(x['max_free_min'], sum(v for k, v in x['validations'] if k == 'free_min'))
    bill = max(0, x['minutes'] - free)
    fee = min(x['daily_max'], -(-x['minutes'] // 60) * x['hourly']) - (free // 60) * x['hourly']
    pcts = [v for k, v in x['validations'] if k == 'pct']
    if pcts:
        fee -= fee * max(pcts) // 100
    flat = sum(v for k, v in x['validations'] if k == 'flat')
    return max(0, fee - flat)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 426, 'validations': [['pct', 50], ['free_min', 15], ['free_min', 30], ['pct', 10]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 180}, 700), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 854, 'validations': [['pct', 10], ['free_min', 30], ['free_min', 30], ['flat', 100]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 60}, 1520), ({'minutes': 217, 'validations': [['pct', 50], ['pct', 10], ['free_min', 15]], 'hourly': 350, 'daily_max': 3000, 'max_free_min': 120}, 700), ({'minutes': 8, 'validations': [], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 60}, 350), ({'minutes': 859, 'validations': [['flat', 500], ['free_min', 15], ['free_min', 90]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 180}, 1300), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700)], [({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 975, 'validations': [['free_min', 120], ['pct', 50], ['pct', 25]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 180}, 900), ({'minutes': 936, 'validations': [['pct', 50], ['free_min', 120]], 'hourly': 300, 'daily_max': 1800, 'max_free_min': 60}, 900), ({'minutes': 523, 'validations': [['free_min', 120], ['pct', 10], ['pct', 50]], 'hourly': 300, 'daily_max': 1800, 'max_free_min': 60}, 900), ({'minutes': 351, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 3000, 'max_free_min': 60}, 2100), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 419, 'validations': [['flat', 500]], 'hourly': 200, 'daily_max': 3000, 'max_free_min': 180}, 900)], [({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 825, 'validations': [['pct', 25], ['free_min', 60], ['free_min', 30]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 1800), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 751, 'validations': [['free_min', 120], ['free_min', 15], ['free_min', 90], ['flat', 250]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 60}, 1550), ({'minutes': 267, 'validations': [['free_min', 15]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 180}, 1750), ({'minutes': 580, 'validations': [['free_min', 90], ['free_min', 15], ['flat', 250]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 180}, 1350), ({'minutes': 51, 'validations': [['pct', 25], ['free_min', 30], ['free_min', 120], ['pct', 10]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 0), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550)], [({'minutes': 1354, 'validations': [['flat', 250], ['free_min', 90], ['pct', 10], ['free_min', 120]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 180}, 1910), ({'minutes': 406, 'validations': [['flat', 500], ['pct', 25], ['free_min', 90], ['pct', 50]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 60}, 400), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 1257, 'validations': [['free_min', 90], ['flat', 250], ['free_min', 60], ['free_min', 120]], 'hourly': 300, 'daily_max': 1800, 'max_free_min': 60}, 1550), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 540, 'validations': [['flat', 100], ['free_min', 60]], 'hourly': 300, 'daily_max': 3000, 'max_free_min': 60}, 2300), ({'minutes': 224, 'validations': [['pct', 50], ['free_min', 15]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 120}, 700), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300)], [({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 911, 'validations': [['flat', 250], ['free_min', 30], ['free_min', 60], ['free_min', 15]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 120}, 1550), ({'minutes': 1367, 'validations': [['free_min', 90], ['flat', 250], ['free_min', 30], ['free_min', 120]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 2150), ({'minutes': 494, 'validations': [], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 180}, 2400), ({'minutes': 440, 'validations': [['free_min', 15], ['flat', 250]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 180}, 1350), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 1259, 'validations': [['free_min', 120], ['free_min', 30], ['free_min', 120], ['free_min', 120]], 'hourly': 300, 'daily_max': 1800, 'max_free_min': 60}, 1800)]]
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):
    free = min(x['max_free_min'], sum(v for k, v in x['validations'] if k == 'free_min'))
    bill = max(0, x['minutes'] - free)
    fee = min(x['daily_max'], -(-x['minutes'] // 60) * x['hourly'] - -(-free // 60) * x['hourly'])
    pcts = [v for k, v in x['validations'] if k == 'pct']
    if pcts:
        fee -= fee * max(pcts) // 100
    flat = sum(v for k, v in x['validations'] if k == 'flat')
    return max(0, fee - flat)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 426, 'validations': [['pct', 50], ['free_min', 15], ['free_min', 30], ['pct', 10]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 180}, 700), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 854, 'validations': [['pct', 10], ['free_min', 30], ['free_min', 30], ['flat', 100]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 60}, 1520), ({'minutes': 217, 'validations': [['pct', 50], ['pct', 10], ['free_min', 15]], 'hourly': 350, 'daily_max': 3000, 'max_free_min': 120}, 700), ({'minutes': 8, 'validations': [], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 60}, 350), ({'minutes': 859, 'validations': [['flat', 500], ['free_min', 15], ['free_min', 90]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 180}, 1300), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700)], [({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 975, 'validations': [['free_min', 120], ['pct', 50], ['pct', 25]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 180}, 900), ({'minutes': 936, 'validations': [['pct', 50], ['free_min', 120]], 'hourly': 300, 'daily_max': 1800, 'max_free_min': 60}, 900), ({'minutes': 523, 'validations': [['free_min', 120], ['pct', 10], ['pct', 50]], 'hourly': 300, 'daily_max': 1800, 'max_free_min': 60}, 900), ({'minutes': 351, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 3000, 'max_free_min': 60}, 2100), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 419, 'validations': [['flat', 500]], 'hourly': 200, 'daily_max': 3000, 'max_free_min': 180}, 900)], [({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 825, 'validations': [['pct', 25], ['free_min', 60], ['free_min', 30]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 1800), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 751, 'validations': [['free_min', 120], ['free_min', 15], ['free_min', 90], ['flat', 250]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 60}, 1550), ({'minutes': 267, 'validations': [['free_min', 15]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 180}, 1750), ({'minutes': 580, 'validations': [['free_min', 90], ['free_min', 15], ['flat', 250]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 180}, 1350), ({'minutes': 51, 'validations': [['pct', 25], ['free_min', 30], ['free_min', 120], ['pct', 10]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 0), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550)], [({'minutes': 1354, 'validations': [['flat', 250], ['free_min', 90], ['pct', 10], ['free_min', 120]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 180}, 1910), ({'minutes': 406, 'validations': [['flat', 500], ['pct', 25], ['free_min', 90], ['pct', 50]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 60}, 400), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 1257, 'validations': [['free_min', 90], ['flat', 250], ['free_min', 60], ['free_min', 120]], 'hourly': 300, 'daily_max': 1800, 'max_free_min': 60}, 1550), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 540, 'validations': [['flat', 100], ['free_min', 60]], 'hourly': 300, 'daily_max': 3000, 'max_free_min': 60}, 2300), ({'minutes': 224, 'validations': [['pct', 50], ['free_min', 15]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 120}, 700), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300)], [({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 911, 'validations': [['flat', 250], ['free_min', 30], ['free_min', 60], ['free_min', 15]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 120}, 1550), ({'minutes': 1367, 'validations': [['free_min', 90], ['flat', 250], ['free_min', 30], ['free_min', 120]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 2150), ({'minutes': 494, 'validations': [], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 180}, 2400), ({'minutes': 440, 'validations': [['free_min', 15], ['flat', 250]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 180}, 1350), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 1259, 'validations': [['free_min', 120], ['free_min', 30], ['free_min', 120], ['free_min', 120]], 'hourly': 300, 'daily_max': 1800, 'max_free_min': 60}, 1800)]]
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:
Merchant parking validations returns a wrong result when free minutes are converted to money after rating.

Input {minutes (single day), validations: [[free_min|pct|flat, value]], hourly, daily_max, max_free_min}. Free minutes from all validations are summed, capped at max_free_min and deducted from the stay before rating. The fee is started hours * hourly capped at daily_max. Only the largest percentage validation applies (discount floored to cents), then all flat validations are subtracted, never below zero.

split: open-access


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

N = 1
observations = []
def solve(x):
    free = min(x['max_free_min'], sum(v for k, v in x['validations'] if k == 'free_min'))
    bill = max(0, x['minutes'] - free)
    fee = min(x['daily_max'], -(-bill // 60) * x['hourly'])
    pcts = [v for k, v in x['validations'] if k == 'pct']
    if pcts:
        fee -= fee * sum(pcts) // 100
    flat = sum(v for k, v in x['validations'] if k == 'flat')
    return max(0, fee - flat)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'minutes': 846, 'validations': [['pct', 10], ['pct', 25], ['free_min', 120], ['free_min', 120]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 60}, 1800), ({'minutes': 1263, 'validations': [['pct', 25], ['flat', 250], ['pct', 50]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 120}, 650), ({'minutes': 881, 'validations': [['free_min', 120]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 120}, 1800), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 1001, 'validations': [['flat', 250], ['free_min', 15], ['free_min', 90]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 60}, 2150), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 1217, 'validations': [['pct', 50], ['pct', 10], ['flat', 500]], 'hourly': 300, 'daily_max': 3000, 'max_free_min': 120}, 1000)], [({'minutes': 257, 'validations': [['pct', 10], ['pct', 25], ['free_min', 120]], 'hourly': 300, 'daily_max': 3000, 'max_free_min': 180}, 675), ({'minutes': 17, 'validations': [['free_min', 60], ['free_min', 90]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 0), ({'minutes': 605, 'validations': [['pct', 50], ['pct', 25]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 180}, 900), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 1047, 'validations': [], 'hourly': 200, 'daily_max': 3000, 'max_free_min': 180}, 3000), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 230, 'validations': [['flat', 250], ['free_min', 120]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 180}, 150), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700)], [({'minutes': 1076, 'validations': [], 'hourly': 300, 'daily_max': 3000, 'max_free_min': 180}, 3000), ({'minutes': 1191, 'validations': [['pct', 25], ['pct', 25], ['flat', 500]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 120}, 1300), ({'minutes': 5, 'validations': [['flat', 100], ['free_min', 15], ['free_min', 120]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 180}, 0), ({'minutes': 740, 'validations': [['free_min', 90]], 'hourly': 300, 'daily_max': 1800, 'max_free_min': 60}, 1800), ({'minutes': 1071, 'validations': [['pct', 50], ['free_min', 60], ['pct', 10], ['free_min', 60]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 60}, 1200), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550)], [({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 297, 'validations': [['pct', 10], ['free_min', 60], ['pct', 25]], 'hourly': 300, 'daily_max': 3000, 'max_free_min': 120}, 900), ({'minutes': 516, 'validations': [['free_min', 30], ['free_min', 60], ['free_min', 30], ['pct', 25]], 'hourly': 300, 'daily_max': 1800, 'max_free_min': 120}, 1350), ({'minutes': 936, 'validations': [['pct', 50], ['free_min', 120], ['pct', 25], ['flat', 500]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 60}, 700), ({'minutes': 814, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 120}, 1800), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 1039, 'validations': [['free_min', 90], ['free_min', 90], ['flat', 250], ['free_min', 60]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 60}, 2150), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550)], [({'minutes': 1392, 'validations': [], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 2400), ({'minutes': 1332, 'validations': [['flat', 500], ['pct', 50], ['pct', 25]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 60}, 700), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 195, 'validations': [['free_min', 60], ['free_min', 30], ['pct', 10]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 60}, 540), ({'minutes': 899, 'validations': [['free_min', 120]], 'hourly': 300, 'daily_max': 3000, 'max_free_min': 180}, 3000), ({'minutes': 1058, 'validations': [['pct', 50], ['pct', 25], ['free_min', 60]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 180}, 900), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550)]]
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):
    free = min(x['max_free_min'], sum(v for k, v in x['validations'] if k == 'free_min'))
    bill = max(0, x['minutes'] - free)
    fee = min(x['daily_max'], -(-bill // 60) * x['hourly'])
    pcts = [v for k, v in x['validations'] if k == 'pct']
    if pcts:
        fee -= fee * pcts[-1] // 100
    flat = sum(v for k, v in x['validations'] if k == 'flat')
    return max(0, fee - flat)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'minutes': 846, 'validations': [['pct', 10], ['pct', 25], ['free_min', 120], ['free_min', 120]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 60}, 1800), ({'minutes': 1263, 'validations': [['pct', 25], ['flat', 250], ['pct', 50]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 120}, 650), ({'minutes': 881, 'validations': [['free_min', 120]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 120}, 1800), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 1001, 'validations': [['flat', 250], ['free_min', 15], ['free_min', 90]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 60}, 2150), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 1217, 'validations': [['pct', 50], ['pct', 10], ['flat', 500]], 'hourly': 300, 'daily_max': 3000, 'max_free_min': 120}, 1000)], [({'minutes': 257, 'validations': [['pct', 10], ['pct', 25], ['free_min', 120]], 'hourly': 300, 'daily_max': 3000, 'max_free_min': 180}, 675), ({'minutes': 17, 'validations': [['free_min', 60], ['free_min', 90]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 0), ({'minutes': 605, 'validations': [['pct', 50], ['pct', 25]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 180}, 900), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 1047, 'validations': [], 'hourly': 200, 'daily_max': 3000, 'max_free_min': 180}, 3000), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550), ({'minutes': 230, 'validations': [['flat', 250], ['free_min', 120]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 180}, 150), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700)], [({'minutes': 1076, 'validations': [], 'hourly': 300, 'daily_max': 3000, 'max_free_min': 180}, 3000), ({'minutes': 1191, 'validations': [['pct', 25], ['pct', 25], ['flat', 500]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 120}, 1300), ({'minutes': 5, 'validations': [['flat', 100], ['free_min', 15], ['free_min', 120]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 180}, 0), ({'minutes': 740, 'validations': [['free_min', 90]], 'hourly': 300, 'daily_max': 1800, 'max_free_min': 60}, 1800), ({'minutes': 1071, 'validations': [['pct', 50], ['free_min', 60], ['pct', 10], ['free_min', 60]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 60}, 1200), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550)], [({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 297, 'validations': [['pct', 10], ['free_min', 60], ['pct', 25]], 'hourly': 300, 'daily_max': 3000, 'max_free_min': 120}, 900), ({'minutes': 516, 'validations': [['free_min', 30], ['free_min', 60], ['free_min', 30], ['pct', 25]], 'hourly': 300, 'daily_max': 1800, 'max_free_min': 120}, 1350), ({'minutes': 936, 'validations': [['pct', 50], ['free_min', 120], ['pct', 25], ['flat', 500]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 60}, 700), ({'minutes': 814, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 1800, 'max_free_min': 120}, 1800), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 1039, 'validations': [['free_min', 90], ['free_min', 90], ['flat', 250], ['free_min', 60]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 60}, 2150), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550)], [({'minutes': 1392, 'validations': [], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 2400), ({'minutes': 1332, 'validations': [['flat', 500], ['pct', 50], ['pct', 25]], 'hourly': 200, 'daily_max': 2400, 'max_free_min': 60}, 700), ({'minutes': 150, 'validations': [['free_min', 60], ['free_min', 60], ['free_min', 60]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 300), ({'minutes': 195, 'validations': [['free_min', 60], ['free_min', 30], ['pct', 10]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 60}, 540), ({'minutes': 899, 'validations': [['free_min', 120]], 'hourly': 300, 'daily_max': 3000, 'max_free_min': 180}, 3000), ({'minutes': 1058, 'validations': [['pct', 50], ['pct', 25], ['free_min', 60]], 'hourly': 200, 'daily_max': 1800, 'max_free_min': 180}, 900), ({'minutes': 95, 'validations': [['free_min', 30]], 'hourly': 350, 'daily_max': 2400, 'max_free_min': 120}, 700), ({'minutes': 200, 'validations': [['pct', 25], ['pct', 10], ['flat', 100], ['flat', 250]], 'hourly': 300, 'daily_max': 2400, 'max_free_min': 120}, 550)]]
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:
Merchant parking validations returns a wrong result when percentage validations are summed.

Input {minutes (single day), validations: [[free_min|pct|flat, value]], hourly, daily_max, max_free_min}. Free minutes from all validations are summed, capped at max_free_min and deducted from the stay before rating. The fee is started hours * hourly capped at daily_max. Only the largest percentage validation applies (discount floored to cents), then all flat validations are subtracted, never below zero.

split: open-access