broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    prev=x['prior']; out=[]
    for ind,changed in x['years']:
        if ind is None:
            out.append(None); prev=0; continue
        if changed or prev==0:
            cur=ind
        else:
            hi=math.floor(Fraction(ind*(1000+x['up']),1000)+Fraction(1,2))
            lo=math.floor(Fraction(prev*(1000-x['down']),1000)+Fraction(1,2))
            cur=max(lo,min(hi,ind))
        out.append(cur); prev=cur
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['large increase phased in', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[282332, False], [282332, False], [282332, False]]}, [156694, 173930, 193062]], ['large decrease capped', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[70583, False], [70583, False]]}, [134108, 127403]], ['coverage change exempt then capped', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[282332, True], [423498, False]]}, [282332, 313389]], ['new business exempt', {'prior': 0, 'up': 110, 'down': 50, 'years': [[141166, False], [282332, False]]}, [141166, 156694]], ['lapse restarts as new business', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[141166, False], [None, False], [423498, False]]}, [141166, None, 423498]], ['within caps', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[142166, False], [140166, False]]}, [142166, 140166]], ['mixed history', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[172018, False], [166564, False], [197332, False], [213340, False]]}, [156694, 166564, 184886, 205223]]], [['large increase phased in', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[163834, False], [163834, False], [163834, False]]}, [91747, 102757, 115088]], ['large decrease capped', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[40958, False], [40958, False]]}, [77821, 73930]], ['coverage change exempt then capped', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[163834, True], [245751, False]]}, [163834, 183494]], ['new business exempt', {'prior': 0, 'up': 120, 'down': 50, 'years': [[81917, False], [163834, False]]}, [81917, 91747]], ['lapse restarts as new business', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[81917, False], [None, False], [245751, False]]}, [81917, None, 245751]], ['within caps', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[82917, False], [80917, False]]}, [82917, 80917]], ['mixed history', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[92584, False], [202024, False], [62931, True], [150823, False]]}, [91747, 102757, 62931, 70483]]], [['large increase phased in', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[280726, False], [280726, False], [280726, False]]}, [158610, 179229, 202529]], ['large decrease capped', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[70181, False], [70181, False]]}, [133345, 126678]], ['coverage change exempt then capped', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[280726, True], [421089, False]]}, [280726, 317220]], ['new business exempt', {'prior': 0, 'up': 130, 'down': 50, 'years': [[140363, False], [280726, False]]}, [140363, 158610]], ['lapse restarts as new business', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[140363, False], [None, False], [421089, False]]}, [140363, None, 421089]], ['within caps', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[141363, False], [139363, False]]}, [141363, 139363]], ['mixed history', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[224001, True], [54488, False], [53043, False], [82834, False]]}, [224001, 212801, 202161, 192053]]], [['large increase phased in', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[262850, False], [262850, False], [262850, False]]}, [149825, 170801, 194713]], ['large decrease capped', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[65712, False], [65712, False]]}, [124854, 118611]], ['coverage change exempt then capped', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[262850, True], [394275, False]]}, [262850, 299649]], ['new business exempt', {'prior': 0, 'up': 140, 'down': 50, 'years': [[131425, False], [262850, False]]}, [131425, 149825]], ['lapse restarts as new business', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[131425, False], [None, False], [394275, False]]}, [131425, None, 394275]], ['within caps', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[132425, False], [130425, False]]}, [132425, 130425]], ['mixed history', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[105255, True], [201448, True], [175992, True], [84220, False]]}, [105255, 201448, 175992, 167192]]], [['large increase phased in', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[258006, False], [258006, False], [258006, False]]}, [148353, 170606, 196197]], ['large decrease capped', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[64501, False], [64501, False]]}, [122553, 116425]], ['coverage change exempt then capped', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[258006, True], [387009, False]]}, [258006, 296707]], ['new business exempt', {'prior': 0, 'up': 150, 'down': 50, 'years': [[129003, False], [258006, False]]}, [129003, 148353]], ['lapse restarts as new business', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[129003, False], [None, False], [387009, False]]}, [129003, None, 387009]], ['within caps', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[130003, False], [128003, False]]}, [130003, 128003]], ['mixed history', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[151965, False], [114334, False], [235286, False], [180318, True]]}, [148353, 140935, 162075, 180318]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    prev=x['prior']; out=[]
    for ind,changed in x['years']:
        if ind is None:
            out.append(None); prev=0; continue
        if changed or prev==0:
            cur=ind
        else:
            hi=math.floor(Fraction((prev+ind)//2*(1000+x['up']),1000)+Fraction(1,2))
            lo=math.floor(Fraction(prev*(1000-x['down']),1000)+Fraction(1,2))
            cur=max(lo,min(hi,ind))
        out.append(cur); prev=cur
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['large increase phased in', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[282332, False], [282332, False], [282332, False]]}, [156694, 173930, 193062]], ['large decrease capped', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[70583, False], [70583, False]]}, [134108, 127403]], ['coverage change exempt then capped', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[282332, True], [423498, False]]}, [282332, 313389]], ['new business exempt', {'prior': 0, 'up': 110, 'down': 50, 'years': [[141166, False], [282332, False]]}, [141166, 156694]], ['lapse restarts as new business', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[141166, False], [None, False], [423498, False]]}, [141166, None, 423498]], ['within caps', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[142166, False], [140166, False]]}, [142166, 140166]], ['mixed history', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[172018, False], [166564, False], [197332, False], [213340, False]]}, [156694, 166564, 184886, 205223]]], [['large increase phased in', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[163834, False], [163834, False], [163834, False]]}, [91747, 102757, 115088]], ['large decrease capped', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[40958, False], [40958, False]]}, [77821, 73930]], ['coverage change exempt then capped', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[163834, True], [245751, False]]}, [163834, 183494]], ['new business exempt', {'prior': 0, 'up': 120, 'down': 50, 'years': [[81917, False], [163834, False]]}, [81917, 91747]], ['lapse restarts as new business', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[81917, False], [None, False], [245751, False]]}, [81917, None, 245751]], ['within caps', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[82917, False], [80917, False]]}, [82917, 80917]], ['mixed history', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[92584, False], [202024, False], [62931, True], [150823, False]]}, [91747, 102757, 62931, 70483]]], [['large increase phased in', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[280726, False], [280726, False], [280726, False]]}, [158610, 179229, 202529]], ['large decrease capped', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[70181, False], [70181, False]]}, [133345, 126678]], ['coverage change exempt then capped', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[280726, True], [421089, False]]}, [280726, 317220]], ['new business exempt', {'prior': 0, 'up': 130, 'down': 50, 'years': [[140363, False], [280726, False]]}, [140363, 158610]], ['lapse restarts as new business', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[140363, False], [None, False], [421089, False]]}, [140363, None, 421089]], ['within caps', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[141363, False], [139363, False]]}, [141363, 139363]], ['mixed history', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[224001, True], [54488, False], [53043, False], [82834, False]]}, [224001, 212801, 202161, 192053]]], [['large increase phased in', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[262850, False], [262850, False], [262850, False]]}, [149825, 170801, 194713]], ['large decrease capped', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[65712, False], [65712, False]]}, [124854, 118611]], ['coverage change exempt then capped', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[262850, True], [394275, False]]}, [262850, 299649]], ['new business exempt', {'prior': 0, 'up': 140, 'down': 50, 'years': [[131425, False], [262850, False]]}, [131425, 149825]], ['lapse restarts as new business', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[131425, False], [None, False], [394275, False]]}, [131425, None, 394275]], ['within caps', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[132425, False], [130425, False]]}, [132425, 130425]], ['mixed history', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[105255, True], [201448, True], [175992, True], [84220, False]]}, [105255, 201448, 175992, 167192]]], [['large increase phased in', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[258006, False], [258006, False], [258006, False]]}, [148353, 170606, 196197]], ['large decrease capped', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[64501, False], [64501, False]]}, [122553, 116425]], ['coverage change exempt then capped', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[258006, True], [387009, False]]}, [258006, 296707]], ['new business exempt', {'prior': 0, 'up': 150, 'down': 50, 'years': [[129003, False], [258006, False]]}, [129003, 148353]], ['lapse restarts as new business', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[129003, False], [None, False], [387009, False]]}, [129003, None, 387009]], ['within caps', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[130003, False], [128003, False]]}, [130003, 128003]], ['mixed history', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[151965, False], [114334, False], [235286, False], [180318, True]]}, [148353, 140935, 162075, 180318]]]]
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:
Increases are never capped.

