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

N = 1
observations = []
def solve(x):
    bal = x['balances']
    caps = x['caps']
    rq = x['requester']
    usable = lambda m: bal[m] if m == rq else min(bal[m], caps.get(m, bal[m]))
    if x['pts'] > sum(usable(m) for m in bal):
        return {'error': 'insufficient'}
    others = sorted([m for m in bal if m != rq], key=lambda m: (-usable(m), m))
    need = x['pts']
    draws = []
    for m in sorted(bal, key=lambda m: (-usable(m), m)):
        t = min(need, usable(m))
        if t > 0:
            draws.append([m, t])
            need -= t
    return {'draws': draws}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1001}, {'draws': [['ann', 300], ['bob', 701]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 201}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 301}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 701}, {'draws': [['ann', 701]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 701}, {'draws': [['cy', 600], ['dee', 101]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 401}, {'draws': [['amy', 300], ['max', 101]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4001}, {'draws': [['ann', 4001]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1002}, {'draws': [['ann', 300], ['bob', 702]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 202}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 302}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 702}, {'draws': [['ann', 702]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 702}, {'draws': [['cy', 600], ['dee', 102]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 402}, {'draws': [['amy', 300], ['max', 102]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4002}, {'draws': [['ann', 4002]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1003}, {'draws': [['ann', 300], ['bob', 703]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 203}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 303}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 703}, {'draws': [['ann', 703]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 703}, {'draws': [['cy', 600], ['dee', 103]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 403}, {'draws': [['amy', 300], ['max', 103]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4003}, {'draws': [['ann', 4003]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1004}, {'draws': [['ann', 300], ['bob', 704]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 204}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 304}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 704}, {'draws': [['ann', 704]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 704}, {'draws': [['cy', 600], ['dee', 104]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 404}, {'draws': [['amy', 300], ['max', 104]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4004}, {'draws': [['ann', 4004]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1005}, {'draws': [['ann', 300], ['bob', 705]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 205}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 305}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 705}, {'draws': [['ann', 705]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 705}, {'draws': [['cy', 600], ['dee', 105]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 405}, {'draws': [['amy', 300], ['max', 105]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4005}, {'draws': [['ann', 4005]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    bal = x['balances']
    caps = x['caps']
    rq = x['requester']
    usable = lambda m: bal[m] if m == rq else min(bal[m], caps.get(m, bal[m]))
    if x['pts'] > sum(usable(m) for m in bal):
        return {'error': 'insufficient'}
    others = sorted([m for m in bal if m != rq], key=lambda m: (-usable(m), m))
    need = x['pts']
    draws = []
    for m in others + [rq]:
        t = min(need, usable(m))
        if t > 0:
            draws.append([m, t])
            need -= t
    return {'draws': draws}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1001}, {'draws': [['ann', 300], ['bob', 701]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 201}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 301}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 701}, {'draws': [['ann', 701]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 701}, {'draws': [['cy', 600], ['dee', 101]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 401}, {'draws': [['amy', 300], ['max', 101]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4001}, {'draws': [['ann', 4001]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1002}, {'draws': [['ann', 300], ['bob', 702]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 202}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 302}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 702}, {'draws': [['ann', 702]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 702}, {'draws': [['cy', 600], ['dee', 102]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 402}, {'draws': [['amy', 300], ['max', 102]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4002}, {'draws': [['ann', 4002]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1003}, {'draws': [['ann', 300], ['bob', 703]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 203}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 303}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 703}, {'draws': [['ann', 703]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 703}, {'draws': [['cy', 600], ['dee', 103]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 403}, {'draws': [['amy', 300], ['max', 103]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4003}, {'draws': [['ann', 4003]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1004}, {'draws': [['ann', 300], ['bob', 704]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 204}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 304}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 704}, {'draws': [['ann', 704]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 704}, {'draws': [['cy', 600], ['dee', 104]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 404}, {'draws': [['amy', 300], ['max', 104]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4004}, {'draws': [['ann', 4004]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1005}, {'draws': [['ann', 300], ['bob', 705]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 205}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 305}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 705}, {'draws': [['ann', 705]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 705}, {'draws': [['cy', 600], ['dee', 105]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 405}, {'draws': [['amy', 300], ['max', 105]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4005}, {'draws': [['ann', 4005]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Household members are drained before the member who is redeeming.

Input {balances:{member:pts}, caps:{member:max contribution}, requester, pts}. The requester contributes their full balance first (caps never apply to the requester). Other members contribute up to min(balance, cap), in descending order of that usable amount, ties by name. If total usable points are short return {"error":"insufficient"}. Return {draws:[[member,pts]]} with zero draws omitted.

split: open-access


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

N = 1
observations = []
def solve(x):
    bal = x['balances']
    caps = x['caps']
    rq = x['requester']
    usable = lambda m: bal[m]
    if x['pts'] > sum(usable(m) for m in bal):
        return {'error': 'insufficient'}
    others = sorted([m for m in bal if m != rq], key=lambda m: (-usable(m), m))
    need = x['pts']
    draws = []
    for m in [rq] + others:
        t = min(need, usable(m))
        if t > 0:
            draws.append([m, t])
            need -= t
    return {'draws': draws}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1001}, {'draws': [['ann', 300], ['bob', 701]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 201}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 301}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 701}, {'draws': [['ann', 701]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 701}, {'draws': [['cy', 600], ['dee', 101]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 401}, {'draws': [['amy', 300], ['max', 101]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4001}, {'draws': [['ann', 4001]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1002}, {'draws': [['ann', 300], ['bob', 702]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 202}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 302}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 702}, {'draws': [['ann', 702]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 702}, {'draws': [['cy', 600], ['dee', 102]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 402}, {'draws': [['amy', 300], ['max', 102]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4002}, {'draws': [['ann', 4002]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1003}, {'draws': [['ann', 300], ['bob', 703]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 203}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 303}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 703}, {'draws': [['ann', 703]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 703}, {'draws': [['cy', 600], ['dee', 103]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 403}, {'draws': [['amy', 300], ['max', 103]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4003}, {'draws': [['ann', 4003]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1004}, {'draws': [['ann', 300], ['bob', 704]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 204}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 304}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 704}, {'draws': [['ann', 704]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 704}, {'draws': [['cy', 600], ['dee', 104]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 404}, {'draws': [['amy', 300], ['max', 104]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4004}, {'draws': [['ann', 4004]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1005}, {'draws': [['ann', 300], ['bob', 705]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 205}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 305}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 705}, {'draws': [['ann', 705]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 705}, {'draws': [['cy', 600], ['dee', 105]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 405}, {'draws': [['amy', 300], ['max', 105]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4005}, {'draws': [['ann', 4005]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    bal = x['balances']
    caps = x['caps']
    rq = x['requester']
    usable = lambda m: min(bal[m], caps.get(m, bal[m]))
    if x['pts'] > sum(usable(m) for m in bal):
        return {'error': 'insufficient'}
    others = sorted([m for m in bal if m != rq], key=lambda m: (-usable(m), m))
    need = x['pts']
    draws = []
    for m in [rq] + others:
        t = min(need, usable(m))
        if t > 0:
            draws.append([m, t])
            need -= t
    return {'draws': draws}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1001}, {'draws': [['ann', 300], ['bob', 701]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 201}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 301}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 701}, {'draws': [['ann', 701]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 701}, {'draws': [['cy', 600], ['dee', 101]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 401}, {'draws': [['amy', 300], ['max', 101]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4001}, {'draws': [['ann', 4001]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1002}, {'draws': [['ann', 300], ['bob', 702]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 202}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 302}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 702}, {'draws': [['ann', 702]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 702}, {'draws': [['cy', 600], ['dee', 102]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 402}, {'draws': [['amy', 300], ['max', 102]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4002}, {'draws': [['ann', 4002]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1003}, {'draws': [['ann', 300], ['bob', 703]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 203}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 303}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 703}, {'draws': [['ann', 703]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 703}, {'draws': [['cy', 600], ['dee', 103]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 403}, {'draws': [['amy', 300], ['max', 103]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4003}, {'draws': [['ann', 4003]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1004}, {'draws': [['ann', 300], ['bob', 704]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 204}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 304}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 704}, {'draws': [['ann', 704]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 704}, {'draws': [['cy', 600], ['dee', 104]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 404}, {'draws': [['amy', 300], ['max', 104]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4004}, {'draws': [['ann', 4004]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1005}, {'draws': [['ann', 300], ['bob', 705]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 205}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 305}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 705}, {'draws': [['ann', 705]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 705}, {'draws': [['cy', 600], ['dee', 105]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 405}, {'draws': [['amy', 300], ['max', 105]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4005}, {'draws': [['ann', 4005]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A member who limited their pool contribution is drawn beyond their limit.

Input {balances:{member:pts}, caps:{member:max contribution}, requester, pts}. The requester contributes their full balance first (caps never apply to the requester). Other members contribute up to min(balance, cap), in descending order of that usable amount, ties by name. If total usable points are short return {"error":"insufficient"}. Return {draws:[[member,pts]]} with zero draws omitted.

split: open-access


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

N = 1
observations = []
def solve(x):
    bal = x['balances']
    caps = x['caps']
    rq = x['requester']
    usable = lambda m: bal[m] if m == rq else min(bal[m], caps.get(m, bal[m]))
    if x['pts'] > sum(bal.values()):
        return {'error': 'insufficient'}
    others = sorted([m for m in bal if m != rq], key=lambda m: (-usable(m), m))
    need = x['pts']
    draws = []
    for m in [rq] + others:
        t = min(need, usable(m))
        if t > 0:
            draws.append([m, t])
            need -= t
    return {'draws': draws}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1001}, {'draws': [['ann', 300], ['bob', 701]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 201}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 301}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 701}, {'draws': [['ann', 701]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 701}, {'draws': [['cy', 600], ['dee', 101]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 401}, {'draws': [['amy', 300], ['max', 101]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4001}, {'draws': [['ann', 4001]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1002}, {'draws': [['ann', 300], ['bob', 702]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 202}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 302}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 702}, {'draws': [['ann', 702]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 702}, {'draws': [['cy', 600], ['dee', 102]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 402}, {'draws': [['amy', 300], ['max', 102]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4002}, {'draws': [['ann', 4002]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1003}, {'draws': [['ann', 300], ['bob', 703]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 203}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 303}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 703}, {'draws': [['ann', 703]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 703}, {'draws': [['cy', 600], ['dee', 103]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 403}, {'draws': [['amy', 300], ['max', 103]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4003}, {'draws': [['ann', 4003]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1004}, {'draws': [['ann', 300], ['bob', 704]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 204}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 304}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 704}, {'draws': [['ann', 704]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 704}, {'draws': [['cy', 600], ['dee', 104]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 404}, {'draws': [['amy', 300], ['max', 104]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4004}, {'draws': [['ann', 4004]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1005}, {'draws': [['ann', 300], ['bob', 705]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 205}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 305}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 705}, {'draws': [['ann', 705]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 705}, {'draws': [['cy', 600], ['dee', 105]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 405}, {'draws': [['amy', 300], ['max', 105]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4005}, {'draws': [['ann', 4005]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    bal = x['balances']
    caps = x['caps']
    rq = x['requester']
    usable = lambda m: bal[m] if m == rq else min(bal[m], caps.get(m, bal[m]))
    if x['pts'] > sum(usable(m) for m in bal if m != rq):
        return {'error': 'insufficient'}
    others = sorted([m for m in bal if m != rq], key=lambda m: (-usable(m), m))
    need = x['pts']
    draws = []
    for m in [rq] + others:
        t = min(need, usable(m))
        if t > 0:
            draws.append([m, t])
            need -= t
    return {'draws': draws}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1001}, {'draws': [['ann', 300], ['bob', 701]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 201}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 301}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 701}, {'draws': [['ann', 701]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 701}, {'draws': [['cy', 600], ['dee', 101]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 401}, {'draws': [['amy', 300], ['max', 101]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4001}, {'draws': [['ann', 4001]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1002}, {'draws': [['ann', 300], ['bob', 702]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 202}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 302}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 702}, {'draws': [['ann', 702]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 702}, {'draws': [['cy', 600], ['dee', 102]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 402}, {'draws': [['amy', 300], ['max', 102]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4002}, {'draws': [['ann', 4002]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1003}, {'draws': [['ann', 300], ['bob', 703]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 203}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 303}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 703}, {'draws': [['ann', 703]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 703}, {'draws': [['cy', 600], ['dee', 103]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 403}, {'draws': [['amy', 300], ['max', 103]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4003}, {'draws': [['ann', 4003]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1004}, {'draws': [['ann', 300], ['bob', 704]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 204}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 304}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 704}, {'draws': [['ann', 704]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 704}, {'draws': [['cy', 600], ['dee', 104]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 404}, {'draws': [['amy', 300], ['max', 104]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4004}, {'draws': [['ann', 4004]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1005}, {'draws': [['ann', 300], ['bob', 705]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 205}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 305}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 705}, {'draws': [['ann', 705]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 705}, {'draws': [['cy', 600], ['dee', 105]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 405}, {'draws': [['amy', 300], ['max', 105]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4005}, {'draws': [['ann', 4005]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A redemption is accepted against capped balances and returns draws that fall short of the request.

Input {balances:{member:pts}, caps:{member:max contribution}, requester, pts}. The requester contributes their full balance first (caps never apply to the requester). Other members contribute up to min(balance, cap), in descending order of that usable amount, ties by name. If total usable points are short return {"error":"insufficient"}. Return {draws:[[member,pts]]} with zero draws omitted.

split: open-access


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

N = 1
observations = []
def solve(x):
    bal = x['balances']
    caps = x['caps']
    rq = x['requester']
    usable = lambda m: bal[m] if m == rq else min(bal[m], caps.get(m, bal[m]))
    if x['pts'] > sum(usable(m) for m in bal):
        return {'error': 'insufficient'}
    others = sorted([m for m in bal if m != rq], key=lambda m: (-bal[m], m))
    need = x['pts']
    draws = []
    for m in [rq] + others:
        t = min(need, usable(m))
        if t > 0:
            draws.append([m, t])
            need -= t
    return {'draws': draws}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1001}, {'draws': [['ann', 300], ['bob', 701]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 201}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 301}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 701}, {'draws': [['ann', 701]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 701}, {'draws': [['cy', 600], ['dee', 101]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 401}, {'draws': [['amy', 300], ['max', 101]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4001}, {'draws': [['ann', 4001]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1002}, {'draws': [['ann', 300], ['bob', 702]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 202}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 302}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 702}, {'draws': [['ann', 702]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 702}, {'draws': [['cy', 600], ['dee', 102]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 402}, {'draws': [['amy', 300], ['max', 102]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4002}, {'draws': [['ann', 4002]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1003}, {'draws': [['ann', 300], ['bob', 703]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 203}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 303}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 703}, {'draws': [['ann', 703]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 703}, {'draws': [['cy', 600], ['dee', 103]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 403}, {'draws': [['amy', 300], ['max', 103]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4003}, {'draws': [['ann', 4003]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1004}, {'draws': [['ann', 300], ['bob', 704]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 204}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 304}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 704}, {'draws': [['ann', 704]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 704}, {'draws': [['cy', 600], ['dee', 104]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 404}, {'draws': [['amy', 300], ['max', 104]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4004}, {'draws': [['ann', 4004]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1005}, {'draws': [['ann', 300], ['bob', 705]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 205}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 305}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 705}, {'draws': [['ann', 705]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 705}, {'draws': [['cy', 600], ['dee', 105]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 405}, {'draws': [['amy', 300], ['max', 105]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4005}, {'draws': [['ann', 4005]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    bal = x['balances']
    caps = x['caps']
    rq = x['requester']
    usable = lambda m: bal[m] if m == rq else min(bal[m], caps.get(m, bal[m]))
    if x['pts'] > sum(usable(m) for m in bal):
        return {'error': 'insufficient'}
    others = sorted([m for m in bal if m != rq], key=lambda m: (usable(m), m))
    need = x['pts']
    draws = []
    for m in [rq] + others:
        t = min(need, usable(m))
        if t > 0:
            draws.append([m, t])
            need -= t
    return {'draws': draws}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1001}, {'draws': [['ann', 300], ['bob', 701]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 201}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 301}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 701}, {'draws': [['ann', 701]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 701}, {'draws': [['cy', 600], ['dee', 101]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 401}, {'draws': [['amy', 300], ['max', 101]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4001}, {'draws': [['ann', 4001]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1002}, {'draws': [['ann', 300], ['bob', 702]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 202}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 302}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 702}, {'draws': [['ann', 702]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 702}, {'draws': [['cy', 600], ['dee', 102]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 402}, {'draws': [['amy', 300], ['max', 102]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4002}, {'draws': [['ann', 4002]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1003}, {'draws': [['ann', 300], ['bob', 703]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 203}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 303}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 703}, {'draws': [['ann', 703]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 703}, {'draws': [['cy', 600], ['dee', 103]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 403}, {'draws': [['amy', 300], ['max', 103]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4003}, {'draws': [['ann', 4003]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1004}, {'draws': [['ann', 300], ['bob', 704]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 204}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 304}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 704}, {'draws': [['ann', 704]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 704}, {'draws': [['cy', 600], ['dee', 104]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 404}, {'draws': [['amy', 300], ['max', 104]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4004}, {'draws': [['ann', 4004]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1005}, {'draws': [['ann', 300], ['bob', 705]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 205}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 305}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 705}, {'draws': [['ann', 705]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 705}, {'draws': [['cy', 600], ['dee', 105]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 405}, {'draws': [['amy', 300], ['max', 105]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4005}, {'draws': [['ann', 4005]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A capped high-balance member is drawn before members who can actually contribute more.

Input {balances:{member:pts}, caps:{member:max contribution}, requester, pts}. The requester contributes their full balance first (caps never apply to the requester). Other members contribute up to min(balance, cap), in descending order of that usable amount, ties by name. If total usable points are short return {"error":"insufficient"}. Return {draws:[[member,pts]]} with zero draws omitted.

split: open-access


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

N = 1
observations = []
def solve(x):
    bal = x['balances']
    caps = x['caps']
    rq = x['requester']
    usable = lambda m: bal[m] if m == rq else min(bal[m], caps.get(m, bal[m]))
    if x['pts'] > sum(usable(m) for m in bal):
        return {'error': 'insufficient'}
    others = sorted([m for m in bal if m != rq], key=lambda m: (-usable(m), m))
    need = x['pts']
    draws = []
    for m in [rq] + others:
        t = min(need, usable(m))
        if t > 0:
            draws.append([m, t])
    return {'draws': draws}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1001}, {'draws': [['ann', 300], ['bob', 701]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 201}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 301}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 701}, {'draws': [['ann', 701]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 701}, {'draws': [['cy', 600], ['dee', 101]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 401}, {'draws': [['amy', 300], ['max', 101]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4001}, {'draws': [['ann', 4001]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1002}, {'draws': [['ann', 300], ['bob', 702]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 202}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 302}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 702}, {'draws': [['ann', 702]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 702}, {'draws': [['cy', 600], ['dee', 102]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 402}, {'draws': [['amy', 300], ['max', 102]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4002}, {'draws': [['ann', 4002]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1003}, {'draws': [['ann', 300], ['bob', 703]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 203}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 303}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 703}, {'draws': [['ann', 703]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 703}, {'draws': [['cy', 600], ['dee', 103]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 403}, {'draws': [['amy', 300], ['max', 103]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4003}, {'draws': [['ann', 4003]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1004}, {'draws': [['ann', 300], ['bob', 704]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 204}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 304}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 704}, {'draws': [['ann', 704]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 704}, {'draws': [['cy', 600], ['dee', 104]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 404}, {'draws': [['amy', 300], ['max', 104]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4004}, {'draws': [['ann', 4004]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1005}, {'draws': [['ann', 300], ['bob', 705]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 205}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 305}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 705}, {'draws': [['ann', 705]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 705}, {'draws': [['cy', 600], ['dee', 105]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 405}, {'draws': [['amy', 300], ['max', 105]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4005}, {'draws': [['ann', 4005]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    bal = x['balances']
    caps = x['caps']
    rq = x['requester']
    usable = lambda m: bal[m] if m == rq else min(bal[m], caps.get(m, bal[m]))
    if x['pts'] > sum(usable(m) for m in bal):
        return {'error': 'insufficient'}
    others = sorted([m for m in bal if m != rq], key=lambda m: (-usable(m), m))
    need = x['pts']
    draws = []
    for m in [rq] + others:
        t = min(need, usable(m))
        if t > 0:
            draws.append([m, t])
            need = x['pts'] - t
    return {'draws': draws}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1001}, {'draws': [['ann', 300], ['bob', 701]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 201}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 301}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 701}, {'draws': [['ann', 701]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 701}, {'draws': [['cy', 600], ['dee', 101]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 401}, {'draws': [['amy', 300], ['max', 101]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4001}, {'draws': [['ann', 4001]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1002}, {'draws': [['ann', 300], ['bob', 702]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 202}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 302}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 702}, {'draws': [['ann', 702]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 702}, {'draws': [['cy', 600], ['dee', 102]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 402}, {'draws': [['amy', 300], ['max', 102]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4002}, {'draws': [['ann', 4002]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1003}, {'draws': [['ann', 300], ['bob', 703]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 203}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 303}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 703}, {'draws': [['ann', 703]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 703}, {'draws': [['cy', 600], ['dee', 103]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 403}, {'draws': [['amy', 300], ['max', 103]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4003}, {'draws': [['ann', 4003]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1004}, {'draws': [['ann', 300], ['bob', 704]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 204}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 304}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 704}, {'draws': [['ann', 704]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 704}, {'draws': [['cy', 600], ['dee', 104]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 404}, {'draws': [['amy', 300], ['max', 104]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4004}, {'draws': [['ann', 4004]]}]], [['requester first', {'balances': {'ann': 300, 'bob': 900, 'cy': 400}, 'caps': {}, 'requester': 'ann', 'pts': 1005}, {'draws': [['ann', 300], ['bob', 705]]}], ['capped contributor', {'balances': {'ann': 100, 'bob': 5000, 'cy': 400}, 'caps': {'bob': 205}, 'requester': 'ann', 'pts': 600}, {'draws': [['ann', 100], ['cy', 400], ['bob', 100]]}], ['insufficient with caps', {'balances': {'ann': 100, 'bob': 5000}, 'caps': {'bob': 100}, 'requester': 'ann', 'pts': 305}, {'error': 'insufficient'}], ['requester cap ignored', {'balances': {'ann': 800, 'bob': 100}, 'caps': {'ann': 10}, 'requester': 'ann', 'pts': 705}, {'draws': [['ann', 705]]}], ['order by usable', {'balances': {'ann': 0, 'bob': 5000, 'cy': 600, 'dee': 500}, 'caps': {'bob': 50}, 'requester': 'ann', 'pts': 705}, {'draws': [['cy', 600], ['dee', 105]]}], ['ties by name', {'balances': {'zed': 0, 'amy': 300, 'max': 300}, 'caps': {}, 'requester': 'zed', 'pts': 405}, {'draws': [['amy', 300], ['max', 105]]}], ['requester covers', {'balances': {'ann': 5000, 'bob': 9000}, 'caps': {}, 'requester': 'ann', 'pts': 4005}, {'draws': [['ann', 4005]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A household redemption pulls points from every member, drawing far more than the reward costs.

Input {balances:{member:pts}, caps:{member:max contribution}, requester, pts}. The requester contributes their full balance first (caps never apply to the requester). Other members contribute up to min(balance, cap), in descending order of that usable amount, ties by name. If total usable points are short return {"error":"insufficient"}. Return {draws:[[member,pts]]} with zero draws omitted.

split: open-access


prompt:
Periods ending on the 31st lose a day even when the start day is early in the month.

Inputs are two [year, month, day] dates. Apply, in order: if both dates are the last day of February, D2 becomes 30; if D1 is the last day of February, D1 becomes 30; if D2 is 31 and (adjusted) D1 is 30 or 31, D2 becomes 30; if D1 is 31, D1 becomes 30. Return 360*(Y2-Y1)+30*(M2-M1)+(D2-D1) as an integer day count.

split: open-access


prompt:
Accruals starting on 28 February of a leap year are extended as if the month had ended.

Inputs are two [year, month, day] dates. Apply, in order: if both dates are the last day of February, D2 becomes 30; if D1 is the last day of February, D1 becomes 30; if D2 is 31 and (adjusted) D1 is 30 or 31, D2 becomes 30; if D1 is 31, D1 becomes 30. Return 360*(Y2-Y1)+30*(M2-M1)+(D2-D1) as an integer day count.

split: open-access


prompt:
Periods ending on the last day of February gain days although they started mid-month.

Inputs are two [year, month, day] dates. Apply, in order: if both dates are the last day of February, D2 becomes 30; if D1 is the last day of February, D1 becomes 30; if D2 is 31 and (adjusted) D1 is 30 or 31, D2 becomes 30; if D1 is 31, D1 becomes 30. Return 360*(Y2-Y1)+30*(M2-M1)+(D2-D1) as an integer day count.

split: open-access


prompt:
A period from the end of February to a 31st keeps D2=31 and overstates the count by one day.

Inputs are two [year, month, day] dates. Apply, in order: if both dates are the last day of February, D2 becomes 30; if D1 is the last day of February, D1 becomes 30; if D2 is 31 and (adjusted) D1 is 30 or 31, D2 becomes 30; if D1 is 31, D1 becomes 30. Return 360*(Y2-Y1)+30*(M2-M1)+(D2-D1) as an integer day count.

split: open-access


prompt:
A start on the 31st with an end mid-month produces a count one day short.

Inputs are two [year, month, day] dates. Apply, in order: if both dates are the last day of February, D2 becomes 30; if D1 is the last day of February, D1 becomes 30; if D2 is 31 and (adjusted) D1 is 30 or 31, D2 becomes 30; if D1 is 31, D1 becomes 30. Return 360*(Y2-Y1)+30*(M2-M1)+(D2-D1) as an integer day count.

split: open-access


prompt:
The final period of a bond maturing at the end of February accrues two or one extra days.

Inputs: start, end and maturity dates as [y,m,d]. D1 becomes 30 if the start is the last day of its month. D2 becomes 30 if the end is the last day of its month, unless the end date equals the maturity date and falls in February. Return 360*(Y2-Y1)+30*(M2-M1)+(D2-D1).

split: open-access


prompt:
An interim February month-end that shares the maturity day number escapes promotion.

Inputs: start, end and maturity dates as [y,m,d]. D1 becomes 30 if the start is the last day of its month. D2 becomes 30 if the end is the last day of its month, unless the end date equals the maturity date and falls in February. Return 360*(Y2-Y1)+30*(M2-M1)+(D2-D1).

split: open-access


prompt:
Accruals starting or ending on 29 February are not recognized as month end.

Inputs: start, end and maturity dates as [y,m,d]. D1 becomes 30 if the start is the last day of its month. D2 becomes 30 if the end is the last day of its month, unless the end date equals the maturity date and falls in February. Return 360*(Y2-Y1)+30*(M2-M1)+(D2-D1).

split: open-access


prompt:
A period starting at the end of February accrues from day 28 or 29 instead of day 30.

Inputs: start, end and maturity dates as [y,m,d]. D1 becomes 30 if the start is the last day of its month. D2 becomes 30 if the end is the last day of its month, unless the end date equals the maturity date and falls in February. Return 360*(Y2-Y1)+30*(M2-M1)+(D2-D1).

split: open-access


prompt:
Accrued interest drifts from the ICMA value for periods that are not exactly 365/freq days.

Inputs prev, nxt, settle ([y,m,d]), annual rate, frequency and ex-coupon days. Settlement outside [prev, nxt] returns "settlement outside period"; settlement on nxt returns 0.0. If the settlement is within ex-coupon days of nxt (days to nxt <= exdays), accrued is negative: -coupon*days(settle,nxt)/days(prev,nxt). Otherwise accrued = coupon*days(prev,settle)/days(prev,nxt). coupon=100*rate/freq; round the final value to 6 decimals.

split: open-access


prompt:
Every positive accrual is one day of coupon too high.

Inputs prev, nxt, settle ([y,m,d]), annual rate, frequency and ex-coupon days. Settlement outside [prev, nxt] returns "settlement outside period"; settlement on nxt returns 0.0. If the settlement is within ex-coupon days of nxt (days to nxt <= exdays), accrued is negative: -coupon*days(settle,nxt)/days(prev,nxt). Otherwise accrued = coupon*days(prev,settle)/days(prev,nxt). coupon=100*rate/freq; round the final value to 6 decimals.

split: open-access


prompt:
Trades settling on the first ex-coupon day receive positive accrued interest.

Inputs prev, nxt, settle ([y,m,d]), annual rate, frequency and ex-coupon days. Settlement outside [prev, nxt] returns "settlement outside period"; settlement on nxt returns 0.0. If the settlement is within ex-coupon days of nxt (days to nxt <= exdays), accrued is negative: -coupon*days(settle,nxt)/days(prev,nxt). Otherwise accrued = coupon*days(prev,settle)/days(prev,nxt). coupon=100*rate/freq; round the final value to 6 decimals.

split: open-access


prompt:
Buyers in the ex-coupon window are charged interest they will never receive.

Inputs prev, nxt, settle ([y,m,d]), annual rate, frequency and ex-coupon days. Settlement outside [prev, nxt] returns "settlement outside period"; settlement on nxt returns 0.0. If the settlement is within ex-coupon days of nxt (days to nxt <= exdays), accrued is negative: -coupon*days(settle,nxt)/days(prev,nxt). Otherwise accrued = coupon*days(prev,settle)/days(prev,nxt). coupon=100*rate/freq; round the final value to 6 decimals.

split: open-access


prompt:
Accrued interest differs in the last decimals for long accrual periods.

Inputs prev, nxt, settle ([y,m,d]), annual rate, frequency and ex-coupon days. Settlement outside [prev, nxt] returns "settlement outside period"; settlement on nxt returns 0.0. If the settlement is within ex-coupon days of nxt (days to nxt <= exdays), accrued is negative: -coupon*days(settle,nxt)/days(prev,nxt). Otherwise accrued = coupon*days(prev,settle)/days(prev,nxt). coupon=100*rate/freq; round the final value to 6 decimals.

split: open-access


prompt:
Spans crossing from a non-leap year into a leap year divide leap-year days by 365.

Inputs start and end [y,m,d]. If end < start return "end before start". Split the interval at each 1 January; each piece contributes its actual days divided by 366 if the piece lies in a Gregorian leap year, else 365. Sum exactly and return the float rounded to 9 decimals.

split: open-access


prompt:
Pieces in 1900 or 2100 are divided by 366.

Inputs start and end [y,m,d]. If end < start return "end before start". Split the interval at each 1 January; each piece contributes its actual days divided by 366 if the piece lies in a Gregorian leap year, else 365. Sum exactly and return the float rounded to 9 decimals.

split: open-access


prompt:
Multi-year spans ignore the leap status of middle years.

Inputs start and end [y,m,d]. If end < start return "end before start". Split the interval at each 1 January; each piece contributes its actual days divided by 366 if the piece lies in a Gregorian leap year, else 365. Sum exactly and return the float rounded to 9 decimals.

split: open-access


source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(a, b):
    A = datetime.date(*a)
    B = datetime.date(*b)
    if B < A:
        return 'end before start'
    def leap(y):
        return (y % 4 == 0 and y % 100 != 0) or y % 400 == 0
    total = Fraction(0)
    cur = A
    has29 = any(leap(y) and A < datetime.date(y, 2, 29) <= B for y in range(A.year, B.year + 1))
    total = Fraction((B - A).days, 366 if has29 else 365)
    return round(float(total), 9)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression average year basis 1', [[2033, 2, 27], [2036, 11, 26]], 3.745474961], ['regression average year basis 2', [[1897, 9, 30], [1898, 3, 28]], 0.490410959], ['partial repair probe 1', [[2079, 11, 3], [2083, 11, 3]], 4.0], ['boundary control 1', [[2024, 3, 1], [2024, 3, 1]], 0.0], ['normal control 1', [[2059, 8, 30], [2059, 7, 23]], 'end before start'], ['normal control 2', [[2099, 12, 16], [2099, 11, 17]], 'end before start'], ['normal control 3', [[2103, 6, 16], [2103, 5, 8]], 'end before start'], ['normal control 4', [[1990, 7, 22], [1990, 7, 4]], 'end before start']], [['regression average year basis 1', [[2041, 1, 23], [2041, 8, 10]], 0.545205479], ['regression average year basis 2', [[1989, 1, 11], [1992, 10, 16]], 3.762220226], ['partial repair probe 1', [[2086, 2, 28], [2090, 1, 22]], 3.898630137], ['partial repair probe 2', [[2028, 12, 24], [2029, 10, 5]], 0.780762033], ['boundary control 1', [[2024, 3, 1], [2024, 3, 1]], 0.0], ['normal control 1', [[2041, 6, 30], [2041, 5, 29]], 'end before start'], ['normal control 2', [[1944, 6, 15], [1944, 5, 27]], 'end before start'], ['normal control 3', [[2087, 4, 19], [2087, 4, 4]], 'end before start']], [['regression average year basis 1', [[2045, 7, 24], [2046, 1, 10]], 0.465753425], ['regression average year basis 2', [[2104, 1, 17], [2104, 7, 25]], 0.519125683], ['partial repair probe 1', [[2096, 12, 31], [2099, 2, 8]], 2.106841829], ['partial repair probe 2', [[1936, 4, 23], [1937, 4, 22]], 0.99536642], ['boundary control 1', [[2024, 3, 1], [2024, 3, 1]], 0.0], ['normal control 1', [[2039, 3, 17], [2039, 2, 26]], 'end before start'], ['normal control 2', [[2031, 11, 17], [2031, 11, 9]], 'end before start'], ['normal control 3', [[2009, 8, 3], [2009, 6, 30]], 'end before start']], [['regression average year basis 1', [[2018, 9, 1], [2019, 9, 29]], 1.076712329], ['regression average year basis 2', [[2094, 2, 28], [2094, 6, 7]], 0.271232877], ['partial repair probe 1', [[1935, 10, 31], [1936, 4, 13]], 0.451283779], ['partial repair probe 2', [[2083, 5, 15], [2084, 6, 1]], 1.048177259], ['boundary control 1', [[2024, 3, 1], [2024, 3, 1]], 0.0], ['normal control 1', [[1908, 12, 13], [1908, 12, 12]], 'end before start'], ['normal control 2', [[1900, 4, 24], [1900, 4, 13]], 'end before start'], ['normal control 3', [[1994, 7, 29], [1994, 7, 14]], 'end before start']], [['regression average year basis 1', [[2058, 8, 14], [2064, 8, 8]], 5.98465454], ['regression average year basis 2', [[1980, 7, 11], [1983, 5, 22]], 2.861711206], ['partial repair probe 1', [[2088, 5, 30], [2088, 6, 2]], 0.008196721], ['partial repair probe 2', [[2027, 1, 9], [2032, 10, 24]], 5.789557602], ['boundary control 1', [[2024, 3, 1], [2024, 3, 1]], 0.0], ['normal control 1', [[2043, 5, 31], [2043, 4, 25]], 'end before start'], ['normal control 2', [[1960, 8, 1], [1960, 6, 27]], 'end before start'], ['normal control 3', [[2078, 1, 31], [2078, 1, 7]], 'end before start']]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Year fractions are close but not equal to the ISDA value for nearly every span.

Inputs start and end [y,m,d]. If end < start return "end before start". Split the interval at each 1 January; each piece contributes its actual days divided by 366 if the piece lies in a Gregorian leap year, else 365. Sum exactly and return the float rounded to 9 decimals.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(a, b):
    A = datetime.date(*a)
    B = datetime.date(*b)
    if B < A:
        A, B = B, A
    def leap(y):
        return (y % 4 == 0 and y % 100 != 0) or y % 400 == 0
    total = Fraction(0)
    cur = A
    while cur < B:
        nxt = min(B, datetime.date(cur.year + 1, 1, 1))
        total += Fraction((nxt - cur).days, 366 if leap(cur.year) else 365)
        cur = nxt
    return round(float(total), 9)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression reversed interval handling 1', [[2045, 10, 29], [2045, 10, 26]], 'end before start'], ['regression reversed interval handling 2', [[2093, 7, 30], [2093, 6, 25]], 'end before start'], ['partial repair probe 1', [[1925, 1, 13], [1924, 12, 14]], 'end before start'], ['partial repair probe 2', [[1922, 10, 16], [1922, 10, 9]], 'end before start'], ['boundary control 1', [[2024, 3, 1], [2024, 3, 1]], 0.0], ['boundary control 2', [[2024, 1, 1], [2025, 1, 1]], 1.0], ['normal control 1', [[1926, 2, 28], [1927, 1, 25]], 0.906849315], ['normal control 2', [[1960, 4, 12], [1961, 5, 15]], 1.088434763]], [['regression reversed interval handling 1', [[1916, 6, 29], [1916, 6, 19]], 'end before start'], ['regression reversed interval handling 2', [[2060, 7, 28], [2060, 6, 19]], 'end before start'], ['partial repair probe 1', [[2056, 2, 28], [2056, 1, 30]], 'end before start'], ['partial repair probe 2', [[1920, 8, 13], [1920, 7, 14]], 'end before start'], ['boundary control 1', [[2099, 12, 1], [2100, 3, 1]], 0.246575342], ['boundary control 2', [[2023, 12, 31], [2024, 1, 1]], 0.002739726], ['normal control 1', [[2061, 10, 31], [2062, 1, 9]], 0.191780822], ['normal control 2', [[2091, 5, 1], [2094, 3, 23]], 2.893150685]], [['regression reversed interval handling 1', [[2006, 3, 31], [2006, 2, 22]], 'end before start'], ['regression reversed interval handling 2', [[2045, 8, 19], [2045, 7, 31]], 'end before start'], ['partial repair probe 1', [[2006, 12, 29], [2006, 11, 27]], 'end before start'], ['partial repair probe 2', [[1950, 4, 8], [1950, 3, 6]], 'end before start'], ['boundary control 1', [[2024, 3, 1], [2024, 3, 1]], 0.0], ['boundary control 2', [[2023, 12, 31], [2024, 1, 1]], 0.002739726], ['normal control 1', [[2094, 3, 31], [2096, 2, 10]], 1.865454001], ['normal control 2', [[2061, 8, 20], [2067, 4, 16]], 5.654794521]], [['regression reversed interval handling 1', [[2094, 7, 1], [2094, 6, 30]], 'end before start'], ['regression reversed interval handling 2', [[2051, 10, 26], [2051, 9, 25]], 'end before start'], ['partial repair probe 1', [[2036, 10, 28], [2036, 9, 26]], 'end before start'], ['partial repair probe 2', [[1935, 6, 19], [1935, 6, 17]], 'end before start'], ['boundary control 1', [[2023, 12, 31], [2024, 1, 1]], 0.002739726], ['boundary control 2', [[2024, 1, 1], [2025, 1, 1]], 1.0], ['normal control 1', [[1910, 1, 6], [1914, 6, 27]], 4.471232877], ['normal control 2', [[2074, 6, 24], [2074, 7, 3]], 0.024657534]], [['regression reversed interval handling 1', [[2053, 9, 30], [2053, 9, 9]], 'end before start'], ['regression reversed interval handling 2', [[1939, 3, 31], [1939, 3, 29]], 'end before start'], ['partial repair probe 1', [[1939, 10, 1], [1939, 9, 3]], 'end before start'], ['partial repair probe 2', [[2067, 10, 31], [2067, 9, 22]], 'end before start'], ['boundary control 1', [[2024, 3, 1], [2024, 3, 1]], 0.0], ['boundary control 2', [[2023, 7, 1], [2024, 7, 1]], 1.001377349], ['normal control 1', [[1911, 4, 24], [1914, 11, 14]], 3.55890411], ['normal control 2', [[1976, 4, 7], [1977, 1, 18]], 0.78154802]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(a, b):
    A = datetime.date(*a)
    B = datetime.date(*b)
    if B < A:
        return 0.0
    def leap(y):
        return (y % 4 == 0 and y % 100 != 0) or y % 400 == 0
    total = Fraction(0)
    cur = A
    while cur < B:
        nxt = min(B, datetime.date(cur.year + 1, 1, 1))
        total += Fraction((nxt - cur).days, 366 if leap(cur.year) else 365)
        cur = nxt
    return round(float(total), 9)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression reversed interval handling 1', [[2045, 10, 29], [2045, 10, 26]], 'end before start'], ['regression reversed interval handling 2', [[2093, 7, 30], [2093, 6, 25]], 'end before start'], ['partial repair probe 1', [[1925, 1, 13], [1924, 12, 14]], 'end before start'], ['partial repair probe 2', [[1922, 10, 16], [1922, 10, 9]], 'end before start'], ['boundary control 1', [[2024, 3, 1], [2024, 3, 1]], 0.0], ['boundary control 2', [[2024, 1, 1], [2025, 1, 1]], 1.0], ['normal control 1', [[1926, 2, 28], [1927, 1, 25]], 0.906849315], ['normal control 2', [[1960, 4, 12], [1961, 5, 15]], 1.088434763]], [['regression reversed interval handling 1', [[1916, 6, 29], [1916, 6, 19]], 'end before start'], ['regression reversed interval handling 2', [[2060, 7, 28], [2060, 6, 19]], 'end before start'], ['partial repair probe 1', [[2056, 2, 28], [2056, 1, 30]], 'end before start'], ['partial repair probe 2', [[1920, 8, 13], [1920, 7, 14]], 'end before start'], ['boundary control 1', [[2099, 12, 1], [2100, 3, 1]], 0.246575342], ['boundary control 2', [[2023, 12, 31], [2024, 1, 1]], 0.002739726], ['normal control 1', [[2061, 10, 31], [2062, 1, 9]], 0.191780822], ['normal control 2', [[2091, 5, 1], [2094, 3, 23]], 2.893150685]], [['regression reversed interval handling 1', [[2006, 3, 31], [2006, 2, 22]], 'end before start'], ['regression reversed interval handling 2', [[2045, 8, 19], [2045, 7, 31]], 'end before start'], ['partial repair probe 1', [[2006, 12, 29], [2006, 11, 27]], 'end before start'], ['partial repair probe 2', [[1950, 4, 8], [1950, 3, 6]], 'end before start'], ['boundary control 1', [[2024, 3, 1], [2024, 3, 1]], 0.0], ['boundary control 2', [[2023, 12, 31], [2024, 1, 1]], 0.002739726], ['normal control 1', [[2094, 3, 31], [2096, 2, 10]], 1.865454001], ['normal control 2', [[2061, 8, 20], [2067, 4, 16]], 5.654794521]], [['regression reversed interval handling 1', [[2094, 7, 1], [2094, 6, 30]], 'end before start'], ['regression reversed interval handling 2', [[2051, 10, 26], [2051, 9, 25]], 'end before start'], ['partial repair probe 1', [[2036, 10, 28], [2036, 9, 26]], 'end before start'], ['partial repair probe 2', [[1935, 6, 19], [1935, 6, 17]], 'end before start'], ['boundary control 1', [[2023, 12, 31], [2024, 1, 1]], 0.002739726], ['boundary control 2', [[2024, 1, 1], [2025, 1, 1]], 1.0], ['normal control 1', [[1910, 1, 6], [1914, 6, 27]], 4.471232877], ['normal control 2', [[2074, 6, 24], [2074, 7, 3]], 0.024657534]], [['regression reversed interval handling 1', [[2053, 9, 30], [2053, 9, 9]], 'end before start'], ['regression reversed interval handling 2', [[1939, 3, 31], [1939, 3, 29]], 'end before start'], ['partial repair probe 1', [[1939, 10, 1], [1939, 9, 3]], 'end before start'], ['partial repair probe 2', [[2067, 10, 31], [2067, 9, 22]], 'end before start'], ['boundary control 1', [[2024, 3, 1], [2024, 3, 1]], 0.0], ['boundary control 2', [[2023, 7, 1], [2024, 7, 1]], 1.001377349], ['normal control 1', [[1911, 4, 24], [1914, 11, 14]], 3.55890411], ['normal control 2', [[1976, 4, 7], [1977, 1, 18]], 0.78154802]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Callers passing dates in the wrong order get a positive fraction instead of an error value.

Inputs start and end [y,m,d]. If end < start return "end before start". Split the interval at each 1 January; each piece contributes its actual days divided by 366 if the piece lies in a Gregorian leap year, else 365. Sum exactly and return the float rounded to 9 decimals.

split: open-access


prompt:
Annual periods beginning on a leap day and periods ending on one are classified the wrong way round.

Inputs start, end ([y,m,d]) and coupon frequency. Days are actual days. For annual frequency the denominator is 366 if any 29 February lies in (start, end], else 365. For other frequencies the denominator is 366 if the end date year is a leap year, else 365. Return days/denominator rounded to 9 decimals.

split: open-access


prompt:
Quarterly periods that begin in December before a leap year use 365 days.

Inputs start, end ([y,m,d]) and coupon frequency. Days are actual days. For annual frequency the denominator is 366 if any 29 February lies in (start, end], else 365. For other frequencies the denominator is 366 if the end date year is a leap year, else 365. Return days/denominator rounded to 9 decimals.

split: open-access


prompt:
An annual period ending in March of a leap year from March of the prior year is priced on 365 days.

Inputs start, end ([y,m,d]) and coupon frequency. Days are actual days. For annual frequency the denominator is 366 if any 29 February lies in (start, end], else 365. For other frequencies the denominator is 366 if the end date year is a leap year, else 365. Return days/denominator rounded to 9 decimals.

split: open-access


prompt:
An annual period ending after 29 February of a leap end year uses 365 days.

Inputs start, end ([y,m,d]) and coupon frequency. Days are actual days. For annual frequency the denominator is 366 if any 29 February lies in (start, end], else 365. For other frequencies the denominator is 366 if the end date year is a leap year, else 365. Return days/denominator rounded to 9 decimals.

split: open-access


prompt:
After passing a short month every earlier coupon date is stuck on the shorter day number.

Inputs issue and maturity [y,m,d], months per period and an end-of-month flag. Unadjusted coupon dates are generated backward from maturity: the k-th date is maturity shifted back k*months calendar months, keeping the maturity day clamped to the month length; if the flag is set and maturity is the last day of its month, every date is the last day of its month. Dates on or before issue are dropped. If more than one date remains and the first is fewer than 15 days after issue, it is removed (long first coupon). Return the dates ascending.

split: open-access


prompt:
Month-end maturities with the flag set produce coupons on the 28th or 30th instead of month end.

Inputs issue and maturity [y,m,d], months per period and an end-of-month flag. Unadjusted coupon dates are generated backward from maturity: the k-th date is maturity shifted back k*months calendar months, keeping the maturity day clamped to the month length; if the flag is set and maturity is the last day of its month, every date is the last day of its month. Dates on or before issue are dropped. If more than one date remains and the first is fewer than 15 days after issue, it is removed (long first coupon). Return the dates ascending.

split: open-access


prompt:
A bond issued less than 15 days before maturity reports an empty coupon schedule.

Inputs issue and maturity [y,m,d], months per period and an end-of-month flag. Unadjusted coupon dates are generated backward from maturity: the k-th date is maturity shifted back k*months calendar months, keeping the maturity day clamped to the month length; if the flag is set and maturity is the last day of its month, every date is the last day of its month. Dates on or before issue are dropped. If more than one date remains and the first is fewer than 15 days after issue, it is removed (long first coupon). Return the dates ascending.

split: open-access


prompt:
A 30 May maturity rolls to month ends while a 28 February maturity does not.

Inputs issue and maturity [y,m,d], months per period and an end-of-month flag. Unadjusted coupon dates are generated backward from maturity: the k-th date is maturity shifted back k*months calendar months, keeping the maturity day clamped to the month length; if the flag is set and maturity is the last day of its month, every date is the last day of its month. Dates on or before issue are dropped. If more than one date remains and the first is fewer than 15 days after issue, it is removed (long first coupon). Return the dates ascending.

split: open-access


prompt:
Short front stubs survive while normal first coupons can be discarded.

Inputs issue and maturity [y,m,d], months per period and an end-of-month flag. Unadjusted coupon dates are generated backward from maturity: the k-th date is maturity shifted back k*months calendar months, keeping the maturity day clamped to the month length; if the flag is set and maturity is the last day of its month, every date is the last day of its month. Dates on or before issue are dropped. If more than one date remains and the first is fewer than 15 days after issue, it is removed (long first coupon). Return the dates ascending.

split: open-access