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

N = 1
observations = []
def solve(x):
    end = x['period_end']
    add = 0
    sub = 0
    for it in x['items']:
        k = it['type']
        v = it['value']
        arrived = it['arrived_day'] is not None and it['arrived_day'] <= end
        if k == 'in_transit_in':
            if it['terms'] == 'FOB_shipping' and it['shipped_day'] <= end and not arrived:
                add += v
        elif k == 'in_transit_out':
            if it['terms'] == 'FOB_destination' and it['shipped_day'] <= end and not arrived:
                add += v
        elif k in ('consigned_in', 'bill_and_hold', 'consigned_out'):
            sub += v
    return {'adjusted': x['count_value'] + add - sub, 'adds': add, 'subtracts': sub}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 501, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10501, 'adds': 501, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 201, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5501, 'adds': 501, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 26}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 801, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 451, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9749, 'adds': 1200, 'subtracts': 451}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 351, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5549, 'adds': 0, 'subtracts': 451}], ['undelivered none', {'count_value': 100, 'period_end': 32, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]], [['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 502, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10502, 'adds': 502, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 202, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5502, 'adds': 502, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 27}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 802, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 452, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9748, 'adds': 1200, 'subtracts': 452}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 352, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5548, 'adds': 0, 'subtracts': 452}], ['undelivered none', {'count_value': 100, 'period_end': 33, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]], [['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 503, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10503, 'adds': 503, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 203, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5503, 'adds': 503, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 28}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 803, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 453, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9747, 'adds': 1200, 'subtracts': 453}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 353, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5547, 'adds': 0, 'subtracts': 453}], ['undelivered none', {'count_value': 100, 'period_end': 34, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]], [['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 504, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10504, 'adds': 504, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 204, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5504, 'adds': 504, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 29}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 804, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 454, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9746, 'adds': 1200, 'subtracts': 454}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 354, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5546, 'adds': 0, 'subtracts': 454}], ['undelivered none', {'count_value': 100, 'period_end': 35, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]], [['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 505, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10505, 'adds': 505, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 205, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5505, 'adds': 505, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 30}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 805, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 455, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9745, 'adds': 1200, 'subtracts': 455}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 355, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5545, 'adds': 0, 'subtracts': 455}], ['undelivered none', {'count_value': 100, 'period_end': 36, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    end = x['period_end']
    add = 0
    sub = 0
    for it in x['items']:
        k = it['type']
        v = it['value']
        arrived = it['arrived_day'] is not None and it['arrived_day'] <= end
        if k == 'in_transit_in':
            if it['terms'] == 'FOB_shipping' and it['shipped_day'] <= end and not arrived:
                add += v
        elif k == 'in_transit_out':
            if it['terms'] == 'FOB_destination' and it['shipped_day'] <= end and not arrived:
                add += v
        elif k in ('consigned_in', 'bill_and_hold'):
            sub += v
    return {'adjusted': x['count_value'] + add - sub, 'adds': add, 'subtracts': sub}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 501, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10501, 'adds': 501, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 201, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5501, 'adds': 501, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 26}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 801, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 451, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9749, 'adds': 1200, 'subtracts': 451}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 351, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5549, 'adds': 0, 'subtracts': 451}], ['undelivered none', {'count_value': 100, 'period_end': 32, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]], [['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 502, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10502, 'adds': 502, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 202, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5502, 'adds': 502, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 27}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 802, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 452, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9748, 'adds': 1200, 'subtracts': 452}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 352, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5548, 'adds': 0, 'subtracts': 452}], ['undelivered none', {'count_value': 100, 'period_end': 33, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]], [['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 503, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10503, 'adds': 503, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 203, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5503, 'adds': 503, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 28}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 803, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 453, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9747, 'adds': 1200, 'subtracts': 453}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 353, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5547, 'adds': 0, 'subtracts': 453}], ['undelivered none', {'count_value': 100, 'period_end': 34, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]], [['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 504, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10504, 'adds': 504, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 204, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5504, 'adds': 504, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 29}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 804, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 454, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9746, 'adds': 1200, 'subtracts': 454}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 354, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5546, 'adds': 0, 'subtracts': 454}], ['undelivered none', {'count_value': 100, 'period_end': 35, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]], [['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 505, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10505, 'adds': 505, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 205, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5505, 'adds': 505, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 30}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 805, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 455, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9745, 'adds': 1200, 'subtracts': 455}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 355, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5545, 'adds': 0, 'subtracts': 455}], ['undelivered none', {'count_value': 100, 'period_end': 36, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Goods held by consignees are deducted from inventory instead of added.

Input {count_value, period_end, items:[{type, terms, value, shipped_day, arrived_day|None}]}. Goods "arrived" when arrived_day is set and <= period_end. Inbound in transit is added when FOB_shipping, shipped by period end and not arrived. Outbound in transit is added back when FOB_destination, shipped by period end and not arrived. Goods consigned out are added; consigned-in and bill-and-hold goods (counted but not owned) are subtracted regardless of terms. Return {adjusted, adds, subtracts}.

split: open-access


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

N = 1
observations = []
def solve(x):
    end = x['period_end']
    add = 0
    sub = 0
    for it in x['items']:
        k = it['type']
        v = it['value']
        arrived = it['arrived_day'] is not None and it['arrived_day'] <= end
        if k == 'in_transit_in':
            if it['terms'] == 'FOB_shipping' and it['shipped_day'] <= end and not arrived:
                add += v
        elif k == 'in_transit_out':
            if it['terms'] == 'FOB_destination' and it['shipped_day'] <= end and not arrived:
                add += v
        elif k == 'consigned_out':
            add += v
        elif k == 'consigned_in':
            sub += v
    return {'adjusted': x['count_value'] + add - sub, 'adds': add, 'subtracts': sub}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 501, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10501, 'adds': 501, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 201, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5501, 'adds': 501, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 26}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 801, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 451, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9749, 'adds': 1200, 'subtracts': 451}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 351, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5549, 'adds': 0, 'subtracts': 451}], ['undelivered none', {'count_value': 100, 'period_end': 32, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]], [['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 502, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10502, 'adds': 502, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 202, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5502, 'adds': 502, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 27}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 802, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 452, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9748, 'adds': 1200, 'subtracts': 452}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 352, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5548, 'adds': 0, 'subtracts': 452}], ['undelivered none', {'count_value': 100, 'period_end': 33, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]], [['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 503, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10503, 'adds': 503, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 203, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5503, 'adds': 503, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 28}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 803, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 453, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9747, 'adds': 1200, 'subtracts': 453}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 353, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5547, 'adds': 0, 'subtracts': 453}], ['undelivered none', {'count_value': 100, 'period_end': 34, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]], [['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 504, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10504, 'adds': 504, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 204, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5504, 'adds': 504, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 29}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 804, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 454, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9746, 'adds': 1200, 'subtracts': 454}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 354, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5546, 'adds': 0, 'subtracts': 454}], ['undelivered none', {'count_value': 100, 'period_end': 35, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]], [['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 505, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10505, 'adds': 505, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 205, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5505, 'adds': 505, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 30}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 805, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 455, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9745, 'adds': 1200, 'subtracts': 455}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 355, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5545, 'adds': 0, 'subtracts': 455}], ['undelivered none', {'count_value': 100, 'period_end': 36, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    end = x['period_end']
    add = 0
    sub = 0
    for it in x['items']:
        k = it['type']
        v = it['value']
        arrived = it['arrived_day'] is not None and it['arrived_day'] <= end
        if k == 'in_transit_in':
            if it['terms'] == 'FOB_shipping' and it['shipped_day'] <= end and not arrived:
                add += v
        elif k == 'in_transit_out':
            if it['terms'] == 'FOB_destination' and it['shipped_day'] <= end and not arrived:
                add += v
        elif k == 'consigned_out':
            add += v
        elif k == 'consigned_in' or (k == 'bill_and_hold' and it['terms'] == 'FOB_shipping'):
            sub += v
    return {'adjusted': x['count_value'] + add - sub, 'adds': add, 'subtracts': sub}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 501, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10501, 'adds': 501, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 201, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5501, 'adds': 501, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 26}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 801, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 451, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9749, 'adds': 1200, 'subtracts': 451}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 351, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5549, 'adds': 0, 'subtracts': 451}], ['undelivered none', {'count_value': 100, 'period_end': 32, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]], [['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 502, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10502, 'adds': 502, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 202, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5502, 'adds': 502, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 27}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 802, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 452, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9748, 'adds': 1200, 'subtracts': 452}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 352, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5548, 'adds': 0, 'subtracts': 452}], ['undelivered none', {'count_value': 100, 'period_end': 33, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]], [['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 503, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10503, 'adds': 503, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 203, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5503, 'adds': 503, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 28}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 803, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 453, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9747, 'adds': 1200, 'subtracts': 453}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 353, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5547, 'adds': 0, 'subtracts': 453}], ['undelivered none', {'count_value': 100, 'period_end': 34, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]], [['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 504, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10504, 'adds': 504, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 204, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5504, 'adds': 504, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 29}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 804, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 454, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9746, 'adds': 1200, 'subtracts': 454}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 354, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5546, 'adds': 0, 'subtracts': 454}], ['undelivered none', {'count_value': 100, 'period_end': 35, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]], [['inbound shipping terms', {'count_value': 10000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 505, 'shipped_day': 30, 'arrived_day': None}, {'type': 'in_transit_in', 'terms': 'FOB_destination', 'value': 700, 'shipped_day': 29, 'arrived_day': 33}]}, {'adjusted': 10505, 'adds': 505, 'subtracts': 0}], ['shipped on period end', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 31, 'arrived_day': 34}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 205, 'shipped_day': 31, 'arrived_day': None}]}, {'adjusted': 5505, 'adds': 505, 'subtracts': 0}], ['shipped after period', {'count_value': 5000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 300, 'shipped_day': 32, 'arrived_day': 35}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 250, 'shipped_day': 32, 'arrived_day': None}]}, {'adjusted': 5000, 'adds': 0, 'subtracts': 0}], ['arrived before end', {'count_value': 8000, 'period_end': 31, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 400, 'shipped_day': 20, 'arrived_day': 30}, {'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 90, 'shipped_day': 28, 'arrived_day': 31}]}, {'adjusted': 8000, 'adds': 0, 'subtracts': 0}], ['outbound terms', {'count_value': 7000, 'period_end': 31, 'items': [{'type': 'in_transit_out', 'terms': 'FOB_destination', 'value': 600, 'shipped_day': 30, 'arrived_day': 32}, {'type': 'in_transit_out', 'terms': 'FOB_shipping', 'value': 805, 'shipped_day': 30, 'arrived_day': 33}]}, {'adjusted': 7600, 'adds': 600, 'subtracts': 0}], ['consignment', {'count_value': 9000, 'period_end': 31, 'items': [{'type': 'consigned_out', 'terms': 'none', 'value': 1200, 'shipped_day': 10, 'arrived_day': None}, {'type': 'consigned_in', 'terms': 'none', 'value': 455, 'shipped_day': 5, 'arrived_day': 6}]}, {'adjusted': 9745, 'adds': 1200, 'subtracts': 455}], ['bill and hold', {'count_value': 6000, 'period_end': 31, 'items': [{'type': 'bill_and_hold', 'terms': 'FOB_destination', 'value': 355, 'shipped_day': 0, 'arrived_day': None}, {'type': 'bill_and_hold', 'terms': 'FOB_shipping', 'value': 100, 'shipped_day': 0, 'arrived_day': None}]}, {'adjusted': 5545, 'adds': 0, 'subtracts': 455}], ['undelivered none', {'count_value': 100, 'period_end': 36, 'items': [{'type': 'in_transit_in', 'terms': 'FOB_shipping', 'value': 55, 'shipped_day': 12, 'arrived_day': None}]}, {'adjusted': 155, 'adds': 55, 'subtracts': 0}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Goods sold on bill-and-hold terms remain in inventory because they sit in the warehouse.

Input {count_value, period_end, items:[{type, terms, value, shipped_day, arrived_day|None}]}. Goods "arrived" when arrived_day is set and <= period_end. Inbound in transit is added when FOB_shipping, shipped by period end and not arrived. Outbound in transit is added back when FOB_destination, shipped by period end and not arrived. Goods consigned out are added; consigned-in and bill-and-hold goods (counted but not owned) are subtracted regardless of terms. Return {adjusted, adds, subtracts}.

split: open-access


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

N = 1
observations = []
def solve(x):
    elig = sum(l['amount'] for l in x['lines'])
    if elig < 500:
        return {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}
    base = elig // 100
    tier = base * {'base': 100, 'silver': 125, 'gold': 150}[x['tier']] // 100
    bonus = 0
    for cat, mult in sorted(x['promo'].items()):
        if cat == 'giftcard':
            continue
        amt = sum(l['amount'] for l in x['lines'] if l['cat'] == cat)
        bonus += (amt // 100) * (mult - 1)
    bonus = min(bonus, 1000)
    return {'base': base, 'tier': tier, 'bonus': bonus, 'total': tier + bonus}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain order', {'lines': [{'cat': 'grocery', 'amount': 2350}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 851}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1399}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 13, 'tier': 16, 'bonus': 0, 'total': 16}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 41, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 2500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 61000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 620, 'tier': 620, 'bonus': 1000, 'total': 1620}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 200}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3326}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2351}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 852}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1499}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 14, 'tier': 17, 'bonus': 0, 'total': 17}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 42, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 5000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 62000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 630, 'tier': 630, 'bonus': 1000, 'total': 1630}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 201}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3327}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2352}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 853}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1599}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 15, 'tier': 18, 'bonus': 0, 'total': 18}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 43, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 7500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 63000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 640, 'tier': 640, 'bonus': 1000, 'total': 1640}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 202}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3328}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2353}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 854}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1699}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 16, 'tier': 20, 'bonus': 0, 'total': 20}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 44, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 10000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 64000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 650, 'tier': 650, 'bonus': 1000, 'total': 1650}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 203}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3329}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2354}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 855}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1799}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 17, 'tier': 21, 'bonus': 0, 'total': 21}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 45, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 12500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 65000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 660, 'tier': 660, 'bonus': 1000, 'total': 1660}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 204}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3330}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]]]
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):
    elig = sum(l['amount'] for l in x['lines'] if l['cat'] != 'giftcard')
    if elig < 500:
        return {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}
    base = sum(l['amount'] for l in x['lines']) // 100
    tier = base * {'base': 100, 'silver': 125, 'gold': 150}[x['tier']] // 100
    bonus = 0
    for cat, mult in sorted(x['promo'].items()):
        if cat == 'giftcard':
            continue
        amt = sum(l['amount'] for l in x['lines'] if l['cat'] == cat)
        bonus += (amt // 100) * (mult - 1)
    bonus = min(bonus, 1000)
    return {'base': base, 'tier': tier, 'bonus': bonus, 'total': tier + bonus}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain order', {'lines': [{'cat': 'grocery', 'amount': 2350}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 851}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1399}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 13, 'tier': 16, 'bonus': 0, 'total': 16}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 41, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 2500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 61000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 620, 'tier': 620, 'bonus': 1000, 'total': 1620}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 200}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3326}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2351}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 852}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1499}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 14, 'tier': 17, 'bonus': 0, 'total': 17}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 42, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 5000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 62000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 630, 'tier': 630, 'bonus': 1000, 'total': 1630}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 201}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3327}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2352}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 853}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1599}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 15, 'tier': 18, 'bonus': 0, 'total': 18}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 43, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 7500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 63000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 640, 'tier': 640, 'bonus': 1000, 'total': 1640}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 202}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3328}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2353}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 854}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1699}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 16, 'tier': 20, 'bonus': 0, 'total': 20}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 44, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 10000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 64000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 650, 'tier': 650, 'bonus': 1000, 'total': 1650}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 203}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3329}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2354}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 855}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1799}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 17, 'tier': 21, 'bonus': 0, 'total': 21}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 45, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 12500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 65000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 660, 'tier': 660, 'bonus': 1000, 'total': 1660}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 204}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3330}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]]]
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:
Members earn points on gift card purchases, which later earn again when the card is spent.

Input {lines:[{cat,amount cents}], tax, shipping, tier, promo:{cat:multiplier}}. Eligible spend = non-giftcard line amounts (tax and shipping never earn). Eligible spend below 500 cents earns nothing. Base = floor(eligible/100) computed once per order. Tier points = floor(base*pct/100) with pct base 100, silver 125, gold 150. Promo bonus per non-giftcard category = floor(category spend/100)*(multiplier-1); the order bonus is capped at 1000. Return {base, tier, bonus, total}.

split: open-access


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

N = 1
observations = []
def solve(x):
    elig = sum(l['amount'] for l in x['lines'] if l['cat'] != 'giftcard') + x['tax'] + x['shipping']
    if elig < 500:
        return {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}
    base = elig // 100
    tier = base * {'base': 100, 'silver': 125, 'gold': 150}[x['tier']] // 100
    bonus = 0
    for cat, mult in sorted(x['promo'].items()):
        if cat == 'giftcard':
            continue
        amt = sum(l['amount'] for l in x['lines'] if l['cat'] == cat)
        bonus += (amt // 100) * (mult - 1)
    bonus = min(bonus, 1000)
    return {'base': base, 'tier': tier, 'bonus': bonus, 'total': tier + bonus}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain order', {'lines': [{'cat': 'grocery', 'amount': 2350}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 851}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1399}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 13, 'tier': 16, 'bonus': 0, 'total': 16}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 41, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 2500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 61000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 620, 'tier': 620, 'bonus': 1000, 'total': 1620}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 200}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3326}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2351}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 852}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1499}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 14, 'tier': 17, 'bonus': 0, 'total': 17}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 42, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 5000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 62000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 630, 'tier': 630, 'bonus': 1000, 'total': 1630}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 201}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3327}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2352}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 853}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1599}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 15, 'tier': 18, 'bonus': 0, 'total': 18}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 43, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 7500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 63000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 640, 'tier': 640, 'bonus': 1000, 'total': 1640}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 202}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3328}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2353}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 854}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1699}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 16, 'tier': 20, 'bonus': 0, 'total': 20}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 44, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 10000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 64000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 650, 'tier': 650, 'bonus': 1000, 'total': 1650}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 203}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3329}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2354}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 855}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1799}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 17, 'tier': 21, 'bonus': 0, 'total': 21}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 45, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 12500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 65000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 660, 'tier': 660, 'bonus': 1000, 'total': 1660}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 204}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3330}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]]]
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):
    elig = sum(l['amount'] for l in x['lines'] if l['cat'] != 'giftcard') + x['shipping']
    if elig < 500:
        return {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}
    base = elig // 100
    tier = base * {'base': 100, 'silver': 125, 'gold': 150}[x['tier']] // 100
    bonus = 0
    for cat, mult in sorted(x['promo'].items()):
        if cat == 'giftcard':
            continue
        amt = sum(l['amount'] for l in x['lines'] if l['cat'] == cat)
        bonus += (amt // 100) * (mult - 1)
    bonus = min(bonus, 1000)
    return {'base': base, 'tier': tier, 'bonus': bonus, 'total': tier + bonus}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain order', {'lines': [{'cat': 'grocery', 'amount': 2350}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 851}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1399}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 13, 'tier': 16, 'bonus': 0, 'total': 16}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 41, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 2500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 61000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 620, 'tier': 620, 'bonus': 1000, 'total': 1620}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 200}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3326}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2351}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 852}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1499}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 14, 'tier': 17, 'bonus': 0, 'total': 17}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 42, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 5000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 62000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 630, 'tier': 630, 'bonus': 1000, 'total': 1630}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 201}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3327}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2352}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 853}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1599}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 15, 'tier': 18, 'bonus': 0, 'total': 18}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 43, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 7500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 63000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 640, 'tier': 640, 'bonus': 1000, 'total': 1640}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 202}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3328}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2353}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 854}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1699}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 16, 'tier': 20, 'bonus': 0, 'total': 20}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 44, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 10000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 64000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 650, 'tier': 650, 'bonus': 1000, 'total': 1650}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 203}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3329}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2354}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 855}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1799}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 17, 'tier': 21, 'bonus': 0, 'total': 21}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 45, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 12500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 65000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 660, 'tier': 660, 'bonus': 1000, 'total': 1660}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 204}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3330}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]]]
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:
Tax and shipping charges earn points.

Input {lines:[{cat,amount cents}], tax, shipping, tier, promo:{cat:multiplier}}. Eligible spend = non-giftcard line amounts (tax and shipping never earn). Eligible spend below 500 cents earns nothing. Base = floor(eligible/100) computed once per order. Tier points = floor(base*pct/100) with pct base 100, silver 125, gold 150. Promo bonus per non-giftcard category = floor(category spend/100)*(multiplier-1); the order bonus is capped at 1000. Return {base, tier, bonus, total}.

split: open-access