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

N = 1
observations = []
def solve(x):
    target = {1: 0, 2: 10, 3: 30, 4: 60, 5: 120}
    rows, overdue = [], []
    for p in x['patients']:
        lvl = p['retriage'] if p['retriage'] is not None else p['level']
        wait = x['now'] - p['arrival']
        pr = lvl
        if wait > target[lvl]:
            overdue.append(p['id'])
            pr = max(1, lvl - 1)
        rows.append((pr, p['id'], p['arrival']))
    rows.sort()
    return {'order': [r[2] for r in rows], 'overdue': sorted(overdue)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('downgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 95, 'retriage': 4},
                 {'id': 'b', 'level': 3, 'arrival': 91, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('upgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 4, 'arrival': 90, 'retriage': 2},
                 {'id': 'b', 'level': 3, 'arrival': 81, 'retriage': None}]},
   {'order': ['a', 'b'], 'overdue': []}),
  ('downgraded patient overdue by new target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 79, 'retriage': 3},
                 {'id': 'b', 'level': 2, 'arrival': 95, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('wait exactly at target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 3, 'arrival': 70, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 93, 'retriage': None},
                 {'id': 'c', 'level': 1, 'arrival': 100, 'retriage': None}]},
   {'order': ['c', 'b', 'a'], 'overdue': []}),
  ('level one waiting',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 98, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 50, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated level two ties with level one',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 91, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 80, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated three ties with native two',
   {'now': 200,
    'patients': [{'id': 'x', 'level': 2, 'arrival': 194, 'retriage': None},
                 {'id': 'y', 'level': 3, 'arrival': 150, 'retriage': None}]},
   {'order': ['y', 'x'], 'overdue': ['y']}),
  ('same arrival id tie-break',
   {'now': 60,
    'patients': [{'id': 'b1', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'a1', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'c', 'level': 4, 'arrival': 11, 'retriage': None}]},
   {'order': ['c', 'a1', 'b1'], 'overdue': []})],
 [('downgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 95, 'retriage': 4},
                 {'id': 'b', 'level': 3, 'arrival': 92, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('upgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 4, 'arrival': 90, 'retriage': 2},
                 {'id': 'b', 'level': 3, 'arrival': 82, 'retriage': None}]},
   {'order': ['a', 'b'], 'overdue': []}),
  ('downgraded patient overdue by new target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 78, 'retriage': 3},
                 {'id': 'b', 'level': 2, 'arrival': 95, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('wait exactly at target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 3, 'arrival': 70, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 94, 'retriage': None},
                 {'id': 'c', 'level': 1, 'arrival': 100, 'retriage': None}]},
   {'order': ['c', 'b', 'a'], 'overdue': []}),
  ('level one waiting',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 97, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 50, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated level two ties with level one',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 92, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 80, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated three ties with native two',
   {'now': 200,
    'patients': [{'id': 'x', 'level': 2, 'arrival': 193, 'retriage': None},
                 {'id': 'y', 'level': 3, 'arrival': 150, 'retriage': None}]},
   {'order': ['y', 'x'], 'overdue': ['y']}),
  ('same arrival id tie-break',
   {'now': 60,
    'patients': [{'id': 'b2', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'a2', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'c', 'level': 4, 'arrival': 12, 'retriage': None}]},
   {'order': ['c', 'a2', 'b2'], 'overdue': []})],
 [('downgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 95, 'retriage': 4},
                 {'id': 'b', 'level': 3, 'arrival': 93, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('upgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 4, 'arrival': 90, 'retriage': 2},
                 {'id': 'b', 'level': 3, 'arrival': 83, 'retriage': None}]},
   {'order': ['a', 'b'], 'overdue': []}),
  ('downgraded patient overdue by new target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 77, 'retriage': 3},
                 {'id': 'b', 'level': 2, 'arrival': 95, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('wait exactly at target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 3, 'arrival': 70, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 95, 'retriage': None},
                 {'id': 'c', 'level': 1, 'arrival': 100, 'retriage': None}]},
   {'order': ['c', 'b', 'a'], 'overdue': []}),
  ('level one waiting',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 96, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 50, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated level two ties with level one',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 93, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 80, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated three ties with native two',
   {'now': 200,
    'patients': [{'id': 'x', 'level': 2, 'arrival': 192, 'retriage': None},
                 {'id': 'y', 'level': 3, 'arrival': 150, 'retriage': None}]},
   {'order': ['y', 'x'], 'overdue': ['y']}),
  ('same arrival id tie-break',
   {'now': 60,
    'patients': [{'id': 'b3', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'a3', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'c', 'level': 4, 'arrival': 13, 'retriage': None}]},
   {'order': ['c', 'a3', 'b3'], 'overdue': []})],
 [('downgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 95, 'retriage': 4},
                 {'id': 'b', 'level': 3, 'arrival': 94, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('upgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 4, 'arrival': 90, 'retriage': 2},
                 {'id': 'b', 'level': 3, 'arrival': 84, 'retriage': None}]},
   {'order': ['a', 'b'], 'overdue': []}),
  ('downgraded patient overdue by new target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 76, 'retriage': 3},
                 {'id': 'b', 'level': 2, 'arrival': 95, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('wait exactly at target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 3, 'arrival': 70, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 96, 'retriage': None},
                 {'id': 'c', 'level': 1, 'arrival': 100, 'retriage': None}]},
   {'order': ['c', 'b', 'a'], 'overdue': []}),
  ('level one waiting',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 95, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 50, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated level two ties with level one',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 94, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 80, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated three ties with native two',
   {'now': 200,
    'patients': [{'id': 'x', 'level': 2, 'arrival': 191, 'retriage': None},
                 {'id': 'y', 'level': 3, 'arrival': 150, 'retriage': None}]},
   {'order': ['y', 'x'], 'overdue': ['y']}),
  ('same arrival id tie-break',
   {'now': 60,
    'patients': [{'id': 'b4', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'a4', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'c', 'level': 4, 'arrival': 14, 'retriage': None}]},
   {'order': ['c', 'a4', 'b4'], 'overdue': []})],
 [('downgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 95, 'retriage': 4},
                 {'id': 'b', 'level': 3, 'arrival': 95, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('upgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 4, 'arrival': 90, 'retriage': 2},
                 {'id': 'b', 'level': 3, 'arrival': 85, 'retriage': None}]},
   {'order': ['a', 'b'], 'overdue': []}),
  ('downgraded patient overdue by new target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 75, 'retriage': 3},
                 {'id': 'b', 'level': 2, 'arrival': 95, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('wait exactly at target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 3, 'arrival': 70, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 97, 'retriage': None},
                 {'id': 'c', 'level': 1, 'arrival': 100, 'retriage': None}]},
   {'order': ['c', 'b', 'a'], 'overdue': []}),
  ('level one waiting',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 94, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 50, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated level two ties with level one',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 95, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 80, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated three ties with native two',
   {'now': 200,
    'patients': [{'id': 'x', 'level': 2, 'arrival': 190, 'retriage': None},
                 {'id': 'y', 'level': 3, 'arrival': 150, 'retriage': None}]},
   {'order': ['y', 'x'], 'overdue': ['y']}),
  ('same arrival id tie-break',
   {'now': 60,
    'patients': [{'id': 'b5', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'a5', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'c', 'level': 4, 'arrival': 15, 'retriage': None}]},
   {'order': ['c', 'a5', 'b5'], 'overdue': []})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    target = {1: 0, 2: 10, 3: 30, 4: 60, 5: 120}
    rows, overdue = [], []
    for p in x['patients']:
        lvl = p['retriage'] if p['retriage'] is not None else p['level']
        wait = x['now'] - p['arrival']
        pr = lvl
        if wait > target[lvl]:
            overdue.append(p['id'])
            pr = max(1, lvl - 1)
        rows.append((pr, lvl, p['arrival'], p['id']))
    rows.sort()
    return {'order': [r[2] for r in rows], 'overdue': sorted(overdue)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('downgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 95, 'retriage': 4},
                 {'id': 'b', 'level': 3, 'arrival': 91, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('upgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 4, 'arrival': 90, 'retriage': 2},
                 {'id': 'b', 'level': 3, 'arrival': 81, 'retriage': None}]},
   {'order': ['a', 'b'], 'overdue': []}),
  ('downgraded patient overdue by new target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 79, 'retriage': 3},
                 {'id': 'b', 'level': 2, 'arrival': 95, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('wait exactly at target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 3, 'arrival': 70, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 93, 'retriage': None},
                 {'id': 'c', 'level': 1, 'arrival': 100, 'retriage': None}]},
   {'order': ['c', 'b', 'a'], 'overdue': []}),
  ('level one waiting',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 98, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 50, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated level two ties with level one',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 91, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 80, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated three ties with native two',
   {'now': 200,
    'patients': [{'id': 'x', 'level': 2, 'arrival': 194, 'retriage': None},
                 {'id': 'y', 'level': 3, 'arrival': 150, 'retriage': None}]},
   {'order': ['y', 'x'], 'overdue': ['y']}),
  ('same arrival id tie-break',
   {'now': 60,
    'patients': [{'id': 'b1', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'a1', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'c', 'level': 4, 'arrival': 11, 'retriage': None}]},
   {'order': ['c', 'a1', 'b1'], 'overdue': []})],
 [('downgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 95, 'retriage': 4},
                 {'id': 'b', 'level': 3, 'arrival': 92, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('upgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 4, 'arrival': 90, 'retriage': 2},
                 {'id': 'b', 'level': 3, 'arrival': 82, 'retriage': None}]},
   {'order': ['a', 'b'], 'overdue': []}),
  ('downgraded patient overdue by new target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 78, 'retriage': 3},
                 {'id': 'b', 'level': 2, 'arrival': 95, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('wait exactly at target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 3, 'arrival': 70, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 94, 'retriage': None},
                 {'id': 'c', 'level': 1, 'arrival': 100, 'retriage': None}]},
   {'order': ['c', 'b', 'a'], 'overdue': []}),
  ('level one waiting',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 97, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 50, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated level two ties with level one',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 92, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 80, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated three ties with native two',
   {'now': 200,
    'patients': [{'id': 'x', 'level': 2, 'arrival': 193, 'retriage': None},
                 {'id': 'y', 'level': 3, 'arrival': 150, 'retriage': None}]},
   {'order': ['y', 'x'], 'overdue': ['y']}),
  ('same arrival id tie-break',
   {'now': 60,
    'patients': [{'id': 'b2', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'a2', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'c', 'level': 4, 'arrival': 12, 'retriage': None}]},
   {'order': ['c', 'a2', 'b2'], 'overdue': []})],
 [('downgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 95, 'retriage': 4},
                 {'id': 'b', 'level': 3, 'arrival': 93, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('upgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 4, 'arrival': 90, 'retriage': 2},
                 {'id': 'b', 'level': 3, 'arrival': 83, 'retriage': None}]},
   {'order': ['a', 'b'], 'overdue': []}),
  ('downgraded patient overdue by new target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 77, 'retriage': 3},
                 {'id': 'b', 'level': 2, 'arrival': 95, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('wait exactly at target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 3, 'arrival': 70, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 95, 'retriage': None},
                 {'id': 'c', 'level': 1, 'arrival': 100, 'retriage': None}]},
   {'order': ['c', 'b', 'a'], 'overdue': []}),
  ('level one waiting',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 96, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 50, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated level two ties with level one',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 93, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 80, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated three ties with native two',
   {'now': 200,
    'patients': [{'id': 'x', 'level': 2, 'arrival': 192, 'retriage': None},
                 {'id': 'y', 'level': 3, 'arrival': 150, 'retriage': None}]},
   {'order': ['y', 'x'], 'overdue': ['y']}),
  ('same arrival id tie-break',
   {'now': 60,
    'patients': [{'id': 'b3', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'a3', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'c', 'level': 4, 'arrival': 13, 'retriage': None}]},
   {'order': ['c', 'a3', 'b3'], 'overdue': []})],
 [('downgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 95, 'retriage': 4},
                 {'id': 'b', 'level': 3, 'arrival': 94, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('upgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 4, 'arrival': 90, 'retriage': 2},
                 {'id': 'b', 'level': 3, 'arrival': 84, 'retriage': None}]},
   {'order': ['a', 'b'], 'overdue': []}),
  ('downgraded patient overdue by new target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 76, 'retriage': 3},
                 {'id': 'b', 'level': 2, 'arrival': 95, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('wait exactly at target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 3, 'arrival': 70, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 96, 'retriage': None},
                 {'id': 'c', 'level': 1, 'arrival': 100, 'retriage': None}]},
   {'order': ['c', 'b', 'a'], 'overdue': []}),
  ('level one waiting',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 95, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 50, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated level two ties with level one',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 94, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 80, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated three ties with native two',
   {'now': 200,
    'patients': [{'id': 'x', 'level': 2, 'arrival': 191, 'retriage': None},
                 {'id': 'y', 'level': 3, 'arrival': 150, 'retriage': None}]},
   {'order': ['y', 'x'], 'overdue': ['y']}),
  ('same arrival id tie-break',
   {'now': 60,
    'patients': [{'id': 'b4', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'a4', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'c', 'level': 4, 'arrival': 14, 'retriage': None}]},
   {'order': ['c', 'a4', 'b4'], 'overdue': []})],
 [('downgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 95, 'retriage': 4},
                 {'id': 'b', 'level': 3, 'arrival': 95, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('upgraded on re-triage',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 4, 'arrival': 90, 'retriage': 2},
                 {'id': 'b', 'level': 3, 'arrival': 85, 'retriage': None}]},
   {'order': ['a', 'b'], 'overdue': []}),
  ('downgraded patient overdue by new target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 2, 'arrival': 75, 'retriage': 3},
                 {'id': 'b', 'level': 2, 'arrival': 95, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': []}),
  ('wait exactly at target',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 3, 'arrival': 70, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 97, 'retriage': None},
                 {'id': 'c', 'level': 1, 'arrival': 100, 'retriage': None}]},
   {'order': ['c', 'b', 'a'], 'overdue': []}),
  ('level one waiting',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 94, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 50, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated level two ties with level one',
   {'now': 100,
    'patients': [{'id': 'a', 'level': 1, 'arrival': 95, 'retriage': None},
                 {'id': 'b', 'level': 2, 'arrival': 80, 'retriage': None}]},
   {'order': ['b', 'a'], 'overdue': ['a', 'b']}),
  ('escalated three ties with native two',
   {'now': 200,
    'patients': [{'id': 'x', 'level': 2, 'arrival': 190, 'retriage': None},
                 {'id': 'y', 'level': 3, 'arrival': 150, 'retriage': None}]},
   {'order': ['y', 'x'], 'overdue': ['y']}),
  ('same arrival id tie-break',
   {'now': 60,
    'patients': [{'id': 'b5', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'a5', 'level': 4, 'arrival': 30, 'retriage': None},
                 {'id': 'c', 'level': 4, 'arrival': 15, 'retriage': None}]},
   {'order': ['c', 'a5', 'b5'], 'overdue': []})]]
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:
Patients at the same priority are ordered alphabetically instead of by arrival.