Input prior premium (0 = new business), up/down caps per mille, years [[indicated or None for a lapse, coverage_changed]]. A lapse outputs None and the next year is new business. New business or coverage changes charge the indicated premium; otherwise charge the indicated premium clamped to [prev*(1-down), prev*(1+up)] with bounds rounded half-up, where prev is last year's charged premium.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    prev=x['prior']; out=[]
    for ind,changed in x['years']:
        if ind is None:
            out.append(None); continue
        if changed or prev==0:
            cur=ind
        else:
            hi=math.floor(Fraction(prev*(1000+x['up']),1000)+Fraction(1,2))
            lo=math.floor(Fraction(prev*(1000-x['down']),1000)+Fraction(1,2))
            cur=max(lo,min(hi,ind))
        out.append(cur); prev=cur
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['large increase phased in', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[282332, False], [282332, False], [282332, False]]}, [156694, 173930, 193062]], ['large decrease capped', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[70583, False], [70583, False]]}, [134108, 127403]], ['coverage change exempt then capped', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[282332, True], [423498, False]]}, [282332, 313389]], ['new business exempt', {'prior': 0, 'up': 110, 'down': 50, 'years': [[141166, False], [282332, False]]}, [141166, 156694]], ['lapse restarts as new business', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[141166, False], [None, False], [423498, False]]}, [141166, None, 423498]], ['within caps', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[142166, False], [140166, False]]}, [142166, 140166]], ['mixed history', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[172018, False], [166564, False], [197332, False], [213340, False]]}, [156694, 166564, 184886, 205223]]], [['large increase phased in', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[163834, False], [163834, False], [163834, False]]}, [91747, 102757, 115088]], ['large decrease capped', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[40958, False], [40958, False]]}, [77821, 73930]], ['coverage change exempt then capped', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[163834, True], [245751, False]]}, [163834, 183494]], ['new business exempt', {'prior': 0, 'up': 120, 'down': 50, 'years': [[81917, False], [163834, False]]}, [81917, 91747]], ['lapse restarts as new business', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[81917, False], [None, False], [245751, False]]}, [81917, None, 245751]], ['within caps', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[82917, False], [80917, False]]}, [82917, 80917]], ['mixed history', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[92584, False], [202024, False], [62931, True], [150823, False]]}, [91747, 102757, 62931, 70483]]], [['large increase phased in', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[280726, False], [280726, False], [280726, False]]}, [158610, 179229, 202529]], ['large decrease capped', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[70181, False], [70181, False]]}, [133345, 126678]], ['coverage change exempt then capped', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[280726, True], [421089, False]]}, [280726, 317220]], ['new business exempt', {'prior': 0, 'up': 130, 'down': 50, 'years': [[140363, False], [280726, False]]}, [140363, 158610]], ['lapse restarts as new business', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[140363, False], [None, False], [421089, False]]}, [140363, None, 421089]], ['within caps', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[141363, False], [139363, False]]}, [141363, 139363]], ['mixed history', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[224001, True], [54488, False], [53043, False], [82834, False]]}, [224001, 212801, 202161, 192053]]], [['large increase phased in', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[262850, False], [262850, False], [262850, False]]}, [149825, 170801, 194713]], ['large decrease capped', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[65712, False], [65712, False]]}, [124854, 118611]], ['coverage change exempt then capped', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[262850, True], [394275, False]]}, [262850, 299649]], ['new business exempt', {'prior': 0, 'up': 140, 'down': 50, 'years': [[131425, False], [262850, False]]}, [131425, 149825]], ['lapse restarts as new business', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[131425, False], [None, False], [394275, False]]}, [131425, None, 394275]], ['within caps', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[132425, False], [130425, False]]}, [132425, 130425]], ['mixed history', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[105255, True], [201448, True], [175992, True], [84220, False]]}, [105255, 201448, 175992, 167192]]], [['large increase phased in', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[258006, False], [258006, False], [258006, False]]}, [148353, 170606, 196197]], ['large decrease capped', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[64501, False], [64501, False]]}, [122553, 116425]], ['coverage change exempt then capped', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[258006, True], [387009, False]]}, [258006, 296707]], ['new business exempt', {'prior': 0, 'up': 150, 'down': 50, 'years': [[129003, False], [258006, False]]}, [129003, 148353]], ['lapse restarts as new business', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[129003, False], [None, False], [387009, False]]}, [129003, None, 387009]], ['within caps', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[130003, False], [128003, False]]}, [130003, 128003]], ['mixed history', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[151965, False], [114334, False], [235286, False], [180318, True]]}, [148353, 140935, 162075, 180318]]]]
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
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    prev=x['prior']; out=[]
    for ind,changed in x['years']:
        if ind is None:
            out.append(None); prev=x['prior']; continue
        if changed or prev==0:
            cur=ind
        else:
            hi=math.floor(Fraction(prev*(1000+x['up']),1000)+Fraction(1,2))
            lo=math.floor(Fraction(prev*(1000-x['down']),1000)+Fraction(1,2))
            cur=max(lo,min(hi,ind))
        out.append(cur); prev=cur
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['large increase phased in', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[282332, False], [282332, False], [282332, False]]}, [156694, 173930, 193062]], ['large decrease capped', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[70583, False], [70583, False]]}, [134108, 127403]], ['coverage change exempt then capped', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[282332, True], [423498, False]]}, [282332, 313389]], ['new business exempt', {'prior': 0, 'up': 110, 'down': 50, 'years': [[141166, False], [282332, False]]}, [141166, 156694]], ['lapse restarts as new business', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[141166, False], [None, False], [423498, False]]}, [141166, None, 423498]], ['within caps', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[142166, False], [140166, False]]}, [142166, 140166]], ['mixed history', {'prior': 141166, 'up': 110, 'down': 50, 'years': [[172018, False], [166564, False], [197332, False], [213340, False]]}, [156694, 166564, 184886, 205223]]], [['large increase phased in', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[163834, False], [163834, False], [163834, False]]}, [91747, 102757, 115088]], ['large decrease capped', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[40958, False], [40958, False]]}, [77821, 73930]], ['coverage change exempt then capped', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[163834, True], [245751, False]]}, [163834, 183494]], ['new business exempt', {'prior': 0, 'up': 120, 'down': 50, 'years': [[81917, False], [163834, False]]}, [81917, 91747]], ['lapse restarts as new business', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[81917, False], [None, False], [245751, False]]}, [81917, None, 245751]], ['within caps', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[82917, False], [80917, False]]}, [82917, 80917]], ['mixed history', {'prior': 81917, 'up': 120, 'down': 50, 'years': [[92584, False], [202024, False], [62931, True], [150823, False]]}, [91747, 102757, 62931, 70483]]], [['large increase phased in', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[280726, False], [280726, False], [280726, False]]}, [158610, 179229, 202529]], ['large decrease capped', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[70181, False], [70181, False]]}, [133345, 126678]], ['coverage change exempt then capped', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[280726, True], [421089, False]]}, [280726, 317220]], ['new business exempt', {'prior': 0, 'up': 130, 'down': 50, 'years': [[140363, False], [280726, False]]}, [140363, 158610]], ['lapse restarts as new business', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[140363, False], [None, False], [421089, False]]}, [140363, None, 421089]], ['within caps', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[141363, False], [139363, False]]}, [141363, 139363]], ['mixed history', {'prior': 140363, 'up': 130, 'down': 50, 'years': [[224001, True], [54488, False], [53043, False], [82834, False]]}, [224001, 212801, 202161, 192053]]], [['large increase phased in', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[262850, False], [262850, False], [262850, False]]}, [149825, 170801, 194713]], ['large decrease capped', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[65712, False], [65712, False]]}, [124854, 118611]], ['coverage change exempt then capped', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[262850, True], [394275, False]]}, [262850, 299649]], ['new business exempt', {'prior': 0, 'up': 140, 'down': 50, 'years': [[131425, False], [262850, False]]}, [131425, 149825]], ['lapse restarts as new business', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[131425, False], [None, False], [394275, False]]}, [131425, None, 394275]], ['within caps', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[132425, False], [130425, False]]}, [132425, 130425]], ['mixed history', {'prior': 131425, 'up': 140, 'down': 50, 'years': [[105255, True], [201448, True], [175992, True], [84220, False]]}, [105255, 201448, 175992, 167192]]], [['large increase phased in', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[258006, False], [258006, False], [258006, False]]}, [148353, 170606, 196197]], ['large decrease capped', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[64501, False], [64501, False]]}, [122553, 116425]], ['coverage change exempt then capped', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[258006, True], [387009, False]]}, [258006, 296707]], ['new business exempt', {'prior': 0, 'up': 150, 'down': 50, 'years': [[129003, False], [258006, False]]}, [129003, 148353]], ['lapse restarts as new business', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[129003, False], [None, False], [387009, False]]}, [129003, None, 387009]], ['within caps', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[130003, False], [128003, False]]}, [130003, 128003]], ['mixed history', {'prior': 129003, 'up': 150, 'down': 50, 'years': [[151965, False], [114334, False], [235286, False], [180318, True]]}, [148353, 140935, 162075, 180318]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A reinstated policy after a lapse is capped against its old premium.

Input prior premium (0 = new business), up/down caps per mille, years [[indicated or None for a lapse, coverage_changed]]. A lapse outputs None and the next year is new business. New business or coverage changes charge the indicated premium; otherwise charge the indicated premium clamped to [prev*(1-down), prev*(1+up)] with bounds rounded half-up, where prev is last year's charged premium.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    m=x['annual_miles']
    if m<=5000: band=Fraction(85,100)
    elif m<10000: band=Fraction(1)
    elif m<=15000: band=Fraction(110,100)
    else: band=Fraction(125,100)
    trips=x['trips']
    if len(trips)>=x['min_trips']:
        miles=sum(t[0] for t in trips); brakes=sum(t[1] for t in trips)
        bp=Fraction(brakes*100,miles) if miles else Fraction(0)
        disc=max(-100,min(300,300-50*bp))
    elif trips:
        disc=Fraction(50)
    else:
        disc=Fraction(0)
    return math.floor(x['base']*band*(1000-disc)/1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mileage 10000 boundary', {'base': 91494, 'annual_miles': 10000, 'trips': [[9, 0], [23, 1], [20, 0], [13, 1], [26, 0], [39, 1]], 'min_trips': 5}, 74603], ['mileage 10300', {'base': 82749, 'annual_miles': 10300, 'trips': [[30, 0], [20, 0], [15, 0], [29, 0], [14, 0], [8, 2], [23, 0]], 'min_trips': 5}, 70265], ['careful driver', {'base': 163637, 'annual_miles': 7341, 'trips': [[30, 1], [8, 2], [6, 0], [14, 2], [39, 2], [11, 1], [14, 1], [28, 1]], 'min_trips': 5}, 169092], ['harsh braker surcharged', {'base': 91954, 'annual_miles': 14146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 111264], ['uneven trip lengths', {'base': 158528, 'annual_miles': 2875, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 115055], ['exactly minimum trips', {'base': 104301, 'annual_miles': 17231, 'trips': [[5, 2], [19, 0], [32, 0], [19, 0], [8, 2]], 'min_trips': 5}, 122679], ['few trips participation', {'base': 97679, 'annual_miles': 12000, 'trips': [[16, 1], [7, 2], [36, 1]], 'min_trips': 5}, 102075], ['no trips', {'base': 134485, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 114312]], [['mileage 10000 boundary', {'base': 191368, 'annual_miles': 10000, 'trips': [[27, 0], [10, 0], [40, 1], [30, 2], [32, 1], [25, 2]], 'min_trips': 5}, 168964], ['mileage 10300', {'base': 105555, 'annual_miles': 10300, 'trips': [[29, 1], [13, 0], [15, 1], [29, 0], [39, 0], [15, 2], [17, 1]], 'min_trips': 5}, 99766], ['careful driver', {'base': 102660, 'annual_miles': 8401, 'trips': [[3, 1], [19, 0], [12, 2], [23, 0], [4, 0], [9, 0], [37, 2], [3, 1]], 'min_trips': 5}, 99860], ['harsh braker surcharged', {'base': 180490, 'annual_miles': 14814, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 218393], ['uneven trip lengths', {'base': 153152, 'annual_miles': 2570, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 111153], ['exactly minimum trips', {'base': 128499, 'annual_miles': 20368, 'trips': [[14, 0], [32, 2], [33, 0], [37, 2], [39, 0]], 'min_trips': 5}, 133162], ['few trips participation', {'base': 120795, 'annual_miles': 12000, 'trips': [[24, 0], [17, 2], [14, 2]], 'min_trips': 5}, 126231], ['no trips', {'base': 91464, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 77744]], [['mileage 10000 boundary', {'base': 137312, 'annual_miles': 10000, 'trips': [[17, 0], [26, 0], [22, 0], [27, 0], [31, 0], [14, 0]], 'min_trips': 5}, 96118], ['mileage 10300', {'base': 96030, 'annual_miles': 10300, 'trips': [[16, 0], [14, 2], [3, 2], [27, 2], [34, 2], [28, 0], [15, 1]], 'min_trips': 5}, 108640], ['careful driver', {'base': 119620, 'annual_miles': 6579, 'trips': [[37, 0], [24, 1], [19, 0], [4, 2], [18, 0], [38, 0], [13, 0], [28, 1]], 'min_trips': 5}, 96952], ['harsh braker surcharged', {'base': 69899, 'annual_miles': 13431, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 84578], ['uneven trip lengths', {'base': 78689, 'annual_miles': 3827, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 57110], ['exactly minimum trips', {'base': 151953, 'annual_miles': 21023, 'trips': [[11, 2], [21, 0], [12, 1], [31, 1], [34, 0]], 'min_trips': 5}, 167810], ['few trips participation', {'base': 175401, 'annual_miles': 12000, 'trips': [[4, 0], [3, 1], [16, 0]], 'min_trips': 5}, 183294], ['no trips', {'base': 63313, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 53816]], [['mileage 10000 boundary', {'base': 97658, 'annual_miles': 10000, 'trips': [[3, 0], [31, 0], [16, 0], [17, 2], [9, 0], [6, 2]], 'min_trips': 5}, 92180], ['mileage 10300', {'base': 197346, 'annual_miles': 10300, 'trips': [[29, 0], [26, 2], [5, 0], [24, 0], [37, 0], [26, 2], [36, 0]], 'min_trips': 5}, 175681], ['careful driver', {'base': 162245, 'annual_miles': 5217, 'trips': [[20, 0], [35, 0], [30, 0], [10, 0], [31, 0], [11, 0], [34, 1], [21, 0]], 'min_trips': 5}, 117797], ['harsh braker surcharged', {'base': 110905, 'annual_miles': 12698, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 134195], ['uneven trip lengths', {'base': 170601, 'annual_miles': 3861, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 123817], ['exactly minimum trips', {'base': 139426, 'annual_miles': 27324, 'trips': [[7, 1], [31, 1], [40, 2], [10, 2], [19, 1]], 'min_trips': 5}, 179006], ['few trips participation', {'base': 116838, 'annual_miles': 12000, 'trips': [[6, 2], [28, 1], [31, 2]], 'min_trips': 5}, 122096], ['no trips', {'base': 196384, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 166926]], [['mileage 10000 boundary', {'base': 176617, 'annual_miles': 10000, 'trips': [[15, 1], [20, 0], [31, 1], [6, 0], [25, 0], [24, 0]], 'min_trips': 5}, 138228], ['mileage 10300', {'base': 171140, 'annual_miles': 10300, 'trips': [[19, 2], [13, 0], [34, 0], [19, 2], [11, 0], [3, 0], [32, 0]], 'min_trips': 5}, 160519], ['careful driver', {'base': 154323, 'annual_miles': 7789, 'trips': [[36, 0], [35, 0], [22, 1], [7, 1], [30, 2], [34, 1], [32, 2], [18, 0]], 'min_trips': 5}, 133266], ['harsh braker surcharged', {'base': 124651, 'annual_miles': 10146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 150828], ['uneven trip lengths', {'base': 133061, 'annual_miles': 2552, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 96572], ['exactly minimum trips', {'base': 110232, 'annual_miles': 28818, 'trips': [[13, 0], [24, 0], [28, 0], [40, 0], [36, 1]], 'min_trips': 5}, 101339], ['few trips participation', {'base': 156778, 'annual_miles': 12000, 'trips': [[3, 0], [5, 0], [8, 0]], 'min_trips': 5}, 163833], ['no trips', {'base': 82109, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 69793]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    m=x['annual_miles']
    if m<=5000: band=Fraction(85,100)
    elif m<=10500: band=Fraction(1)
    elif m<=15000: band=Fraction(110,100)
    else: band=Fraction(125,100)
    trips=x['trips']
    if len(trips)>=x['min_trips']:
        miles=sum(t[0] for t in trips); brakes=sum(t[1] for t in trips)
        bp=Fraction(brakes*100,miles) if miles else Fraction(0)
        disc=max(-100,min(300,300-50*bp))
    elif trips:
        disc=Fraction(50)
    else:
        disc=Fraction(0)
    return math.floor(x['base']*band*(1000-disc)/1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mileage 10000 boundary', {'base': 91494, 'annual_miles': 10000, 'trips': [[9, 0], [23, 1], [20, 0], [13, 1], [26, 0], [39, 1]], 'min_trips': 5}, 74603], ['mileage 10300', {'base': 82749, 'annual_miles': 10300, 'trips': [[30, 0], [20, 0], [15, 0], [29, 0], [14, 0], [8, 2], [23, 0]], 'min_trips': 5}, 70265], ['careful driver', {'base': 163637, 'annual_miles': 7341, 'trips': [[30, 1], [8, 2], [6, 0], [14, 2], [39, 2], [11, 1], [14, 1], [28, 1]], 'min_trips': 5}, 169092], ['harsh braker surcharged', {'base': 91954, 'annual_miles': 14146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 111264], ['uneven trip lengths', {'base': 158528, 'annual_miles': 2875, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 115055], ['exactly minimum trips', {'base': 104301, 'annual_miles': 17231, 'trips': [[5, 2], [19, 0], [32, 0], [19, 0], [8, 2]], 'min_trips': 5}, 122679], ['few trips participation', {'base': 97679, 'annual_miles': 12000, 'trips': [[16, 1], [7, 2], [36, 1]], 'min_trips': 5}, 102075], ['no trips', {'base': 134485, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 114312]], [['mileage 10000 boundary', {'base': 191368, 'annual_miles': 10000, 'trips': [[27, 0], [10, 0], [40, 1], [30, 2], [32, 1], [25, 2]], 'min_trips': 5}, 168964], ['mileage 10300', {'base': 105555, 'annual_miles': 10300, 'trips': [[29, 1], [13, 0], [15, 1], [29, 0], [39, 0], [15, 2], [17, 1]], 'min_trips': 5}, 99766], ['careful driver', {'base': 102660, 'annual_miles': 8401, 'trips': [[3, 1], [19, 0], [12, 2], [23, 0], [4, 0], [9, 0], [37, 2], [3, 1]], 'min_trips': 5}, 99860], ['harsh braker surcharged', {'base': 180490, 'annual_miles': 14814, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 218393], ['uneven trip lengths', {'base': 153152, 'annual_miles': 2570, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 111153], ['exactly minimum trips', {'base': 128499, 'annual_miles': 20368, 'trips': [[14, 0], [32, 2], [33, 0], [37, 2], [39, 0]], 'min_trips': 5}, 133162], ['few trips participation', {'base': 120795, 'annual_miles': 12000, 'trips': [[24, 0], [17, 2], [14, 2]], 'min_trips': 5}, 126231], ['no trips', {'base': 91464, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 77744]], [['mileage 10000 boundary', {'base': 137312, 'annual_miles': 10000, 'trips': [[17, 0], [26, 0], [22, 0], [27, 0], [31, 0], [14, 0]], 'min_trips': 5}, 96118], ['mileage 10300', {'base': 96030, 'annual_miles': 10300, 'trips': [[16, 0], [14, 2], [3, 2], [27, 2], [34, 2], [28, 0], [15, 1]], 'min_trips': 5}, 108640], ['careful driver', {'base': 119620, 'annual_miles': 6579, 'trips': [[37, 0], [24, 1], [19, 0], [4, 2], [18, 0], [38, 0], [13, 0], [28, 1]], 'min_trips': 5}, 96952], ['harsh braker surcharged', {'base': 69899, 'annual_miles': 13431, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 84578], ['uneven trip lengths', {'base': 78689, 'annual_miles': 3827, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 57110], ['exactly minimum trips', {'base': 151953, 'annual_miles': 21023, 'trips': [[11, 2], [21, 0], [12, 1], [31, 1], [34, 0]], 'min_trips': 5}, 167810], ['few trips participation', {'base': 175401, 'annual_miles': 12000, 'trips': [[4, 0], [3, 1], [16, 0]], 'min_trips': 5}, 183294], ['no trips', {'base': 63313, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 53816]], [['mileage 10000 boundary', {'base': 97658, 'annual_miles': 10000, 'trips': [[3, 0], [31, 0], [16, 0], [17, 2], [9, 0], [6, 2]], 'min_trips': 5}, 92180], ['mileage 10300', {'base': 197346, 'annual_miles': 10300, 'trips': [[29, 0], [26, 2], [5, 0], [24, 0], [37, 0], [26, 2], [36, 0]], 'min_trips': 5}, 175681], ['careful driver', {'base': 162245, 'annual_miles': 5217, 'trips': [[20, 0], [35, 0], [30, 0], [10, 0], [31, 0], [11, 0], [34, 1], [21, 0]], 'min_trips': 5}, 117797], ['harsh braker surcharged', {'base': 110905, 'annual_miles': 12698, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 134195], ['uneven trip lengths', {'base': 170601, 'annual_miles': 3861, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 123817], ['exactly minimum trips', {'base': 139426, 'annual_miles': 27324, 'trips': [[7, 1], [31, 1], [40, 2], [10, 2], [19, 1]], 'min_trips': 5}, 179006], ['few trips participation', {'base': 116838, 'annual_miles': 12000, 'trips': [[6, 2], [28, 1], [31, 2]], 'min_trips': 5}, 122096], ['no trips', {'base': 196384, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 166926]], [['mileage 10000 boundary', {'base': 176617, 'annual_miles': 10000, 'trips': [[15, 1], [20, 0], [31, 1], [6, 0], [25, 0], [24, 0]], 'min_trips': 5}, 138228], ['mileage 10300', {'base': 171140, 'annual_miles': 10300, 'trips': [[19, 2], [13, 0], [34, 0], [19, 2], [11, 0], [3, 0], [32, 0]], 'min_trips': 5}, 160519], ['careful driver', {'base': 154323, 'annual_miles': 7789, 'trips': [[36, 0], [35, 0], [22, 1], [7, 1], [30, 2], [34, 1], [32, 2], [18, 0]], 'min_trips': 5}, 133266], ['harsh braker surcharged', {'base': 124651, 'annual_miles': 10146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 150828], ['uneven trip lengths', {'base': 133061, 'annual_miles': 2552, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 96572], ['exactly minimum trips', {'base': 110232, 'annual_miles': 28818, 'trips': [[13, 0], [24, 0], [28, 0], [40, 0], [36, 1]], 'min_trips': 5}, 101339], ['few trips participation', {'base': 156778, 'annual_miles': 12000, 'trips': [[3, 0], [5, 0], [8, 0]], 'min_trips': 5}, 163833], ['no trips', {'base': 82109, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 69793]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A vehicle driven exactly 10000 miles is placed in the higher band.

Input base, annual_miles (bands <=5000 0.85, <=10000 1.00, <=15000 1.10, else 1.25), trips [[miles, hard brakes]], min_trips. With at least min_trips trips: bp = total brakes per 100 total miles; discount = clamp(300-50*bp, -100, 300) per mille. Fewer (but some) trips: 50 per mille participation discount; none: 0. Premium = base*band*(1000-discount)/1000 half-up.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    m=x['annual_miles']
    if m<=5000: band=Fraction(85,100)
    elif m<=10000: band=Fraction(1)
    elif m<=15000: band=Fraction(110,100)
    else: band=Fraction(125,100)
    trips=x['trips']
    if len(trips)>=x['min_trips']:
        miles=sum(t[0] for t in trips); brakes=sum(t[1] for t in trips)
        bp=sum(Fraction(t[1]*100,t[0]) for t in trips if t[0])/len(trips)
        disc=max(-100,min(300,300-50*bp))
    elif trips:
        disc=Fraction(50)
    else:
        disc=Fraction(0)
    return math.floor(x['base']*band*(1000-disc)/1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mileage 10000 boundary', {'base': 91494, 'annual_miles': 10000, 'trips': [[9, 0], [23, 1], [20, 0], [13, 1], [26, 0], [39, 1]], 'min_trips': 5}, 74603], ['mileage 10300', {'base': 82749, 'annual_miles': 10300, 'trips': [[30, 0], [20, 0], [15, 0], [29, 0], [14, 0], [8, 2], [23, 0]], 'min_trips': 5}, 70265], ['careful driver', {'base': 163637, 'annual_miles': 7341, 'trips': [[30, 1], [8, 2], [6, 0], [14, 2], [39, 2], [11, 1], [14, 1], [28, 1]], 'min_trips': 5}, 169092], ['harsh braker surcharged', {'base': 91954, 'annual_miles': 14146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 111264], ['uneven trip lengths', {'base': 158528, 'annual_miles': 2875, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 115055], ['exactly minimum trips', {'base': 104301, 'annual_miles': 17231, 'trips': [[5, 2], [19, 0], [32, 0], [19, 0], [8, 2]], 'min_trips': 5}, 122679], ['few trips participation', {'base': 97679, 'annual_miles': 12000, 'trips': [[16, 1], [7, 2], [36, 1]], 'min_trips': 5}, 102075], ['no trips', {'base': 134485, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 114312]], [['mileage 10000 boundary', {'base': 191368, 'annual_miles': 10000, 'trips': [[27, 0], [10, 0], [40, 1], [30, 2], [32, 1], [25, 2]], 'min_trips': 5}, 168964], ['mileage 10300', {'base': 105555, 'annual_miles': 10300, 'trips': [[29, 1], [13, 0], [15, 1], [29, 0], [39, 0], [15, 2], [17, 1]], 'min_trips': 5}, 99766], ['careful driver', {'base': 102660, 'annual_miles': 8401, 'trips': [[3, 1], [19, 0], [12, 2], [23, 0], [4, 0], [9, 0], [37, 2], [3, 1]], 'min_trips': 5}, 99860], ['harsh braker surcharged', {'base': 180490, 'annual_miles': 14814, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 218393], ['uneven trip lengths', {'base': 153152, 'annual_miles': 2570, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 111153], ['exactly minimum trips', {'base': 128499, 'annual_miles': 20368, 'trips': [[14, 0], [32, 2], [33, 0], [37, 2], [39, 0]], 'min_trips': 5}, 133162], ['few trips participation', {'base': 120795, 'annual_miles': 12000, 'trips': [[24, 0], [17, 2], [14, 2]], 'min_trips': 5}, 126231], ['no trips', {'base': 91464, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 77744]], [['mileage 10000 boundary', {'base': 137312, 'annual_miles': 10000, 'trips': [[17, 0], [26, 0], [22, 0], [27, 0], [31, 0], [14, 0]], 'min_trips': 5}, 96118], ['mileage 10300', {'base': 96030, 'annual_miles': 10300, 'trips': [[16, 0], [14, 2], [3, 2], [27, 2], [34, 2], [28, 0], [15, 1]], 'min_trips': 5}, 108640], ['careful driver', {'base': 119620, 'annual_miles': 6579, 'trips': [[37, 0], [24, 1], [19, 0], [4, 2], [18, 0], [38, 0], [13, 0], [28, 1]], 'min_trips': 5}, 96952], ['harsh braker surcharged', {'base': 69899, 'annual_miles': 13431, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 84578], ['uneven trip lengths', {'base': 78689, 'annual_miles': 3827, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 57110], ['exactly minimum trips', {'base': 151953, 'annual_miles': 21023, 'trips': [[11, 2], [21, 0], [12, 1], [31, 1], [34, 0]], 'min_trips': 5}, 167810], ['few trips participation', {'base': 175401, 'annual_miles': 12000, 'trips': [[4, 0], [3, 1], [16, 0]], 'min_trips': 5}, 183294], ['no trips', {'base': 63313, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 53816]], [['mileage 10000 boundary', {'base': 97658, 'annual_miles': 10000, 'trips': [[3, 0], [31, 0], [16, 0], [17, 2], [9, 0], [6, 2]], 'min_trips': 5}, 92180], ['mileage 10300', {'base': 197346, 'annual_miles': 10300, 'trips': [[29, 0], [26, 2], [5, 0], [24, 0], [37, 0], [26, 2], [36, 0]], 'min_trips': 5}, 175681], ['careful driver', {'base': 162245, 'annual_miles': 5217, 'trips': [[20, 0], [35, 0], [30, 0], [10, 0], [31, 0], [11, 0], [34, 1], [21, 0]], 'min_trips': 5}, 117797], ['harsh braker surcharged', {'base': 110905, 'annual_miles': 12698, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 134195], ['uneven trip lengths', {'base': 170601, 'annual_miles': 3861, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 123817], ['exactly minimum trips', {'base': 139426, 'annual_miles': 27324, 'trips': [[7, 1], [31, 1], [40, 2], [10, 2], [19, 1]], 'min_trips': 5}, 179006], ['few trips participation', {'base': 116838, 'annual_miles': 12000, 'trips': [[6, 2], [28, 1], [31, 2]], 'min_trips': 5}, 122096], ['no trips', {'base': 196384, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 166926]], [['mileage 10000 boundary', {'base': 176617, 'annual_miles': 10000, 'trips': [[15, 1], [20, 0], [31, 1], [6, 0], [25, 0], [24, 0]], 'min_trips': 5}, 138228], ['mileage 10300', {'base': 171140, 'annual_miles': 10300, 'trips': [[19, 2], [13, 0], [34, 0], [19, 2], [11, 0], [3, 0], [32, 0]], 'min_trips': 5}, 160519], ['careful driver', {'base': 154323, 'annual_miles': 7789, 'trips': [[36, 0], [35, 0], [22, 1], [7, 1], [30, 2], [34, 1], [32, 2], [18, 0]], 'min_trips': 5}, 133266], ['harsh braker surcharged', {'base': 124651, 'annual_miles': 10146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 150828], ['uneven trip lengths', {'base': 133061, 'annual_miles': 2552, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 96572], ['exactly minimum trips', {'base': 110232, 'annual_miles': 28818, 'trips': [[13, 0], [24, 0], [28, 0], [40, 0], [36, 1]], 'min_trips': 5}, 101339], ['few trips participation', {'base': 156778, 'annual_miles': 12000, 'trips': [[3, 0], [5, 0], [8, 0]], 'min_trips': 5}, 163833], ['no trips', {'base': 82109, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 69793]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    m=x['annual_miles']
    if m<=5000: band=Fraction(85,100)
    elif m<=10000: band=Fraction(1)
    elif m<=15000: band=Fraction(110,100)
    else: band=Fraction(125,100)
    trips=x['trips']
    if len(trips)>=x['min_trips']:
        miles=sum(t[0] for t in trips); brakes=sum(t[1] for t in trips)
        bp=Fraction(brakes*100,len(trips))
        disc=max(-100,min(300,300-50*bp))
    elif trips:
        disc=Fraction(50)
    else:
        disc=Fraction(0)
    return math.floor(x['base']*band*(1000-disc)/1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mileage 10000 boundary', {'base': 91494, 'annual_miles': 10000, 'trips': [[9, 0], [23, 1], [20, 0], [13, 1], [26, 0], [39, 1]], 'min_trips': 5}, 74603], ['mileage 10300', {'base': 82749, 'annual_miles': 10300, 'trips': [[30, 0], [20, 0], [15, 0], [29, 0], [14, 0], [8, 2], [23, 0]], 'min_trips': 5}, 70265], ['careful driver', {'base': 163637, 'annual_miles': 7341, 'trips': [[30, 1], [8, 2], [6, 0], [14, 2], [39, 2], [11, 1], [14, 1], [28, 1]], 'min_trips': 5}, 169092], ['harsh braker surcharged', {'base': 91954, 'annual_miles': 14146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 111264], ['uneven trip lengths', {'base': 158528, 'annual_miles': 2875, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 115055], ['exactly minimum trips', {'base': 104301, 'annual_miles': 17231, 'trips': [[5, 2], [19, 0], [32, 0], [19, 0], [8, 2]], 'min_trips': 5}, 122679], ['few trips participation', {'base': 97679, 'annual_miles': 12000, 'trips': [[16, 1], [7, 2], [36, 1]], 'min_trips': 5}, 102075], ['no trips', {'base': 134485, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 114312]], [['mileage 10000 boundary', {'base': 191368, 'annual_miles': 10000, 'trips': [[27, 0], [10, 0], [40, 1], [30, 2], [32, 1], [25, 2]], 'min_trips': 5}, 168964], ['mileage 10300', {'base': 105555, 'annual_miles': 10300, 'trips': [[29, 1], [13, 0], [15, 1], [29, 0], [39, 0], [15, 2], [17, 1]], 'min_trips': 5}, 99766], ['careful driver', {'base': 102660, 'annual_miles': 8401, 'trips': [[3, 1], [19, 0], [12, 2], [23, 0], [4, 0], [9, 0], [37, 2], [3, 1]], 'min_trips': 5}, 99860], ['harsh braker surcharged', {'base': 180490, 'annual_miles': 14814, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 218393], ['uneven trip lengths', {'base': 153152, 'annual_miles': 2570, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 111153], ['exactly minimum trips', {'base': 128499, 'annual_miles': 20368, 'trips': [[14, 0], [32, 2], [33, 0], [37, 2], [39, 0]], 'min_trips': 5}, 133162], ['few trips participation', {'base': 120795, 'annual_miles': 12000, 'trips': [[24, 0], [17, 2], [14, 2]], 'min_trips': 5}, 126231], ['no trips', {'base': 91464, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 77744]], [['mileage 10000 boundary', {'base': 137312, 'annual_miles': 10000, 'trips': [[17, 0], [26, 0], [22, 0], [27, 0], [31, 0], [14, 0]], 'min_trips': 5}, 96118], ['mileage 10300', {'base': 96030, 'annual_miles': 10300, 'trips': [[16, 0], [14, 2], [3, 2], [27, 2], [34, 2], [28, 0], [15, 1]], 'min_trips': 5}, 108640], ['careful driver', {'base': 119620, 'annual_miles': 6579, 'trips': [[37, 0], [24, 1], [19, 0], [4, 2], [18, 0], [38, 0], [13, 0], [28, 1]], 'min_trips': 5}, 96952], ['harsh braker surcharged', {'base': 69899, 'annual_miles': 13431, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 84578], ['uneven trip lengths', {'base': 78689, 'annual_miles': 3827, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 57110], ['exactly minimum trips', {'base': 151953, 'annual_miles': 21023, 'trips': [[11, 2], [21, 0], [12, 1], [31, 1], [34, 0]], 'min_trips': 5}, 167810], ['few trips participation', {'base': 175401, 'annual_miles': 12000, 'trips': [[4, 0], [3, 1], [16, 0]], 'min_trips': 5}, 183294], ['no trips', {'base': 63313, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 53816]], [['mileage 10000 boundary', {'base': 97658, 'annual_miles': 10000, 'trips': [[3, 0], [31, 0], [16, 0], [17, 2], [9, 0], [6, 2]], 'min_trips': 5}, 92180], ['mileage 10300', {'base': 197346, 'annual_miles': 10300, 'trips': [[29, 0], [26, 2], [5, 0], [24, 0], [37, 0], [26, 2], [36, 0]], 'min_trips': 5}, 175681], ['careful driver', {'base': 162245, 'annual_miles': 5217, 'trips': [[20, 0], [35, 0], [30, 0], [10, 0], [31, 0], [11, 0], [34, 1], [21, 0]], 'min_trips': 5}, 117797], ['harsh braker surcharged', {'base': 110905, 'annual_miles': 12698, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 134195], ['uneven trip lengths', {'base': 170601, 'annual_miles': 3861, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 123817], ['exactly minimum trips', {'base': 139426, 'annual_miles': 27324, 'trips': [[7, 1], [31, 1], [40, 2], [10, 2], [19, 1]], 'min_trips': 5}, 179006], ['few trips participation', {'base': 116838, 'annual_miles': 12000, 'trips': [[6, 2], [28, 1], [31, 2]], 'min_trips': 5}, 122096], ['no trips', {'base': 196384, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 166926]], [['mileage 10000 boundary', {'base': 176617, 'annual_miles': 10000, 'trips': [[15, 1], [20, 0], [31, 1], [6, 0], [25, 0], [24, 0]], 'min_trips': 5}, 138228], ['mileage 10300', {'base': 171140, 'annual_miles': 10300, 'trips': [[19, 2], [13, 0], [34, 0], [19, 2], [11, 0], [3, 0], [32, 0]], 'min_trips': 5}, 160519], ['careful driver', {'base': 154323, 'annual_miles': 7789, 'trips': [[36, 0], [35, 0], [22, 1], [7, 1], [30, 2], [34, 1], [32, 2], [18, 0]], 'min_trips': 5}, 133266], ['harsh braker surcharged', {'base': 124651, 'annual_miles': 10146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 150828], ['uneven trip lengths', {'base': 133061, 'annual_miles': 2552, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 96572], ['exactly minimum trips', {'base': 110232, 'annual_miles': 28818, 'trips': [[13, 0], [24, 0], [28, 0], [40, 0], [36, 1]], 'min_trips': 5}, 101339], ['few trips participation', {'base': 156778, 'annual_miles': 12000, 'trips': [[3, 0], [5, 0], [8, 0]], 'min_trips': 5}, 163833], ['no trips', {'base': 82109, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 69793]]]
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:
Short trips with a single brake event dominate the score.

Input base, annual_miles (bands <=5000 0.85, <=10000 1.00, <=15000 1.10, else 1.25), trips [[miles, hard brakes]], min_trips. With at least min_trips trips: bp = total brakes per 100 total miles; discount = clamp(300-50*bp, -100, 300) per mille. Fewer (but some) trips: 50 per mille participation discount; none: 0. Premium = base*band*(1000-discount)/1000 half-up.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    m=x['annual_miles']
    if m<=5000: band=Fraction(85,100)
    elif m<=10000: band=Fraction(1)
    elif m<=15000: band=Fraction(110,100)
    else: band=Fraction(125,100)
    trips=x['trips']
    if len(trips)>=x['min_trips']:
        miles=sum(t[0] for t in trips); brakes=sum(t[1] for t in trips)
        bp=Fraction(brakes*100,miles) if miles else Fraction(0)
        disc=min(300,300-50*bp)
    elif trips:
        disc=Fraction(50)
    else:
        disc=Fraction(0)
    return math.floor(x['base']*band*(1000-disc)/1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mileage 10000 boundary', {'base': 91494, 'annual_miles': 10000, 'trips': [[9, 0], [23, 1], [20, 0], [13, 1], [26, 0], [39, 1]], 'min_trips': 5}, 74603], ['mileage 10300', {'base': 82749, 'annual_miles': 10300, 'trips': [[30, 0], [20, 0], [15, 0], [29, 0], [14, 0], [8, 2], [23, 0]], 'min_trips': 5}, 70265], ['careful driver', {'base': 163637, 'annual_miles': 7341, 'trips': [[30, 1], [8, 2], [6, 0], [14, 2], [39, 2], [11, 1], [14, 1], [28, 1]], 'min_trips': 5}, 169092], ['harsh braker surcharged', {'base': 91954, 'annual_miles': 14146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 111264], ['uneven trip lengths', {'base': 158528, 'annual_miles': 2875, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 115055], ['exactly minimum trips', {'base': 104301, 'annual_miles': 17231, 'trips': [[5, 2], [19, 0], [32, 0], [19, 0], [8, 2]], 'min_trips': 5}, 122679], ['few trips participation', {'base': 97679, 'annual_miles': 12000, 'trips': [[16, 1], [7, 2], [36, 1]], 'min_trips': 5}, 102075], ['no trips', {'base': 134485, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 114312]], [['mileage 10000 boundary', {'base': 191368, 'annual_miles': 10000, 'trips': [[27, 0], [10, 0], [40, 1], [30, 2], [32, 1], [25, 2]], 'min_trips': 5}, 168964], ['mileage 10300', {'base': 105555, 'annual_miles': 10300, 'trips': [[29, 1], [13, 0], [15, 1], [29, 0], [39, 0], [15, 2], [17, 1]], 'min_trips': 5}, 99766], ['careful driver', {'base': 102660, 'annual_miles': 8401, 'trips': [[3, 1], [19, 0], [12, 2], [23, 0], [4, 0], [9, 0], [37, 2], [3, 1]], 'min_trips': 5}, 99860], ['harsh braker surcharged', {'base': 180490, 'annual_miles': 14814, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 218393], ['uneven trip lengths', {'base': 153152, 'annual_miles': 2570, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 111153], ['exactly minimum trips', {'base': 128499, 'annual_miles': 20368, 'trips': [[14, 0], [32, 2], [33, 0], [37, 2], [39, 0]], 'min_trips': 5}, 133162], ['few trips participation', {'base': 120795, 'annual_miles': 12000, 'trips': [[24, 0], [17, 2], [14, 2]], 'min_trips': 5}, 126231], ['no trips', {'base': 91464, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 77744]], [['mileage 10000 boundary', {'base': 137312, 'annual_miles': 10000, 'trips': [[17, 0], [26, 0], [22, 0], [27, 0], [31, 0], [14, 0]], 'min_trips': 5}, 96118], ['mileage 10300', {'base': 96030, 'annual_miles': 10300, 'trips': [[16, 0], [14, 2], [3, 2], [27, 2], [34, 2], [28, 0], [15, 1]], 'min_trips': 5}, 108640], ['careful driver', {'base': 119620, 'annual_miles': 6579, 'trips': [[37, 0], [24, 1], [19, 0], [4, 2], [18, 0], [38, 0], [13, 0], [28, 1]], 'min_trips': 5}, 96952], ['harsh braker surcharged', {'base': 69899, 'annual_miles': 13431, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 84578], ['uneven trip lengths', {'base': 78689, 'annual_miles': 3827, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 57110], ['exactly minimum trips', {'base': 151953, 'annual_miles': 21023, 'trips': [[11, 2], [21, 0], [12, 1], [31, 1], [34, 0]], 'min_trips': 5}, 167810], ['few trips participation', {'base': 175401, 'annual_miles': 12000, 'trips': [[4, 0], [3, 1], [16, 0]], 'min_trips': 5}, 183294], ['no trips', {'base': 63313, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 53816]], [['mileage 10000 boundary', {'base': 97658, 'annual_miles': 10000, 'trips': [[3, 0], [31, 0], [16, 0], [17, 2], [9, 0], [6, 2]], 'min_trips': 5}, 92180], ['mileage 10300', {'base': 197346, 'annual_miles': 10300, 'trips': [[29, 0], [26, 2], [5, 0], [24, 0], [37, 0], [26, 2], [36, 0]], 'min_trips': 5}, 175681], ['careful driver', {'base': 162245, 'annual_miles': 5217, 'trips': [[20, 0], [35, 0], [30, 0], [10, 0], [31, 0], [11, 0], [34, 1], [21, 0]], 'min_trips': 5}, 117797], ['harsh braker surcharged', {'base': 110905, 'annual_miles': 12698, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 134195], ['uneven trip lengths', {'base': 170601, 'annual_miles': 3861, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 123817], ['exactly minimum trips', {'base': 139426, 'annual_miles': 27324, 'trips': [[7, 1], [31, 1], [40, 2], [10, 2], [19, 1]], 'min_trips': 5}, 179006], ['few trips participation', {'base': 116838, 'annual_miles': 12000, 'trips': [[6, 2], [28, 1], [31, 2]], 'min_trips': 5}, 122096], ['no trips', {'base': 196384, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 166926]], [['mileage 10000 boundary', {'base': 176617, 'annual_miles': 10000, 'trips': [[15, 1], [20, 0], [31, 1], [6, 0], [25, 0], [24, 0]], 'min_trips': 5}, 138228], ['mileage 10300', {'base': 171140, 'annual_miles': 10300, 'trips': [[19, 2], [13, 0], [34, 0], [19, 2], [11, 0], [3, 0], [32, 0]], 'min_trips': 5}, 160519], ['careful driver', {'base': 154323, 'annual_miles': 7789, 'trips': [[36, 0], [35, 0], [22, 1], [7, 1], [30, 2], [34, 1], [32, 2], [18, 0]], 'min_trips': 5}, 133266], ['harsh braker surcharged', {'base': 124651, 'annual_miles': 10146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 150828], ['uneven trip lengths', {'base': 133061, 'annual_miles': 2552, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 96572], ['exactly minimum trips', {'base': 110232, 'annual_miles': 28818, 'trips': [[13, 0], [24, 0], [28, 0], [40, 0], [36, 1]], 'min_trips': 5}, 101339], ['few trips participation', {'base': 156778, 'annual_miles': 12000, 'trips': [[3, 0], [5, 0], [8, 0]], 'min_trips': 5}, 163833], ['no trips', {'base': 82109, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 69793]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    m=x['annual_miles']
    if m<=5000: band=Fraction(85,100)
    elif m<=10000: band=Fraction(1)
    elif m<=15000: band=Fraction(110,100)
    else: band=Fraction(125,100)
    trips=x['trips']
    if len(trips)>=x['min_trips']:
        miles=sum(t[0] for t in trips); brakes=sum(t[1] for t in trips)
        bp=Fraction(brakes*100,miles) if miles else Fraction(0)
        disc=max(0,min(300,300-50*bp))
    elif trips:
        disc=Fraction(50)
    else:
        disc=Fraction(0)
    return math.floor(x['base']*band*(1000-disc)/1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mileage 10000 boundary', {'base': 91494, 'annual_miles': 10000, 'trips': [[9, 0], [23, 1], [20, 0], [13, 1], [26, 0], [39, 1]], 'min_trips': 5}, 74603], ['mileage 10300', {'base': 82749, 'annual_miles': 10300, 'trips': [[30, 0], [20, 0], [15, 0], [29, 0], [14, 0], [8, 2], [23, 0]], 'min_trips': 5}, 70265], ['careful driver', {'base': 163637, 'annual_miles': 7341, 'trips': [[30, 1], [8, 2], [6, 0], [14, 2], [39, 2], [11, 1], [14, 1], [28, 1]], 'min_trips': 5}, 169092], ['harsh braker surcharged', {'base': 91954, 'annual_miles': 14146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 111264], ['uneven trip lengths', {'base': 158528, 'annual_miles': 2875, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 115055], ['exactly minimum trips', {'base': 104301, 'annual_miles': 17231, 'trips': [[5, 2], [19, 0], [32, 0], [19, 0], [8, 2]], 'min_trips': 5}, 122679], ['few trips participation', {'base': 97679, 'annual_miles': 12000, 'trips': [[16, 1], [7, 2], [36, 1]], 'min_trips': 5}, 102075], ['no trips', {'base': 134485, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 114312]], [['mileage 10000 boundary', {'base': 191368, 'annual_miles': 10000, 'trips': [[27, 0], [10, 0], [40, 1], [30, 2], [32, 1], [25, 2]], 'min_trips': 5}, 168964], ['mileage 10300', {'base': 105555, 'annual_miles': 10300, 'trips': [[29, 1], [13, 0], [15, 1], [29, 0], [39, 0], [15, 2], [17, 1]], 'min_trips': 5}, 99766], ['careful driver', {'base': 102660, 'annual_miles': 8401, 'trips': [[3, 1], [19, 0], [12, 2], [23, 0], [4, 0], [9, 0], [37, 2], [3, 1]], 'min_trips': 5}, 99860], ['harsh braker surcharged', {'base': 180490, 'annual_miles': 14814, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 218393], ['uneven trip lengths', {'base': 153152, 'annual_miles': 2570, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 111153], ['exactly minimum trips', {'base': 128499, 'annual_miles': 20368, 'trips': [[14, 0], [32, 2], [33, 0], [37, 2], [39, 0]], 'min_trips': 5}, 133162], ['few trips participation', {'base': 120795, 'annual_miles': 12000, 'trips': [[24, 0], [17, 2], [14, 2]], 'min_trips': 5}, 126231], ['no trips', {'base': 91464, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 77744]], [['mileage 10000 boundary', {'base': 137312, 'annual_miles': 10000, 'trips': [[17, 0], [26, 0], [22, 0], [27, 0], [31, 0], [14, 0]], 'min_trips': 5}, 96118], ['mileage 10300', {'base': 96030, 'annual_miles': 10300, 'trips': [[16, 0], [14, 2], [3, 2], [27, 2], [34, 2], [28, 0], [15, 1]], 'min_trips': 5}, 108640], ['careful driver', {'base': 119620, 'annual_miles': 6579, 'trips': [[37, 0], [24, 1], [19, 0], [4, 2], [18, 0], [38, 0], [13, 0], [28, 1]], 'min_trips': 5}, 96952], ['harsh braker surcharged', {'base': 69899, 'annual_miles': 13431, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 84578], ['uneven trip lengths', {'base': 78689, 'annual_miles': 3827, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 57110], ['exactly minimum trips', {'base': 151953, 'annual_miles': 21023, 'trips': [[11, 2], [21, 0], [12, 1], [31, 1], [34, 0]], 'min_trips': 5}, 167810], ['few trips participation', {'base': 175401, 'annual_miles': 12000, 'trips': [[4, 0], [3, 1], [16, 0]], 'min_trips': 5}, 183294], ['no trips', {'base': 63313, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 53816]], [['mileage 10000 boundary', {'base': 97658, 'annual_miles': 10000, 'trips': [[3, 0], [31, 0], [16, 0], [17, 2], [9, 0], [6, 2]], 'min_trips': 5}, 92180], ['mileage 10300', {'base': 197346, 'annual_miles': 10300, 'trips': [[29, 0], [26, 2], [5, 0], [24, 0], [37, 0], [26, 2], [36, 0]], 'min_trips': 5}, 175681], ['careful driver', {'base': 162245, 'annual_miles': 5217, 'trips': [[20, 0], [35, 0], [30, 0], [10, 0], [31, 0], [11, 0], [34, 1], [21, 0]], 'min_trips': 5}, 117797], ['harsh braker surcharged', {'base': 110905, 'annual_miles': 12698, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 134195], ['uneven trip lengths', {'base': 170601, 'annual_miles': 3861, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 123817], ['exactly minimum trips', {'base': 139426, 'annual_miles': 27324, 'trips': [[7, 1], [31, 1], [40, 2], [10, 2], [19, 1]], 'min_trips': 5}, 179006], ['few trips participation', {'base': 116838, 'annual_miles': 12000, 'trips': [[6, 2], [28, 1], [31, 2]], 'min_trips': 5}, 122096], ['no trips', {'base': 196384, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 166926]], [['mileage 10000 boundary', {'base': 176617, 'annual_miles': 10000, 'trips': [[15, 1], [20, 0], [31, 1], [6, 0], [25, 0], [24, 0]], 'min_trips': 5}, 138228], ['mileage 10300', {'base': 171140, 'annual_miles': 10300, 'trips': [[19, 2], [13, 0], [34, 0], [19, 2], [11, 0], [3, 0], [32, 0]], 'min_trips': 5}, 160519], ['careful driver', {'base': 154323, 'annual_miles': 7789, 'trips': [[36, 0], [35, 0], [22, 1], [7, 1], [30, 2], [34, 1], [32, 2], [18, 0]], 'min_trips': 5}, 133266], ['harsh braker surcharged', {'base': 124651, 'annual_miles': 10146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 150828], ['uneven trip lengths', {'base': 133061, 'annual_miles': 2552, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 96572], ['exactly minimum trips', {'base': 110232, 'annual_miles': 28818, 'trips': [[13, 0], [24, 0], [28, 0], [40, 0], [36, 1]], 'min_trips': 5}, 101339], ['few trips participation', {'base': 156778, 'annual_miles': 12000, 'trips': [[3, 0], [5, 0], [8, 0]], 'min_trips': 5}, 163833], ['no trips', {'base': 82109, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 69793]]]
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:
Harsh drivers receive surcharges beyond the 10% maximum.

Input base, annual_miles (bands <=5000 0.85, <=10000 1.00, <=15000 1.10, else 1.25), trips [[miles, hard brakes]], min_trips. With at least min_trips trips: bp = total brakes per 100 total miles; discount = clamp(300-50*bp, -100, 300) per mille. Fewer (but some) trips: 50 per mille participation discount; none: 0. Premium = base*band*(1000-discount)/1000 half-up.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    m=x['annual_miles']
    if m<=5000: band=Fraction(85,100)
    elif m<=10000: band=Fraction(1)
    elif m<=15000: band=Fraction(110,100)
    else: band=Fraction(125,100)
    trips=x['trips']
    if len(trips)>x['min_trips']:
        miles=sum(t[0] for t in trips); brakes=sum(t[1] for t in trips)
        bp=Fraction(brakes*100,miles) if miles else Fraction(0)
        disc=max(-100,min(300,300-50*bp))
    elif trips:
        disc=Fraction(50)
    else:
        disc=Fraction(0)
    return math.floor(x['base']*band*(1000-disc)/1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mileage 10000 boundary', {'base': 91494, 'annual_miles': 10000, 'trips': [[9, 0], [23, 1], [20, 0], [13, 1], [26, 0], [39, 1]], 'min_trips': 5}, 74603], ['mileage 10300', {'base': 82749, 'annual_miles': 10300, 'trips': [[30, 0], [20, 0], [15, 0], [29, 0], [14, 0], [8, 2], [23, 0]], 'min_trips': 5}, 70265], ['careful driver', {'base': 163637, 'annual_miles': 7341, 'trips': [[30, 1], [8, 2], [6, 0], [14, 2], [39, 2], [11, 1], [14, 1], [28, 1]], 'min_trips': 5}, 169092], ['harsh braker surcharged', {'base': 91954, 'annual_miles': 14146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 111264], ['uneven trip lengths', {'base': 158528, 'annual_miles': 2875, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 115055], ['exactly minimum trips', {'base': 104301, 'annual_miles': 17231, 'trips': [[5, 2], [19, 0], [32, 0], [19, 0], [8, 2]], 'min_trips': 5}, 122679], ['few trips participation', {'base': 97679, 'annual_miles': 12000, 'trips': [[16, 1], [7, 2], [36, 1]], 'min_trips': 5}, 102075], ['no trips', {'base': 134485, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 114312]], [['mileage 10000 boundary', {'base': 191368, 'annual_miles': 10000, 'trips': [[27, 0], [10, 0], [40, 1], [30, 2], [32, 1], [25, 2]], 'min_trips': 5}, 168964], ['mileage 10300', {'base': 105555, 'annual_miles': 10300, 'trips': [[29, 1], [13, 0], [15, 1], [29, 0], [39, 0], [15, 2], [17, 1]], 'min_trips': 5}, 99766], ['careful driver', {'base': 102660, 'annual_miles': 8401, 'trips': [[3, 1], [19, 0], [12, 2], [23, 0], [4, 0], [9, 0], [37, 2], [3, 1]], 'min_trips': 5}, 99860], ['harsh braker surcharged', {'base': 180490, 'annual_miles': 14814, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 218393], ['uneven trip lengths', {'base': 153152, 'annual_miles': 2570, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 111153], ['exactly minimum trips', {'base': 128499, 'annual_miles': 20368, 'trips': [[14, 0], [32, 2], [33, 0], [37, 2], [39, 0]], 'min_trips': 5}, 133162], ['few trips participation', {'base': 120795, 'annual_miles': 12000, 'trips': [[24, 0], [17, 2], [14, 2]], 'min_trips': 5}, 126231], ['no trips', {'base': 91464, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 77744]], [['mileage 10000 boundary', {'base': 137312, 'annual_miles': 10000, 'trips': [[17, 0], [26, 0], [22, 0], [27, 0], [31, 0], [14, 0]], 'min_trips': 5}, 96118], ['mileage 10300', {'base': 96030, 'annual_miles': 10300, 'trips': [[16, 0], [14, 2], [3, 2], [27, 2], [34, 2], [28, 0], [15, 1]], 'min_trips': 5}, 108640], ['careful driver', {'base': 119620, 'annual_miles': 6579, 'trips': [[37, 0], [24, 1], [19, 0], [4, 2], [18, 0], [38, 0], [13, 0], [28, 1]], 'min_trips': 5}, 96952], ['harsh braker surcharged', {'base': 69899, 'annual_miles': 13431, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 84578], ['uneven trip lengths', {'base': 78689, 'annual_miles': 3827, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 57110], ['exactly minimum trips', {'base': 151953, 'annual_miles': 21023, 'trips': [[11, 2], [21, 0], [12, 1], [31, 1], [34, 0]], 'min_trips': 5}, 167810], ['few trips participation', {'base': 175401, 'annual_miles': 12000, 'trips': [[4, 0], [3, 1], [16, 0]], 'min_trips': 5}, 183294], ['no trips', {'base': 63313, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 53816]], [['mileage 10000 boundary', {'base': 97658, 'annual_miles': 10000, 'trips': [[3, 0], [31, 0], [16, 0], [17, 2], [9, 0], [6, 2]], 'min_trips': 5}, 92180], ['mileage 10300', {'base': 197346, 'annual_miles': 10300, 'trips': [[29, 0], [26, 2], [5, 0], [24, 0], [37, 0], [26, 2], [36, 0]], 'min_trips': 5}, 175681], ['careful driver', {'base': 162245, 'annual_miles': 5217, 'trips': [[20, 0], [35, 0], [30, 0], [10, 0], [31, 0], [11, 0], [34, 1], [21, 0]], 'min_trips': 5}, 117797], ['harsh braker surcharged', {'base': 110905, 'annual_miles': 12698, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 134195], ['uneven trip lengths', {'base': 170601, 'annual_miles': 3861, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 123817], ['exactly minimum trips', {'base': 139426, 'annual_miles': 27324, 'trips': [[7, 1], [31, 1], [40, 2], [10, 2], [19, 1]], 'min_trips': 5}, 179006], ['few trips participation', {'base': 116838, 'annual_miles': 12000, 'trips': [[6, 2], [28, 1], [31, 2]], 'min_trips': 5}, 122096], ['no trips', {'base': 196384, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 166926]], [['mileage 10000 boundary', {'base': 176617, 'annual_miles': 10000, 'trips': [[15, 1], [20, 0], [31, 1], [6, 0], [25, 0], [24, 0]], 'min_trips': 5}, 138228], ['mileage 10300', {'base': 171140, 'annual_miles': 10300, 'trips': [[19, 2], [13, 0], [34, 0], [19, 2], [11, 0], [3, 0], [32, 0]], 'min_trips': 5}, 160519], ['careful driver', {'base': 154323, 'annual_miles': 7789, 'trips': [[36, 0], [35, 0], [22, 1], [7, 1], [30, 2], [34, 1], [32, 2], [18, 0]], 'min_trips': 5}, 133266], ['harsh braker surcharged', {'base': 124651, 'annual_miles': 10146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 150828], ['uneven trip lengths', {'base': 133061, 'annual_miles': 2552, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 96572], ['exactly minimum trips', {'base': 110232, 'annual_miles': 28818, 'trips': [[13, 0], [24, 0], [28, 0], [40, 0], [36, 1]], 'min_trips': 5}, 101339], ['few trips participation', {'base': 156778, 'annual_miles': 12000, 'trips': [[3, 0], [5, 0], [8, 0]], 'min_trips': 5}, 163833], ['no trips', {'base': 82109, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 69793]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    m=x['annual_miles']
    if m<=5000: band=Fraction(85,100)
    elif m<=10000: band=Fraction(1)
    elif m<=15000: band=Fraction(110,100)
    else: band=Fraction(125,100)
    trips=x['trips']
    if sum(t[0] for t in trips)>=x['min_trips']:
        miles=sum(t[0] for t in trips); brakes=sum(t[1] for t in trips)
        bp=Fraction(brakes*100,miles) if miles else Fraction(0)
        disc=max(-100,min(300,300-50*bp))
    elif trips:
        disc=Fraction(50)
    else:
        disc=Fraction(0)
    return math.floor(x['base']*band*(1000-disc)/1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mileage 10000 boundary', {'base': 91494, 'annual_miles': 10000, 'trips': [[9, 0], [23, 1], [20, 0], [13, 1], [26, 0], [39, 1]], 'min_trips': 5}, 74603], ['mileage 10300', {'base': 82749, 'annual_miles': 10300, 'trips': [[30, 0], [20, 0], [15, 0], [29, 0], [14, 0], [8, 2], [23, 0]], 'min_trips': 5}, 70265], ['careful driver', {'base': 163637, 'annual_miles': 7341, 'trips': [[30, 1], [8, 2], [6, 0], [14, 2], [39, 2], [11, 1], [14, 1], [28, 1]], 'min_trips': 5}, 169092], ['harsh braker surcharged', {'base': 91954, 'annual_miles': 14146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 111264], ['uneven trip lengths', {'base': 158528, 'annual_miles': 2875, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 115055], ['exactly minimum trips', {'base': 104301, 'annual_miles': 17231, 'trips': [[5, 2], [19, 0], [32, 0], [19, 0], [8, 2]], 'min_trips': 5}, 122679], ['few trips participation', {'base': 97679, 'annual_miles': 12000, 'trips': [[16, 1], [7, 2], [36, 1]], 'min_trips': 5}, 102075], ['no trips', {'base': 134485, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 114312]], [['mileage 10000 boundary', {'base': 191368, 'annual_miles': 10000, 'trips': [[27, 0], [10, 0], [40, 1], [30, 2], [32, 1], [25, 2]], 'min_trips': 5}, 168964], ['mileage 10300', {'base': 105555, 'annual_miles': 10300, 'trips': [[29, 1], [13, 0], [15, 1], [29, 0], [39, 0], [15, 2], [17, 1]], 'min_trips': 5}, 99766], ['careful driver', {'base': 102660, 'annual_miles': 8401, 'trips': [[3, 1], [19, 0], [12, 2], [23, 0], [4, 0], [9, 0], [37, 2], [3, 1]], 'min_trips': 5}, 99860], ['harsh braker surcharged', {'base': 180490, 'annual_miles': 14814, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 218393], ['uneven trip lengths', {'base': 153152, 'annual_miles': 2570, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 111153], ['exactly minimum trips', {'base': 128499, 'annual_miles': 20368, 'trips': [[14, 0], [32, 2], [33, 0], [37, 2], [39, 0]], 'min_trips': 5}, 133162], ['few trips participation', {'base': 120795, 'annual_miles': 12000, 'trips': [[24, 0], [17, 2], [14, 2]], 'min_trips': 5}, 126231], ['no trips', {'base': 91464, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 77744]], [['mileage 10000 boundary', {'base': 137312, 'annual_miles': 10000, 'trips': [[17, 0], [26, 0], [22, 0], [27, 0], [31, 0], [14, 0]], 'min_trips': 5}, 96118], ['mileage 10300', {'base': 96030, 'annual_miles': 10300, 'trips': [[16, 0], [14, 2], [3, 2], [27, 2], [34, 2], [28, 0], [15, 1]], 'min_trips': 5}, 108640], ['careful driver', {'base': 119620, 'annual_miles': 6579, 'trips': [[37, 0], [24, 1], [19, 0], [4, 2], [18, 0], [38, 0], [13, 0], [28, 1]], 'min_trips': 5}, 96952], ['harsh braker surcharged', {'base': 69899, 'annual_miles': 13431, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 84578], ['uneven trip lengths', {'base': 78689, 'annual_miles': 3827, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 57110], ['exactly minimum trips', {'base': 151953, 'annual_miles': 21023, 'trips': [[11, 2], [21, 0], [12, 1], [31, 1], [34, 0]], 'min_trips': 5}, 167810], ['few trips participation', {'base': 175401, 'annual_miles': 12000, 'trips': [[4, 0], [3, 1], [16, 0]], 'min_trips': 5}, 183294], ['no trips', {'base': 63313, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 53816]], [['mileage 10000 boundary', {'base': 97658, 'annual_miles': 10000, 'trips': [[3, 0], [31, 0], [16, 0], [17, 2], [9, 0], [6, 2]], 'min_trips': 5}, 92180], ['mileage 10300', {'base': 197346, 'annual_miles': 10300, 'trips': [[29, 0], [26, 2], [5, 0], [24, 0], [37, 0], [26, 2], [36, 0]], 'min_trips': 5}, 175681], ['careful driver', {'base': 162245, 'annual_miles': 5217, 'trips': [[20, 0], [35, 0], [30, 0], [10, 0], [31, 0], [11, 0], [34, 1], [21, 0]], 'min_trips': 5}, 117797], ['harsh braker surcharged', {'base': 110905, 'annual_miles': 12698, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 134195], ['uneven trip lengths', {'base': 170601, 'annual_miles': 3861, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 123817], ['exactly minimum trips', {'base': 139426, 'annual_miles': 27324, 'trips': [[7, 1], [31, 1], [40, 2], [10, 2], [19, 1]], 'min_trips': 5}, 179006], ['few trips participation', {'base': 116838, 'annual_miles': 12000, 'trips': [[6, 2], [28, 1], [31, 2]], 'min_trips': 5}, 122096], ['no trips', {'base': 196384, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 166926]], [['mileage 10000 boundary', {'base': 176617, 'annual_miles': 10000, 'trips': [[15, 1], [20, 0], [31, 1], [6, 0], [25, 0], [24, 0]], 'min_trips': 5}, 138228], ['mileage 10300', {'base': 171140, 'annual_miles': 10300, 'trips': [[19, 2], [13, 0], [34, 0], [19, 2], [11, 0], [3, 0], [32, 0]], 'min_trips': 5}, 160519], ['careful driver', {'base': 154323, 'annual_miles': 7789, 'trips': [[36, 0], [35, 0], [22, 1], [7, 1], [30, 2], [34, 1], [32, 2], [18, 0]], 'min_trips': 5}, 133266], ['harsh braker surcharged', {'base': 124651, 'annual_miles': 10146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 150828], ['uneven trip lengths', {'base': 133061, 'annual_miles': 2552, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 96572], ['exactly minimum trips', {'base': 110232, 'annual_miles': 28818, 'trips': [[13, 0], [24, 0], [28, 0], [40, 0], [36, 1]], 'min_trips': 5}, 101339], ['few trips participation', {'base': 156778, 'annual_miles': 12000, 'trips': [[3, 0], [5, 0], [8, 0]], 'min_trips': 5}, 163833], ['no trips', {'base': 82109, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 69793]]]
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:
Drivers with exactly the required trips only get the participation discount.

Input base, annual_miles (bands <=5000 0.85, <=10000 1.00, <=15000 1.10, else 1.25), trips [[miles, hard brakes]], min_trips. With at least min_trips trips: bp = total brakes per 100 total miles; discount = clamp(300-50*bp, -100, 300) per mille. Fewer (but some) trips: 50 per mille participation discount; none: 0. Premium = base*band*(1000-discount)/1000 half-up.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    m=x['annual_miles']
    if m<=5000: band=Fraction(85,100)
    elif m<=10000: band=Fraction(1)
    elif m<=15000: band=Fraction(110,100)
    else: band=Fraction(125,100)
    trips=x['trips']
    if len(trips)>=x['min_trips']:
        miles=sum(t[0] for t in trips); brakes=sum(t[1] for t in trips)
        bp=Fraction(brakes*100,miles) if miles else Fraction(0)
        disc=max(-100,min(300,300-50*bp))
    else:
        disc=Fraction(50)
    return math.floor(x['base']*band*(1000-disc)/1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mileage 10000 boundary', {'base': 91494, 'annual_miles': 10000, 'trips': [[9, 0], [23, 1], [20, 0], [13, 1], [26, 0], [39, 1]], 'min_trips': 5}, 74603], ['mileage 10300', {'base': 82749, 'annual_miles': 10300, 'trips': [[30, 0], [20, 0], [15, 0], [29, 0], [14, 0], [8, 2], [23, 0]], 'min_trips': 5}, 70265], ['careful driver', {'base': 163637, 'annual_miles': 7341, 'trips': [[30, 1], [8, 2], [6, 0], [14, 2], [39, 2], [11, 1], [14, 1], [28, 1]], 'min_trips': 5}, 169092], ['harsh braker surcharged', {'base': 91954, 'annual_miles': 14146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 111264], ['uneven trip lengths', {'base': 158528, 'annual_miles': 2875, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 115055], ['exactly minimum trips', {'base': 104301, 'annual_miles': 17231, 'trips': [[5, 2], [19, 0], [32, 0], [19, 0], [8, 2]], 'min_trips': 5}, 122679], ['few trips participation', {'base': 97679, 'annual_miles': 12000, 'trips': [[16, 1], [7, 2], [36, 1]], 'min_trips': 5}, 102075], ['no trips', {'base': 134485, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 114312]], [['mileage 10000 boundary', {'base': 191368, 'annual_miles': 10000, 'trips': [[27, 0], [10, 0], [40, 1], [30, 2], [32, 1], [25, 2]], 'min_trips': 5}, 168964], ['mileage 10300', {'base': 105555, 'annual_miles': 10300, 'trips': [[29, 1], [13, 0], [15, 1], [29, 0], [39, 0], [15, 2], [17, 1]], 'min_trips': 5}, 99766], ['careful driver', {'base': 102660, 'annual_miles': 8401, 'trips': [[3, 1], [19, 0], [12, 2], [23, 0], [4, 0], [9, 0], [37, 2], [3, 1]], 'min_trips': 5}, 99860], ['harsh braker surcharged', {'base': 180490, 'annual_miles': 14814, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 218393], ['uneven trip lengths', {'base': 153152, 'annual_miles': 2570, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 111153], ['exactly minimum trips', {'base': 128499, 'annual_miles': 20368, 'trips': [[14, 0], [32, 2], [33, 0], [37, 2], [39, 0]], 'min_trips': 5}, 133162], ['few trips participation', {'base': 120795, 'annual_miles': 12000, 'trips': [[24, 0], [17, 2], [14, 2]], 'min_trips': 5}, 126231], ['no trips', {'base': 91464, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 77744]], [['mileage 10000 boundary', {'base': 137312, 'annual_miles': 10000, 'trips': [[17, 0], [26, 0], [22, 0], [27, 0], [31, 0], [14, 0]], 'min_trips': 5}, 96118], ['mileage 10300', {'base': 96030, 'annual_miles': 10300, 'trips': [[16, 0], [14, 2], [3, 2], [27, 2], [34, 2], [28, 0], [15, 1]], 'min_trips': 5}, 108640], ['careful driver', {'base': 119620, 'annual_miles': 6579, 'trips': [[37, 0], [24, 1], [19, 0], [4, 2], [18, 0], [38, 0], [13, 0], [28, 1]], 'min_trips': 5}, 96952], ['harsh braker surcharged', {'base': 69899, 'annual_miles': 13431, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 84578], ['uneven trip lengths', {'base': 78689, 'annual_miles': 3827, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 57110], ['exactly minimum trips', {'base': 151953, 'annual_miles': 21023, 'trips': [[11, 2], [21, 0], [12, 1], [31, 1], [34, 0]], 'min_trips': 5}, 167810], ['few trips participation', {'base': 175401, 'annual_miles': 12000, 'trips': [[4, 0], [3, 1], [16, 0]], 'min_trips': 5}, 183294], ['no trips', {'base': 63313, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 53816]], [['mileage 10000 boundary', {'base': 97658, 'annual_miles': 10000, 'trips': [[3, 0], [31, 0], [16, 0], [17, 2], [9, 0], [6, 2]], 'min_trips': 5}, 92180], ['mileage 10300', {'base': 197346, 'annual_miles': 10300, 'trips': [[29, 0], [26, 2], [5, 0], [24, 0], [37, 0], [26, 2], [36, 0]], 'min_trips': 5}, 175681], ['careful driver', {'base': 162245, 'annual_miles': 5217, 'trips': [[20, 0], [35, 0], [30, 0], [10, 0], [31, 0], [11, 0], [34, 1], [21, 0]], 'min_trips': 5}, 117797], ['harsh braker surcharged', {'base': 110905, 'annual_miles': 12698, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 134195], ['uneven trip lengths', {'base': 170601, 'annual_miles': 3861, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 123817], ['exactly minimum trips', {'base': 139426, 'annual_miles': 27324, 'trips': [[7, 1], [31, 1], [40, 2], [10, 2], [19, 1]], 'min_trips': 5}, 179006], ['few trips participation', {'base': 116838, 'annual_miles': 12000, 'trips': [[6, 2], [28, 1], [31, 2]], 'min_trips': 5}, 122096], ['no trips', {'base': 196384, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 166926]], [['mileage 10000 boundary', {'base': 176617, 'annual_miles': 10000, 'trips': [[15, 1], [20, 0], [31, 1], [6, 0], [25, 0], [24, 0]], 'min_trips': 5}, 138228], ['mileage 10300', {'base': 171140, 'annual_miles': 10300, 'trips': [[19, 2], [13, 0], [34, 0], [19, 2], [11, 0], [3, 0], [32, 0]], 'min_trips': 5}, 160519], ['careful driver', {'base': 154323, 'annual_miles': 7789, 'trips': [[36, 0], [35, 0], [22, 1], [7, 1], [30, 2], [34, 1], [32, 2], [18, 0]], 'min_trips': 5}, 133266], ['harsh braker surcharged', {'base': 124651, 'annual_miles': 10146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 150828], ['uneven trip lengths', {'base': 133061, 'annual_miles': 2552, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 96572], ['exactly minimum trips', {'base': 110232, 'annual_miles': 28818, 'trips': [[13, 0], [24, 0], [28, 0], [40, 0], [36, 1]], 'min_trips': 5}, 101339], ['few trips participation', {'base': 156778, 'annual_miles': 12000, 'trips': [[3, 0], [5, 0], [8, 0]], 'min_trips': 5}, 163833], ['no trips', {'base': 82109, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 69793]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    m=x['annual_miles']
    if m<=5000: band=Fraction(85,100)
    elif m<=10000: band=Fraction(1)
    elif m<=15000: band=Fraction(110,100)
    else: band=Fraction(125,100)
    trips=x['trips']
    if len(trips)>=x['min_trips']:
        miles=sum(t[0] for t in trips); brakes=sum(t[1] for t in trips)
        bp=Fraction(brakes*100,miles) if miles else Fraction(0)
        disc=max(-100,min(300,300-50*bp))
    elif trips:
        disc=Fraction(0)
    else:
        disc=Fraction(50)
    return math.floor(x['base']*band*(1000-disc)/1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mileage 10000 boundary', {'base': 91494, 'annual_miles': 10000, 'trips': [[9, 0], [23, 1], [20, 0], [13, 1], [26, 0], [39, 1]], 'min_trips': 5}, 74603], ['mileage 10300', {'base': 82749, 'annual_miles': 10300, 'trips': [[30, 0], [20, 0], [15, 0], [29, 0], [14, 0], [8, 2], [23, 0]], 'min_trips': 5}, 70265], ['careful driver', {'base': 163637, 'annual_miles': 7341, 'trips': [[30, 1], [8, 2], [6, 0], [14, 2], [39, 2], [11, 1], [14, 1], [28, 1]], 'min_trips': 5}, 169092], ['harsh braker surcharged', {'base': 91954, 'annual_miles': 14146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 111264], ['uneven trip lengths', {'base': 158528, 'annual_miles': 2875, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 115055], ['exactly minimum trips', {'base': 104301, 'annual_miles': 17231, 'trips': [[5, 2], [19, 0], [32, 0], [19, 0], [8, 2]], 'min_trips': 5}, 122679], ['few trips participation', {'base': 97679, 'annual_miles': 12000, 'trips': [[16, 1], [7, 2], [36, 1]], 'min_trips': 5}, 102075], ['no trips', {'base': 134485, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 114312]], [['mileage 10000 boundary', {'base': 191368, 'annual_miles': 10000, 'trips': [[27, 0], [10, 0], [40, 1], [30, 2], [32, 1], [25, 2]], 'min_trips': 5}, 168964], ['mileage 10300', {'base': 105555, 'annual_miles': 10300, 'trips': [[29, 1], [13, 0], [15, 1], [29, 0], [39, 0], [15, 2], [17, 1]], 'min_trips': 5}, 99766], ['careful driver', {'base': 102660, 'annual_miles': 8401, 'trips': [[3, 1], [19, 0], [12, 2], [23, 0], [4, 0], [9, 0], [37, 2], [3, 1]], 'min_trips': 5}, 99860], ['harsh braker surcharged', {'base': 180490, 'annual_miles': 14814, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 218393], ['uneven trip lengths', {'base': 153152, 'annual_miles': 2570, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 111153], ['exactly minimum trips', {'base': 128499, 'annual_miles': 20368, 'trips': [[14, 0], [32, 2], [33, 0], [37, 2], [39, 0]], 'min_trips': 5}, 133162], ['few trips participation', {'base': 120795, 'annual_miles': 12000, 'trips': [[24, 0], [17, 2], [14, 2]], 'min_trips': 5}, 126231], ['no trips', {'base': 91464, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 77744]], [['mileage 10000 boundary', {'base': 137312, 'annual_miles': 10000, 'trips': [[17, 0], [26, 0], [22, 0], [27, 0], [31, 0], [14, 0]], 'min_trips': 5}, 96118], ['mileage 10300', {'base': 96030, 'annual_miles': 10300, 'trips': [[16, 0], [14, 2], [3, 2], [27, 2], [34, 2], [28, 0], [15, 1]], 'min_trips': 5}, 108640], ['careful driver', {'base': 119620, 'annual_miles': 6579, 'trips': [[37, 0], [24, 1], [19, 0], [4, 2], [18, 0], [38, 0], [13, 0], [28, 1]], 'min_trips': 5}, 96952], ['harsh braker surcharged', {'base': 69899, 'annual_miles': 13431, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 84578], ['uneven trip lengths', {'base': 78689, 'annual_miles': 3827, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 57110], ['exactly minimum trips', {'base': 151953, 'annual_miles': 21023, 'trips': [[11, 2], [21, 0], [12, 1], [31, 1], [34, 0]], 'min_trips': 5}, 167810], ['few trips participation', {'base': 175401, 'annual_miles': 12000, 'trips': [[4, 0], [3, 1], [16, 0]], 'min_trips': 5}, 183294], ['no trips', {'base': 63313, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 53816]], [['mileage 10000 boundary', {'base': 97658, 'annual_miles': 10000, 'trips': [[3, 0], [31, 0], [16, 0], [17, 2], [9, 0], [6, 2]], 'min_trips': 5}, 92180], ['mileage 10300', {'base': 197346, 'annual_miles': 10300, 'trips': [[29, 0], [26, 2], [5, 0], [24, 0], [37, 0], [26, 2], [36, 0]], 'min_trips': 5}, 175681], ['careful driver', {'base': 162245, 'annual_miles': 5217, 'trips': [[20, 0], [35, 0], [30, 0], [10, 0], [31, 0], [11, 0], [34, 1], [21, 0]], 'min_trips': 5}, 117797], ['harsh braker surcharged', {'base': 110905, 'annual_miles': 12698, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 134195], ['uneven trip lengths', {'base': 170601, 'annual_miles': 3861, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 123817], ['exactly minimum trips', {'base': 139426, 'annual_miles': 27324, 'trips': [[7, 1], [31, 1], [40, 2], [10, 2], [19, 1]], 'min_trips': 5}, 179006], ['few trips participation', {'base': 116838, 'annual_miles': 12000, 'trips': [[6, 2], [28, 1], [31, 2]], 'min_trips': 5}, 122096], ['no trips', {'base': 196384, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 166926]], [['mileage 10000 boundary', {'base': 176617, 'annual_miles': 10000, 'trips': [[15, 1], [20, 0], [31, 1], [6, 0], [25, 0], [24, 0]], 'min_trips': 5}, 138228], ['mileage 10300', {'base': 171140, 'annual_miles': 10300, 'trips': [[19, 2], [13, 0], [34, 0], [19, 2], [11, 0], [3, 0], [32, 0]], 'min_trips': 5}, 160519], ['careful driver', {'base': 154323, 'annual_miles': 7789, 'trips': [[36, 0], [35, 0], [22, 1], [7, 1], [30, 2], [34, 1], [32, 2], [18, 0]], 'min_trips': 5}, 133266], ['harsh braker surcharged', {'base': 124651, 'annual_miles': 10146, 'trips': [[5, 6], [4, 5], [6, 7], [3, 4], [5, 6]], 'min_trips': 5}, 150828], ['uneven trip lengths', {'base': 133061, 'annual_miles': 2552, 'trips': [[80, 2], [2, 1], [60, 1], [3, 0], [50, 2]], 'min_trips': 5}, 96572], ['exactly minimum trips', {'base': 110232, 'annual_miles': 28818, 'trips': [[13, 0], [24, 0], [28, 0], [40, 0], [36, 1]], 'min_trips': 5}, 101339], ['few trips participation', {'base': 156778, 'annual_miles': 12000, 'trips': [[3, 0], [5, 0], [8, 0]], 'min_trips': 5}, 163833], ['no trips', {'base': 82109, 'annual_miles': 4000, 'trips': [], 'min_trips': 5}, 69793]]]
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:
Enrolled vehicles that never report a trip still get the participation discount.

Input base, annual_miles (bands <=5000 0.85, <=10000 1.00, <=15000 1.10, else 1.25), trips [[miles, hard brakes]], min_trips. With at least min_trips trips: bp = total brakes per 100 total miles; discount = clamp(300-50*bp, -100, 300) per mille. Fewer (but some) trips: 50 per mille participation discount; none: 0. Premium = base*band*(1000-discount)/1000 half-up.

split: open-access


prompt:
Published l_x values drift from the stepwise-rounded table.

Input q (per 100000, last must be 100000 else 'open table'; any outside [0,100000] -> 'invalid q') and radix (<=0 -> 'invalid radix'). l_0 = radix; l_{k+1} = l_k*(1-q_k) rounded half-up at every age; d_k = l_k - l_{k+1}. Return [l, d].

split: open-access


prompt:
Every properly closed table is reported as invalid.

Input q (per 100000, last must be 100000 else 'open table'; any outside [0,100000] -> 'invalid q') and radix (<=0 -> 'invalid radix'). l_0 = radix; l_{k+1} = l_k*(1-q_k) rounded half-up at every age; d_k = l_k - l_{k+1}. Return [l, d].

split: open-access


prompt:
An open table produces survivors past the last age.

Input q (per 100000, last must be 100000 else 'open table'; any outside [0,100000] -> 'invalid q') and radix (<=0 -> 'invalid radix'). l_0 = radix; l_{k+1} = l_k*(1-q_k) rounded half-up at every age; d_k = l_k - l_{k+1}. Return [l, d].

split: open-access


prompt:
d_x does not reconcile with l_x - l_{x+1}.

Input q (per 100000, last must be 100000 else 'open table'; any outside [0,100000] -> 'invalid q') and radix (<=0 -> 'invalid radix'). l_0 = radix; l_{k+1} = l_k*(1-q_k) rounded half-up at every age; d_k = l_k - l_{k+1}. Return [l, d].

split: open-access


prompt:
A zero radix silently yields an all-zero table.

Input q (per 100000, last must be 100000 else 'open table'; any outside [0,100000] -> 'invalid q') and radix (<=0 -> 'invalid radix'). l_0 = radix; l_{k+1} = l_k*(1-q_k) rounded half-up at every age; d_k = l_k - l_{k+1}. Return [l, d].

split: open-access


prompt:
Life expectancies are overstated by about one year.

Input l (survivors by age, last entry is the open interval) and m_open (per mille central rate of the open interval, <=0 -> 'invalid open rate'). L_x = l_{x+1} + d_x/2, L_open = l_open/m, T_x = sum of L from x, e_x = T_x/l_x rounded to 4 places (None where l_x=0).

split: open-access


prompt:
Expectation at the oldest ages collapses.

Input l (survivors by age, last entry is the open interval) and m_open (per mille central rate of the open interval, <=0 -> 'invalid open rate'). L_x = l_{x+1} + d_x/2, L_open = l_open/m, T_x = sum of L from x, e_x = T_x/l_x rounded to 4 places (None where l_x=0).

split: open-access


prompt:
Every expectation is short by the current year's person-years.

Input l (survivors by age, last entry is the open interval) and m_open (per mille central rate of the open interval, <=0 -> 'invalid open rate'). L_x = l_{x+1} + d_x/2, L_open = l_open/m, T_x = sum of L from x, e_x = T_x/l_x rounded to 4 places (None where l_x=0).

split: open-access


prompt:
Expectations at older ages are far too small.

Input l (survivors by age, last entry is the open interval) and m_open (per mille central rate of the open interval, <=0 -> 'invalid open rate'). L_x = l_{x+1} + d_x/2, L_open = l_open/m, T_x = sum of L from x, e_x = T_x/l_x rounded to 4 places (None where l_x=0).

split: open-access


prompt:
e_0 is tiny and the oldest age has the largest expectation.

Input l (survivors by age, last entry is the open interval) and m_open (per mille central rate of the open interval, <=0 -> 'invalid open rate'). L_x = l_{x+1} + d_x/2, L_open = l_open/m, T_x = sum of L from x, e_x = T_x/l_x rounded to 4 places (None where l_x=0).

split: open-access