Input {now, patients [{id, level, arrival, retriage (or null)}]}. Effective level = retriage when present (up or down), else level. Target waits: 1:0, 2:10, 3:30, 4:60, 5:120 minutes. A patient whose wait strictly exceeds the target of the effective level is overdue and moves up one priority (never above 1). Order by (priority, arrival, id). Return {order, overdue (sorted ids)}.

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):
    a = x['age_years']
    if a < 10:
        head, leg = Fraction(18 - a), Fraction(18)
    else:
        head, leg = Fraction(9), Fraction(18)
    pct = {'head': head, 'arm_l': 9, 'arm_r': 9, 'leg_l': leg, 'leg_r': leg, 'trunk_front': 18, 'trunk_back': 18, 'perineum': 1}
    tbsa = sum(pct[k] * Fraction(str(v)) for k, v in x['regions'].items())
    major = tbsa >= (10 if a < 10 else 20)
    if not major:
        return {'tbsa': round(float(tbsa), 1), 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}
    total = 4 * Fraction(str(x['weight_kg'])) * tbsa
    h = Fraction(str(x['hours_since_burn']))
    rate = round(float(total / 2 / (8 - h)), 1) if h < 8 else None
    return {'tbsa': round(float(tbsa), 1), 'major': True, 'total_ml': round(float(total)), 'first_rate_ml_h': rate}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 65, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 3, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 22.5, 'major': True, 'total_ml': 1350, 'first_rate_ml_h': 112.5}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '1'},
    'hours_since_burn': '2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 3780, 'first_rate_ml_h': 315.0}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 72,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 5760, 'first_rate_ml_h': 480.0}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.3'}, 'hours_since_burn': '2'},
   {'tbsa': 11.7, 'major': True, 'total_ml': 842, 'first_rate_ml_h': 70.2}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.5'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 7560.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '9'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.1'},
    'hours_since_burn': '2'},
   {'tbsa': 10.8, 'major': True, 'total_ml': 346, 'first_rate_ml_h': 28.8})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 4, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 23.2, 'major': True, 'total_ml': 1395, 'first_rate_ml_h': 116.2}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '0'},
    'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 74,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 5920, 'first_rate_ml_h': 493.3}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.4'}, 'hours_since_burn': '2'},
   {'tbsa': 12.6, 'major': True, 'total_ml': 907, 'first_rate_ml_h': 75.6}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.25'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 5040.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '10'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 12.6, 'major': True, 'total_ml': 403, 'first_rate_ml_h': 33.6})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 75, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 5, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 24.0, 'major': True, 'total_ml': 1440, 'first_rate_ml_h': 120.0}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '1'},
    'hours_since_burn': '2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 3780, 'first_rate_ml_h': 315.0}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 76,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 6080, 'first_rate_ml_h': 506.7}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 13.5, 'major': True, 'total_ml': 972, 'first_rate_ml_h': 81.0}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.75'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 15120.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '11'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.3'},
    'hours_since_burn': '2'},
   {'tbsa': 14.4, 'major': True, 'total_ml': 461, 'first_rate_ml_h': 38.4})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 80, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 6, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 24.8, 'major': True, 'total_ml': 1485, 'first_rate_ml_h': 123.8}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '0'},
    'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 78,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 6240, 'first_rate_ml_h': 520.0}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.6'}, 'hours_since_burn': '2'},
   {'tbsa': 14.4, 'major': True, 'total_ml': 1037, 'first_rate_ml_h': 86.4}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 4725.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '12'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.4'},
    'hours_since_burn': '2'},
   {'tbsa': 16.2, 'major': True, 'total_ml': 518, 'first_rate_ml_h': 43.2})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 85, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 7, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 25.5, 'major': True, 'total_ml': 1530, 'first_rate_ml_h': 127.5}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '1'},
    'hours_since_burn': '2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 3780, 'first_rate_ml_h': 315.0}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 80,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 6400, 'first_rate_ml_h': 533.3}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.7'}, 'hours_since_burn': '2'},
   {'tbsa': 15.3, 'major': True, 'total_ml': 1102, 'first_rate_ml_h': 91.8}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.6'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 9450.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '13'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.5'},
    'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': True, 'total_ml': 576, 'first_rate_ml_h': 48.0})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    a = x['age_years']
    if a < 10:
        head, leg = Fraction(18 - a), Fraction(27 - a, 2)
    else:
        head, leg = Fraction(9), Fraction(18)
    pct = {'head': head, 'arm_l': 9, 'arm_r': 9, 'leg_l': leg, 'leg_r': leg, 'trunk_front': 18, 'trunk_back': 18, 'perineum': 1}
    tbsa = sum(pct[k] * Fraction(str(v)) for k, v in x['regions'].items())
    major = tbsa >= (10 if a < 10 else 20)
    if not major:
        return {'tbsa': round(float(tbsa), 1), 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}
    total = 4 * Fraction(str(x['weight_kg'])) * tbsa
    h = Fraction(str(x['hours_since_burn']))
    rate = round(float(total / 2 / (8 - h)), 1) if h < 8 else None
    return {'tbsa': round(float(tbsa), 1), 'major': True, 'total_ml': round(float(total)), 'first_rate_ml_h': rate}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 65, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 3, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 22.5, 'major': True, 'total_ml': 1350, 'first_rate_ml_h': 112.5}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '1'},
    'hours_since_burn': '2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 3780, 'first_rate_ml_h': 315.0}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 72,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 5760, 'first_rate_ml_h': 480.0}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.3'}, 'hours_since_burn': '2'},
   {'tbsa': 11.7, 'major': True, 'total_ml': 842, 'first_rate_ml_h': 70.2}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.5'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 7560.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '9'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.1'},
    'hours_since_burn': '2'},
   {'tbsa': 10.8, 'major': True, 'total_ml': 346, 'first_rate_ml_h': 28.8})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 4, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 23.2, 'major': True, 'total_ml': 1395, 'first_rate_ml_h': 116.2}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '0'},
    'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 74,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 5920, 'first_rate_ml_h': 493.3}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.4'}, 'hours_since_burn': '2'},
   {'tbsa': 12.6, 'major': True, 'total_ml': 907, 'first_rate_ml_h': 75.6}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.25'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 5040.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '10'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 12.6, 'major': True, 'total_ml': 403, 'first_rate_ml_h': 33.6})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 75, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 5, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 24.0, 'major': True, 'total_ml': 1440, 'first_rate_ml_h': 120.0}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '1'},
    'hours_since_burn': '2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 3780, 'first_rate_ml_h': 315.0}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 76,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 6080, 'first_rate_ml_h': 506.7}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 13.5, 'major': True, 'total_ml': 972, 'first_rate_ml_h': 81.0}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.75'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 15120.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '11'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.3'},
    'hours_since_burn': '2'},
   {'tbsa': 14.4, 'major': True, 'total_ml': 461, 'first_rate_ml_h': 38.4})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 80, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 6, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 24.8, 'major': True, 'total_ml': 1485, 'first_rate_ml_h': 123.8}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '0'},
    'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 78,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 6240, 'first_rate_ml_h': 520.0}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.6'}, 'hours_since_burn': '2'},
   {'tbsa': 14.4, 'major': True, 'total_ml': 1037, 'first_rate_ml_h': 86.4}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 4725.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '12'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.4'},
    'hours_since_burn': '2'},
   {'tbsa': 16.2, 'major': True, 'total_ml': 518, 'first_rate_ml_h': 43.2})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 85, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 7, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 25.5, 'major': True, 'total_ml': 1530, 'first_rate_ml_h': 127.5}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '1'},
    'hours_since_burn': '2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 3780, 'first_rate_ml_h': 315.0}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 80,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 6400, 'first_rate_ml_h': 533.3}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.7'}, 'hours_since_burn': '2'},
   {'tbsa': 15.3, 'major': True, 'total_ml': 1102, 'first_rate_ml_h': 91.8}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.6'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 9450.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '13'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.5'},
    'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': True, 'total_ml': 576, 'first_rate_ml_h': 48.0})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Leg burns in young children are over-estimated and the chart totals exceed 100%.

Input {age_years (int), weight_kg, regions {name: fraction burned}, hours_since_burn}. Toy rule of nines: arms 9, trunk front 18, trunk back 18, perineum 1; age >= 10 head 9 and each leg 18; age < 10 head 18-age and each leg (27+age)/2. TBSA = sum(region % x fraction). Major burn when TBSA >= 20 (age >= 10) or >= 10 (age < 10); minor burns return total_ml 0 and no rate. Major: total = 4 mL x kg x TBSA; half is given over the remainder of the first 8 hours measured from the burn; rate is null once 8 hours have passed. Return {tbsa (1 dp), major, total_ml, first_rate_ml_h (1 dp)}.

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):
    a = x['age_years']
    if a <= 10:
        head, leg = Fraction(18 - a), Fraction(27 + a, 2)
    else:
        head, leg = Fraction(9), Fraction(18)
    pct = {'head': head, 'arm_l': 9, 'arm_r': 9, 'leg_l': leg, 'leg_r': leg, 'trunk_front': 18, 'trunk_back': 18, 'perineum': 1}
    tbsa = sum(pct[k] * Fraction(str(v)) for k, v in x['regions'].items())
    major = tbsa >= (10 if a < 10 else 20)
    if not major:
        return {'tbsa': round(float(tbsa), 1), 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}
    total = 4 * Fraction(str(x['weight_kg'])) * tbsa
    h = Fraction(str(x['hours_since_burn']))
    rate = round(float(total / 2 / (8 - h)), 1) if h < 8 else None
    return {'tbsa': round(float(tbsa), 1), 'major': True, 'total_ml': round(float(total)), 'first_rate_ml_h': rate}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 65, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 3, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 22.5, 'major': True, 'total_ml': 1350, 'first_rate_ml_h': 112.5}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '1'},
    'hours_since_burn': '2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 3780, 'first_rate_ml_h': 315.0}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 72,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 5760, 'first_rate_ml_h': 480.0}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.3'}, 'hours_since_burn': '2'},
   {'tbsa': 11.7, 'major': True, 'total_ml': 842, 'first_rate_ml_h': 70.2}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.5'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 7560.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '9'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.1'},
    'hours_since_burn': '2'},
   {'tbsa': 10.8, 'major': True, 'total_ml': 346, 'first_rate_ml_h': 28.8})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 4, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 23.2, 'major': True, 'total_ml': 1395, 'first_rate_ml_h': 116.2}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '0'},
    'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 74,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 5920, 'first_rate_ml_h': 493.3}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.4'}, 'hours_since_burn': '2'},
   {'tbsa': 12.6, 'major': True, 'total_ml': 907, 'first_rate_ml_h': 75.6}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.25'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 5040.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '10'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 12.6, 'major': True, 'total_ml': 403, 'first_rate_ml_h': 33.6})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 75, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 5, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 24.0, 'major': True, 'total_ml': 1440, 'first_rate_ml_h': 120.0}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '1'},
    'hours_since_burn': '2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 3780, 'first_rate_ml_h': 315.0}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 76,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 6080, 'first_rate_ml_h': 506.7}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 13.5, 'major': True, 'total_ml': 972, 'first_rate_ml_h': 81.0}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.75'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 15120.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '11'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.3'},
    'hours_since_burn': '2'},
   {'tbsa': 14.4, 'major': True, 'total_ml': 461, 'first_rate_ml_h': 38.4})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 80, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 6, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 24.8, 'major': True, 'total_ml': 1485, 'first_rate_ml_h': 123.8}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '0'},
    'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 78,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 6240, 'first_rate_ml_h': 520.0}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.6'}, 'hours_since_burn': '2'},
   {'tbsa': 14.4, 'major': True, 'total_ml': 1037, 'first_rate_ml_h': 86.4}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 4725.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '12'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.4'},
    'hours_since_burn': '2'},
   {'tbsa': 16.2, 'major': True, 'total_ml': 518, 'first_rate_ml_h': 43.2})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 85, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 7, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 25.5, 'major': True, 'total_ml': 1530, 'first_rate_ml_h': 127.5}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '1'},
    'hours_since_burn': '2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 3780, 'first_rate_ml_h': 315.0}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 80,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 6400, 'first_rate_ml_h': 533.3}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.7'}, 'hours_since_burn': '2'},
   {'tbsa': 15.3, 'major': True, 'total_ml': 1102, 'first_rate_ml_h': 91.8}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.6'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 9450.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '13'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.5'},
    'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': True, 'total_ml': 576, 'first_rate_ml_h': 48.0})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    a = x['age_years']
    if a < 1:
        head, leg = Fraction(18 - a), Fraction(27 + a, 2)
    else:
        head, leg = Fraction(9), Fraction(18)
    pct = {'head': head, 'arm_l': 9, 'arm_r': 9, 'leg_l': leg, 'leg_r': leg, 'trunk_front': 18, 'trunk_back': 18, 'perineum': 1}
    tbsa = sum(pct[k] * Fraction(str(v)) for k, v in x['regions'].items())
    major = tbsa >= (10 if a < 10 else 20)
    if not major:
        return {'tbsa': round(float(tbsa), 1), 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}
    total = 4 * Fraction(str(x['weight_kg'])) * tbsa
    h = Fraction(str(x['hours_since_burn']))
    rate = round(float(total / 2 / (8 - h)), 1) if h < 8 else None
    return {'tbsa': round(float(tbsa), 1), 'major': True, 'total_ml': round(float(total)), 'first_rate_ml_h': rate}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 65, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 3, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 22.5, 'major': True, 'total_ml': 1350, 'first_rate_ml_h': 112.5}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '1'},
    'hours_since_burn': '2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 3780, 'first_rate_ml_h': 315.0}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 72,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 5760, 'first_rate_ml_h': 480.0}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.3'}, 'hours_since_burn': '2'},
   {'tbsa': 11.7, 'major': True, 'total_ml': 842, 'first_rate_ml_h': 70.2}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.5'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 7560.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '9'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.1'},
    'hours_since_burn': '2'},
   {'tbsa': 10.8, 'major': True, 'total_ml': 346, 'first_rate_ml_h': 28.8})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 4, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 23.2, 'major': True, 'total_ml': 1395, 'first_rate_ml_h': 116.2}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '0'},
    'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 74,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 5920, 'first_rate_ml_h': 493.3}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.4'}, 'hours_since_burn': '2'},
   {'tbsa': 12.6, 'major': True, 'total_ml': 907, 'first_rate_ml_h': 75.6}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.25'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 5040.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '10'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 12.6, 'major': True, 'total_ml': 403, 'first_rate_ml_h': 33.6})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 75, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 5, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 24.0, 'major': True, 'total_ml': 1440, 'first_rate_ml_h': 120.0}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '1'},
    'hours_since_burn': '2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 3780, 'first_rate_ml_h': 315.0}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 76,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 6080, 'first_rate_ml_h': 506.7}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 13.5, 'major': True, 'total_ml': 972, 'first_rate_ml_h': 81.0}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.75'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 15120.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '11'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.3'},
    'hours_since_burn': '2'},
   {'tbsa': 14.4, 'major': True, 'total_ml': 461, 'first_rate_ml_h': 38.4})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 80, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 6, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 24.8, 'major': True, 'total_ml': 1485, 'first_rate_ml_h': 123.8}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '0'},
    'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 78,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 6240, 'first_rate_ml_h': 520.0}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.6'}, 'hours_since_burn': '2'},
   {'tbsa': 14.4, 'major': True, 'total_ml': 1037, 'first_rate_ml_h': 86.4}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 4725.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '12'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.4'},
    'hours_since_burn': '2'},
   {'tbsa': 16.2, 'major': True, 'total_ml': 518, 'first_rate_ml_h': 43.2})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 85, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 7, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 25.5, 'major': True, 'total_ml': 1530, 'first_rate_ml_h': 127.5}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '1'},
    'hours_since_burn': '2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 3780, 'first_rate_ml_h': 315.0}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 80,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 6400, 'first_rate_ml_h': 533.3}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.7'}, 'hours_since_burn': '2'},
   {'tbsa': 15.3, 'major': True, 'total_ml': 1102, 'first_rate_ml_h': 91.8}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.6'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 9450.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '13'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.5'},
    'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': True, 'total_ml': 576, 'first_rate_ml_h': 48.0})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A ten-year-old is charted with child proportions.

Input {age_years (int), weight_kg, regions {name: fraction burned}, hours_since_burn}. Toy rule of nines: arms 9, trunk front 18, trunk back 18, perineum 1; age >= 10 head 9 and each leg 18; age < 10 head 18-age and each leg (27+age)/2. TBSA = sum(region % x fraction). Major burn when TBSA >= 20 (age >= 10) or >= 10 (age < 10); minor burns return total_ml 0 and no rate. Major: total = 4 mL x kg x TBSA; half is given over the remainder of the first 8 hours measured from the burn; rate is null once 8 hours have passed. Return {tbsa (1 dp), major, total_ml, first_rate_ml_h (1 dp)}.

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):
    a = x['age_years']
    if a < 10:
        head, leg = Fraction(18 - a), Fraction(27 + a, 2)
    else:
        head, leg = Fraction(9), Fraction(18)
    pct = {'head': head, 'arm_l': 9, 'arm_r': 9, 'leg_l': leg, 'leg_r': leg, 'trunk_front': 18, 'trunk_back': 18, 'perineum': 1}
    tbsa = sum(pct[k] * Fraction(str(v)) for k, v in x['regions'].items())
    major = tbsa > (10 if a < 10 else 20)
    if not major:
        return {'tbsa': round(float(tbsa), 1), 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}
    total = 4 * Fraction(str(x['weight_kg'])) * tbsa
    h = Fraction(str(x['hours_since_burn']))
    rate = round(float(total / 2 / (8 - h)), 1) if h < 8 else None
    return {'tbsa': round(float(tbsa), 1), 'major': True, 'total_ml': round(float(total)), 'first_rate_ml_h': rate}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 65, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 3, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 22.5, 'major': True, 'total_ml': 1350, 'first_rate_ml_h': 112.5}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '1'},
    'hours_since_burn': '2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 3780, 'first_rate_ml_h': 315.0}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 72,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 5760, 'first_rate_ml_h': 480.0}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.3'}, 'hours_since_burn': '2'},
   {'tbsa': 11.7, 'major': True, 'total_ml': 842, 'first_rate_ml_h': 70.2}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.5'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 7560.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '9'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.1'},
    'hours_since_burn': '2'},
   {'tbsa': 10.8, 'major': True, 'total_ml': 346, 'first_rate_ml_h': 28.8})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 4, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 23.2, 'major': True, 'total_ml': 1395, 'first_rate_ml_h': 116.2}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '0'},
    'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 74,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 5920, 'first_rate_ml_h': 493.3}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.4'}, 'hours_since_burn': '2'},
   {'tbsa': 12.6, 'major': True, 'total_ml': 907, 'first_rate_ml_h': 75.6}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.25'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 5040.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '10'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 12.6, 'major': True, 'total_ml': 403, 'first_rate_ml_h': 33.6})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 75, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 5, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 24.0, 'major': True, 'total_ml': 1440, 'first_rate_ml_h': 120.0}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '1'},
    'hours_since_burn': '2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 3780, 'first_rate_ml_h': 315.0}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 76,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 6080, 'first_rate_ml_h': 506.7}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 13.5, 'major': True, 'total_ml': 972, 'first_rate_ml_h': 81.0}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.75'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 15120.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '11'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.3'},
    'hours_since_burn': '2'},
   {'tbsa': 14.4, 'major': True, 'total_ml': 461, 'first_rate_ml_h': 38.4})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 80, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 6, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 24.8, 'major': True, 'total_ml': 1485, 'first_rate_ml_h': 123.8}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '0'},
    'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 78,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 6240, 'first_rate_ml_h': 520.0}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.6'}, 'hours_since_burn': '2'},
   {'tbsa': 14.4, 'major': True, 'total_ml': 1037, 'first_rate_ml_h': 86.4}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 4725.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '12'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.4'},
    'hours_since_burn': '2'},
   {'tbsa': 16.2, 'major': True, 'total_ml': 518, 'first_rate_ml_h': 43.2})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 85, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 7, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 25.5, 'major': True, 'total_ml': 1530, 'first_rate_ml_h': 127.5}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '1'},
    'hours_since_burn': '2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 3780, 'first_rate_ml_h': 315.0}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 80,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 6400, 'first_rate_ml_h': 533.3}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.7'}, 'hours_since_burn': '2'},
   {'tbsa': 15.3, 'major': True, 'total_ml': 1102, 'first_rate_ml_h': 91.8}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.6'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 9450.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '13'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.5'},
    'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': True, 'total_ml': 576, 'first_rate_ml_h': 48.0})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    a = x['age_years']
    if a < 10:
        head, leg = Fraction(18 - a), Fraction(27 + a, 2)
    else:
        head, leg = Fraction(9), Fraction(18)
    pct = {'head': head, 'arm_l': 9, 'arm_r': 9, 'leg_l': leg, 'leg_r': leg, 'trunk_front': 18, 'trunk_back': 18, 'perineum': 1}
    tbsa = sum(pct[k] * Fraction(str(v)) for k, v in x['regions'].items())
    major = tbsa >= 20
    if not major:
        return {'tbsa': round(float(tbsa), 1), 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}
    total = 4 * Fraction(str(x['weight_kg'])) * tbsa
    h = Fraction(str(x['hours_since_burn']))
    rate = round(float(total / 2 / (8 - h)), 1) if h < 8 else None
    return {'tbsa': round(float(tbsa), 1), 'major': True, 'total_ml': round(float(total)), 'first_rate_ml_h': rate}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 65, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 3, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 22.5, 'major': True, 'total_ml': 1350, 'first_rate_ml_h': 112.5}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '1'},
    'hours_since_burn': '2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 3780, 'first_rate_ml_h': 315.0}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 72,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 5760, 'first_rate_ml_h': 480.0}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.3'}, 'hours_since_burn': '2'},
   {'tbsa': 11.7, 'major': True, 'total_ml': 842, 'first_rate_ml_h': 70.2}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.5'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 7560.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '9'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.1'},
    'hours_since_burn': '2'},
   {'tbsa': 10.8, 'major': True, 'total_ml': 346, 'first_rate_ml_h': 28.8})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 4, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 23.2, 'major': True, 'total_ml': 1395, 'first_rate_ml_h': 116.2}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '0'},
    'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 74,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 5920, 'first_rate_ml_h': 493.3}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.4'}, 'hours_since_burn': '2'},
   {'tbsa': 12.6, 'major': True, 'total_ml': 907, 'first_rate_ml_h': 75.6}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.25'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 5040.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '10'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 12.6, 'major': True, 'total_ml': 403, 'first_rate_ml_h': 33.6})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 75, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 5, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 24.0, 'major': True, 'total_ml': 1440, 'first_rate_ml_h': 120.0}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '1'},
    'hours_since_burn': '2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 3780, 'first_rate_ml_h': 315.0}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 76,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 6080, 'first_rate_ml_h': 506.7}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 13.5, 'major': True, 'total_ml': 972, 'first_rate_ml_h': 81.0}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.75'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 15120.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '11'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.3'},
    'hours_since_burn': '2'},
   {'tbsa': 14.4, 'major': True, 'total_ml': 461, 'first_rate_ml_h': 38.4})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 80, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 6, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 24.8, 'major': True, 'total_ml': 1485, 'first_rate_ml_h': 123.8}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '0'},
    'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 78,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 6240, 'first_rate_ml_h': 520.0}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.6'}, 'hours_since_burn': '2'},
   {'tbsa': 14.4, 'major': True, 'total_ml': 1037, 'first_rate_ml_h': 86.4}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 4725.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '12'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.4'},
    'hours_since_burn': '2'},
   {'tbsa': 16.2, 'major': True, 'total_ml': 518, 'first_rate_ml_h': 43.2})],
 [('adult anterior trunk',
   {'age_years': 30, 'weight_kg': 85, 'regions': {'trunk_front': '1'}, 'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': False, 'total_ml': 0, 'first_rate_ml_h': None}),
  ('child legs use adjusted proportion',
   {'age_years': 7, 'weight_kg': 15, 'regions': {'leg_l': '1', 'leg_r': '0.5'}, 'hours_since_burn': '2'},
   {'tbsa': 25.5, 'major': True, 'total_ml': 1530, 'first_rate_ml_h': 127.5}),
  ('ten-year-old uses adult proportions',
   {'age_years': 10,
    'weight_kg': 35,
    'regions': {'head': '1', 'leg_l': '0.5', 'arm_l': '1'},
    'hours_since_burn': '2'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 3780, 'first_rate_ml_h': 315.0}),
  ('adult exactly 20 percent',
   {'age_years': 30,
    'weight_kg': 80,
    'regions': {'trunk_front': '0.5', 'head': '1', 'arm_l': '0.2', 'perineum': '0.2'},
    'hours_since_burn': '2'},
   {'tbsa': 20.0, 'major': True, 'total_ml': 6400, 'first_rate_ml_h': 533.3}),
  ('child 12 percent is major',
   {'age_years': 4, 'weight_kg': 18, 'regions': {'arm_l': '1', 'arm_r': '0.7'}, 'hours_since_burn': '2'},
   {'tbsa': 15.3, 'major': True, 'total_ml': 1102, 'first_rate_ml_h': 91.8}),
  ('late arrival shortens first window',
   {'age_years': 30,
    'weight_kg': 70,
    'regions': {'trunk_front': '1', 'leg_l': '0.5'},
    'hours_since_burn': '7.6'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': 9450.0}),
  ('beyond eight hours',
   {'age_years': 30, 'weight_kg': 70, 'regions': {'trunk_back': '1', 'arm_l': '1'}, 'hours_since_burn': '13'},
   {'tbsa': 27.0, 'major': True, 'total_ml': 7560, 'first_rate_ml_h': None}),
  ('infant head burn',
   {'age_years': 0,
    'weight_kg': 8,
    'regions': {'head': '0.5', 'trunk_front': '0.5'},
    'hours_since_burn': '2'},
   {'tbsa': 18.0, 'major': True, 'total_ml': 576, 'first_rate_ml_h': 48.0})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
An adult with exactly 20% TBSA is classified as a minor burn.

Input {age_years (int), weight_kg, regions {name: fraction burned}, hours_since_burn}. Toy rule of nines: arms 9, trunk front 18, trunk back 18, perineum 1; age >= 10 head 9 and each leg 18; age < 10 head 18-age and each leg (27+age)/2. TBSA = sum(region % x fraction). Major burn when TBSA >= 20 (age >= 10) or >= 10 (age < 10); minor burns return total_ml 0 and no rate. Major: total = 4 mL x kg x TBSA; half is given over the remainder of the first 8 hours measured from the burn; rate is null once 8 hours have passed. Return {tbsa (1 dp), major, total_ml, first_rate_ml_h (1 dp)}.

split: open-access