broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    pct = Fraction(x['pef'] * 100, x['best'])
    if pct <= 33 or x['spo2'] < 92:
        sev = 'LIFE_THREATENING'
    elif pct <= 50 or x['rr'] >= 25 or x['hr'] >= 110 or not x['sentences']:
        sev = 'ACUTE_SEVERE'
    elif pct <= 75:
        sev = 'MODERATE'
    else:
        sev = 'MILD'
    return {'pct': round(float(pct), 1), 'severity': sev}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('mild control',
   {'pef': 430, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 86.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 310, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 62.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 91, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 19, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 331, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.2, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 26, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 11},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 116, 'age': 6},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 401, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.2, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 110, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 24.4, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 440, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 88.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 320, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 64.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 92, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 20, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 332, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.4, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 27, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 12},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 117, 'age': 7},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 402, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.4, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 120, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 26.7, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 450, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 90.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 330, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 93, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 21, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 333, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.6, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 28, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 13},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 118, 'age': 8},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 403, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.6, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 130, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 28.9, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 460, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 92.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 340, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 68.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 94, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 22, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 334, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.8, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 29, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 14},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 119, 'age': 9},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 404, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.8, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 140, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 31.1, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 470, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 94.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 95, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 23, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 335, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 67.0, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 30, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 15},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 120, 'age': 10},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 405, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 81.0, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 150, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 33.3, 'severity': 'ACUTE_SEVERE'})]]
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):
    pct = Fraction(x['pef'] * 100, x['best'])
    if pct < 33 and x['spo2'] < 92:
        sev = 'LIFE_THREATENING'
    elif pct <= 50 or x['rr'] >= 25 or x['hr'] >= 110 or not x['sentences']:
        sev = 'ACUTE_SEVERE'
    elif pct <= 75:
        sev = 'MODERATE'
    else:
        sev = 'MILD'
    return {'pct': round(float(pct), 1), 'severity': sev}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('mild control',
   {'pef': 430, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 86.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 310, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 62.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 91, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 19, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 331, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.2, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 26, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 11},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 116, 'age': 6},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 401, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.2, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 110, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 24.4, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 440, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 88.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 320, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 64.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 92, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 20, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 332, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.4, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 27, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 12},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 117, 'age': 7},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 402, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.4, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 120, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 26.7, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 450, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 90.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 330, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 93, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 21, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 333, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.6, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 28, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 13},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 118, 'age': 8},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 403, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.6, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 130, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 28.9, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 460, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 92.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 340, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 68.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 94, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 22, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 334, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.8, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 29, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 14},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 119, 'age': 9},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 404, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.8, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 140, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 31.1, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 470, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 94.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 95, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 23, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 335, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 67.0, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 30, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 15},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 120, 'age': 10},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 405, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 81.0, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 150, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 33.3, 'severity': 'ACUTE_SEVERE'})]]
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 peak flow of exactly 33% is graded life-threatening.

Input {pef, best (best or predicted PEF), spo2, sentences (can complete sentences), rr, hr, age}. pct = pef*100/best. Toy classification: LIFE_THREATENING when pct < 33 or spo2 < 92; ACUTE_SEVERE when pct <= 50, rr >= 25, hr >= 110 or sentences cannot be completed; MODERATE when pct <= 75; else MILD. Return {pct (1 dp), severity}.

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):
    pct = Fraction(x['pef'] * 100, x['best'])
    if pct < 33 or x['spo2'] < 92:
        sev = 'LIFE_THREATENING'
    elif pct < 50 or x['rr'] >= 25 or x['hr'] >= 110 or not x['sentences']:
        sev = 'ACUTE_SEVERE'
    elif pct <= 75:
        sev = 'MODERATE'
    else:
        sev = 'MILD'
    return {'pct': round(float(pct), 1), 'severity': sev}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('mild control',
   {'pef': 430, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 86.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 310, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 62.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 91, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 19, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 331, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.2, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 26, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 11},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 116, 'age': 6},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 401, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.2, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 110, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 24.4, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 440, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 88.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 320, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 64.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 92, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 20, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 332, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.4, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 27, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 12},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 117, 'age': 7},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 402, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.4, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 120, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 26.7, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 450, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 90.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 330, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 93, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 21, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 333, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.6, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 28, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 13},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 118, 'age': 8},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 403, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.6, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 130, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 28.9, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 460, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 92.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 340, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 68.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 94, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 22, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 334, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.8, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 29, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 14},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 119, 'age': 9},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 404, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.8, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 140, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 31.1, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 470, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 94.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 95, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 23, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 335, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 67.0, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 30, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 15},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 120, 'age': 10},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 405, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 81.0, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 150, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 33.3, 'severity': 'ACUTE_SEVERE'})]]
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):
    pct = Fraction(x['pef'] * 100, x['best'])
    if pct < 33 or x['spo2'] < 92:
        sev = 'LIFE_THREATENING'
    elif (pct <= 50 and x['rr'] >= 25) or x['rr'] >= 25 or x['hr'] >= 110 or not x['sentences']:
        sev = 'ACUTE_SEVERE'
    elif pct <= 75:
        sev = 'MODERATE'
    else:
        sev = 'MILD'
    return {'pct': round(float(pct), 1), 'severity': sev}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('mild control',
   {'pef': 430, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 86.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 310, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 62.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 91, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 19, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 331, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.2, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 26, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 11},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 116, 'age': 6},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 401, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.2, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 110, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 24.4, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 440, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 88.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 320, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 64.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 92, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 20, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 332, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.4, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 27, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 12},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 117, 'age': 7},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 402, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.4, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 120, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 26.7, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 450, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 90.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 330, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 93, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 21, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 333, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.6, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 28, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 13},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 118, 'age': 8},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 403, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.6, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 130, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 28.9, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 460, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 92.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 340, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 68.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 94, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 22, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 334, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.8, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 29, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 14},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 119, 'age': 9},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 404, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.8, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 140, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 31.1, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 470, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 94.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 95, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 23, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 335, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 67.0, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 30, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 15},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 120, 'age': 10},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 405, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 81.0, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 150, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 33.3, 'severity': 'ACUTE_SEVERE'})]]
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 peak flow of exactly 50% is graded moderate.

Input {pef, best (best or predicted PEF), spo2, sentences (can complete sentences), rr, hr, age}. pct = pef*100/best. Toy classification: LIFE_THREATENING when pct < 33 or spo2 < 92; ACUTE_SEVERE when pct <= 50, rr >= 25, hr >= 110 or sentences cannot be completed; MODERATE when pct <= 75; else MILD. Return {pct (1 dp), severity}.

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):
    pct = Fraction(x['pef'] * 100, x['best'])
    if pct < 33 or x['spo2'] < 92:
        sev = 'LIFE_THREATENING'
    elif pct <= 50 or x['rr'] >= 25 or x['hr'] > 110 or not x['sentences']:
        sev = 'ACUTE_SEVERE'
    elif pct <= 75:
        sev = 'MODERATE'
    else:
        sev = 'MILD'
    return {'pct': round(float(pct), 1), 'severity': sev}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('mild control',
   {'pef': 430, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 86.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 310, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 62.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 91, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 19, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 331, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.2, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 26, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 11},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 116, 'age': 6},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 401, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.2, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 110, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 24.4, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 440, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 88.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 320, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 64.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 92, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 20, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 332, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.4, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 27, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 12},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 117, 'age': 7},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 402, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.4, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 120, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 26.7, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 450, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 90.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 330, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 93, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 21, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 333, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.6, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 28, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 13},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 118, 'age': 8},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 403, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.6, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 130, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 28.9, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 460, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 92.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 340, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 68.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 94, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 22, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 334, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.8, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 29, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 14},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 119, 'age': 9},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 404, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.8, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 140, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 31.1, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 470, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 94.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 95, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 23, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 335, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 67.0, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 30, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 15},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 120, 'age': 10},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 405, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 81.0, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 150, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 33.3, 'severity': 'ACUTE_SEVERE'})]]
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):
    pct = Fraction(x['pef'] * 100, x['best'])
    if pct < 33 or x['spo2'] < 92:
        sev = 'LIFE_THREATENING'
    elif pct <= 50 or x['rr'] >= 25 or (x['hr'] >= 110 and x['age'] >= 12) or not x['sentences']:
        sev = 'ACUTE_SEVERE'
    elif pct <= 75:
        sev = 'MODERATE'
    else:
        sev = 'MILD'
    return {'pct': round(float(pct), 1), 'severity': sev}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('mild control',
   {'pef': 430, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 86.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 310, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 62.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 91, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 19, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 331, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.2, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 26, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 11},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 116, 'age': 6},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 401, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.2, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 110, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 24.4, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 440, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 88.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 320, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 64.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 92, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 20, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 332, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.4, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 27, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 12},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 117, 'age': 7},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 402, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.4, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 120, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 26.7, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 450, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 90.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 330, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 93, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 21, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 333, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.6, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 28, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 13},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 118, 'age': 8},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 403, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.6, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 130, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 28.9, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 460, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 92.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 340, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 68.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 94, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 22, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 334, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 66.8, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 29, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 14},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 119, 'age': 9},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 404, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 80.8, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 140, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 31.1, 'severity': 'LIFE_THREATENING'})],
 [('mild control',
   {'pef': 470, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 94.0, 'severity': 'MILD'}),
  ('moderate',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'MODERATE'}),
  ('exactly 50 percent',
   {'pef': 250, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 95, 'age': 30},
   {'pct': 50.0, 'severity': 'ACUTE_SEVERE'}),
  ('exactly 33 percent',
   {'pef': 165, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 23, 'hr': 90, 'age': 30},
   {'pct': 33.0, 'severity': 'ACUTE_SEVERE'}),
  ('hypoxic with fair peak flow',
   {'pef': 335, 'best': 500, 'spo2': 90, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 67.0, 'severity': 'LIFE_THREATENING'}),
  ('severe by rate alone',
   {'pef': 350, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 30, 'hr': 90, 'age': 30},
   {'pct': 70.0, 'severity': 'ACUTE_SEVERE'}),
  ('heart rate exactly 110',
   {'pef': 360, 'best': 500, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 110, 'age': 15},
   {'pct': 72.0, 'severity': 'ACUTE_SEVERE'}),
  ('tachycardic child',
   {'pef': 200, 'best': 250, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 120, 'age': 10},
   {'pct': 80.0, 'severity': 'ACUTE_SEVERE'}),
  ('cannot finish sentences',
   {'pef': 405, 'best': 500, 'spo2': 97, 'sentences': False, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 81.0, 'severity': 'ACUTE_SEVERE'}),
  ('below one third',
   {'pef': 150, 'best': 450, 'spo2': 97, 'sentences': True, 'rr': 18, 'hr': 90, 'age': 30},
   {'pct': 33.3, 'severity': 'ACUTE_SEVERE'})]]
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 heart rate of exactly 110 is not treated as a severe sign.

Input {pef, best (best or predicted PEF), spo2, sentences (can complete sentences), rr, hr, age}. pct = pef*100/best. Toy classification: LIFE_THREATENING when pct < 33 or spo2 < 92; ACUTE_SEVERE when pct <= 50, rr >= 25, hr >= 110 or sentences cannot be completed; MODERATE when pct <= 75; else MILD. Return {pct (1 dp), severity}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(beta, gamma, pop, i0, days, substeps):
    if pop <= 0 or i0 < 0 or i0 > pop or substeps < 1:
        return None
    dt = 1.0 / substeps
    s = float(pop - i0)
    i = float(i0)
    r = 0.0
    peak_i = i
    peak_day = 0
    for day in range(1, days + 1):
        for _ in range(substeps):
            new_inf = min(beta * s * i * dt, s)
            new_rec = gamma * i * dt
            s -= new_inf
            i += new_inf - new_rec
            r += new_rec
        if i > peak_i:
            peak_i = i
            peak_day = day
    return [round(s, 3), round(peak_i, 3), peak_day, round(r, 3)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('regression: fast outbreak daily steps', (0.9, 0.2, 500, 5, 40, 1), [2.433, 249.994, 10, 497.014]),
  ('regression: subcritical seed decays', (0.08, 0.2, 1000, 10, 20, 2), [984.011, 10.0, 0, 15.167]),
  ('control: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('regression: overshoot-prone large beta two steps', (2.5, 0.3, 200, 80, 6, 2), [0.0, 156.8, 1, 166.339]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0])],
 [('control: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('regression: overshoot-prone large beta two steps', (2.5, 0.3, 200, 80, 6, 2), [0.0, 156.8, 1, 166.339]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('control: invalid zero substeps', (0.5, 0.1, 100, 1, 10, 0), None),
  ('regression: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639])],
 [('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('control: invalid zero substeps', (0.5, 0.1, 100, 1, 10, 0), None),
  ('regression: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639]),
  ('regression: large city fine steps',
   (0.4, 0.15, 100000, 20, 50, 8),
   [13105.196, 25867.476, 37, 75829.968]),
  ('regression: small village', (0.6, 0.25, 50, 1, 30, 2), [5.845, 11.78, 12, 43.206]),
  ('control: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])],
 [('regression: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('control: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('regression: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639]),
  ('regression: large city fine steps',
   (0.4, 0.15, 100000, 20, 50, 8),
   [13105.196, 25867.476, 37, 75829.968]),
  ('regression: small village', (0.6, 0.25, 50, 1, 30, 2), [5.845, 11.78, 12, 43.206]),
  ('control: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])],
 [('regression: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('regression: fast outbreak daily steps', (0.9, 0.2, 500, 5, 40, 1), [2.433, 249.994, 10, 497.014]),
  ('regression: subcritical seed decays', (0.08, 0.2, 1000, 10, 20, 2), [984.011, 10.0, 0, 15.167]),
  ('control: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('regression: overshoot-prone large beta two steps', (2.5, 0.3, 200, 80, 6, 2), [0.0, 156.8, 1, 166.339]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])]]
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
N = 1
observations = []
def solve(beta, gamma, pop, i0, days, substeps):
    if pop <= 0 or i0 < 0 or i0 > pop or substeps < 1:
        return None
    dt = 1.0 / substeps
    s = float(pop - i0)
    i = float(i0)
    r = 0.0
    peak_i = i
    peak_day = 0
    for day in range(1, days + 1):
        for _ in range(substeps):
            new_inf = min(beta * s * i / (s + i) * dt, s)
            new_rec = gamma * i * dt
            s -= new_inf
            i += new_inf - new_rec
            r += new_rec
        if i > peak_i:
            peak_i = i
            peak_day = day
    return [round(s, 3), round(peak_i, 3), peak_day, round(r, 3)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('regression: fast outbreak daily steps', (0.9, 0.2, 500, 5, 40, 1), [2.433, 249.994, 10, 497.014]),
  ('regression: subcritical seed decays', (0.08, 0.2, 1000, 10, 20, 2), [984.011, 10.0, 0, 15.167]),
  ('control: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('regression: overshoot-prone large beta two steps', (2.5, 0.3, 200, 80, 6, 2), [0.0, 156.8, 1, 166.339]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0])],
 [('control: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('regression: overshoot-prone large beta two steps', (2.5, 0.3, 200, 80, 6, 2), [0.0, 156.8, 1, 166.339]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('control: invalid zero substeps', (0.5, 0.1, 100, 1, 10, 0), None),
  ('regression: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639])],
 [('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('control: invalid zero substeps', (0.5, 0.1, 100, 1, 10, 0), None),
  ('regression: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639]),
  ('regression: large city fine steps',
   (0.4, 0.15, 100000, 20, 50, 8),
   [13105.196, 25867.476, 37, 75829.968]),
  ('regression: small village', (0.6, 0.25, 50, 1, 30, 2), [5.845, 11.78, 12, 43.206]),
  ('control: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])],
 [('regression: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('control: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('regression: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639]),
  ('regression: large city fine steps',
   (0.4, 0.15, 100000, 20, 50, 8),
   [13105.196, 25867.476, 37, 75829.968]),
  ('regression: small village', (0.6, 0.25, 50, 1, 30, 2), [5.845, 11.78, 12, 43.206]),
  ('control: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])],
 [('regression: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('regression: fast outbreak daily steps', (0.9, 0.2, 500, 5, 40, 1), [2.433, 249.994, 10, 497.014]),
  ('regression: subcritical seed decays', (0.08, 0.2, 1000, 10, 20, 2), [984.011, 10.0, 0, 15.167]),
  ('control: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('regression: overshoot-prone large beta two steps', (2.5, 0.3, 200, 80, 6, 2), [0.0, 156.8, 1, 166.339]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])]]
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:
Outbreak size explodes with population size and susceptibles are exhausted within the first substep.

Frequency-dependent SIR integrated with forward Euler at dt=1/substeps; new infections per substep are beta*S*I/pop*dt capped at S; peak prevalence and its day are sampled at day ends (day 0 is the seed); return [S, peak I, peak day, R] rounded to 3 decimals, or None for invalid input.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(beta, gamma, pop, i0, days, substeps):
    if pop <= 0 or i0 < 0 or i0 > pop or substeps < 1:
        return None
    dt = 1.0 / substeps
    s = float(pop - i0)
    i = float(i0)
    r = 0.0
    peak_i = i
    peak_day = 0
    for day in range(1, days + 1):
        for _ in range(substeps):
            new_inf = beta * s * i / pop * dt
            new_rec = gamma * i * dt
            s -= new_inf
            i += new_inf - new_rec
            r += new_rec
        if i > peak_i:
            peak_i = i
            peak_day = day
    return [round(s, 3), round(peak_i, 3), peak_day, round(r, 3)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('control: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('control: fast outbreak daily steps', (0.9, 0.2, 500, 5, 40, 1), [2.433, 249.994, 10, 497.014]),
  ('control: subcritical seed decays', (0.08, 0.2, 1000, 10, 20, 2), [984.011, 10.0, 0, 15.167]),
  ('regression: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('control: overshoot-prone large beta two steps', (2.5, 0.3, 200, 80, 6, 2), [0.0, 156.8, 1, 166.339]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0])],
 [('regression: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('control: overshoot-prone large beta two steps', (2.5, 0.3, 200, 80, 6, 2), [0.0, 156.8, 1, 166.339]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('control: invalid zero substeps', (0.5, 0.1, 100, 1, 10, 0), None),
  ('control: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639])],
 [('regression: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('control: invalid zero substeps', (0.5, 0.1, 100, 1, 10, 0), None),
  ('control: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639]),
  ('control: large city fine steps', (0.4, 0.15, 100000, 20, 50, 8), [13105.196, 25867.476, 37, 75829.968]),
  ('control: small village', (0.6, 0.25, 50, 1, 30, 2), [5.845, 11.78, 12, 43.206])],
 [('control: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('control: fast outbreak daily steps', (0.9, 0.2, 500, 5, 40, 1), [2.433, 249.994, 10, 497.014]),
  ('regression: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('control: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639]),
  ('control: large city fine steps', (0.4, 0.15, 100000, 20, 50, 8), [13105.196, 25867.476, 37, 75829.968]),
  ('control: small village', (0.6, 0.25, 50, 1, 30, 2), [5.845, 11.78, 12, 43.206]),
  ('control: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])],
 [('control: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('control: fast outbreak daily steps', (0.9, 0.2, 500, 5, 40, 1), [2.433, 249.994, 10, 497.014]),
  ('control: subcritical seed decays', (0.08, 0.2, 1000, 10, 20, 2), [984.011, 10.0, 0, 15.167]),
  ('regression: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('control: overshoot-prone large beta two steps', (2.5, 0.3, 200, 80, 6, 2), [0.0, 156.8, 1, 166.339]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])]]
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
N = 1
observations = []
def solve(beta, gamma, pop, i0, days, substeps):
    if pop <= 0 or i0 < 0 or i0 > pop or substeps < 1:
        return None
    dt = 1.0 / substeps
    s = float(pop - i0)
    i = float(i0)
    r = 0.0
    peak_i = i
    peak_day = 0
    for day in range(1, days + 1):
        for _ in range(substeps):
            new_inf = min(beta * s * i / pop * dt, pop)
            new_rec = gamma * i * dt
            s -= new_inf
            i += new_inf - new_rec
            r += new_rec
        if i > peak_i:
            peak_i = i
            peak_day = day
    return [round(s, 3), round(peak_i, 3), peak_day, round(r, 3)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('control: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('control: fast outbreak daily steps', (0.9, 0.2, 500, 5, 40, 1), [2.433, 249.994, 10, 497.014]),
  ('control: subcritical seed decays', (0.08, 0.2, 1000, 10, 20, 2), [984.011, 10.0, 0, 15.167]),
  ('regression: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('control: overshoot-prone large beta two steps', (2.5, 0.3, 200, 80, 6, 2), [0.0, 156.8, 1, 166.339]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0])],
 [('regression: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('control: overshoot-prone large beta two steps', (2.5, 0.3, 200, 80, 6, 2), [0.0, 156.8, 1, 166.339]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('control: invalid zero substeps', (0.5, 0.1, 100, 1, 10, 0), None),
  ('control: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639])],
 [('regression: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('control: invalid zero substeps', (0.5, 0.1, 100, 1, 10, 0), None),
  ('control: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639]),
  ('control: large city fine steps', (0.4, 0.15, 100000, 20, 50, 8), [13105.196, 25867.476, 37, 75829.968]),
  ('control: small village', (0.6, 0.25, 50, 1, 30, 2), [5.845, 11.78, 12, 43.206])],
 [('control: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('control: fast outbreak daily steps', (0.9, 0.2, 500, 5, 40, 1), [2.433, 249.994, 10, 497.014]),
  ('regression: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('control: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639]),
  ('control: large city fine steps', (0.4, 0.15, 100000, 20, 50, 8), [13105.196, 25867.476, 37, 75829.968]),
  ('control: small village', (0.6, 0.25, 50, 1, 30, 2), [5.845, 11.78, 12, 43.206]),
  ('control: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])],
 [('control: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('control: fast outbreak daily steps', (0.9, 0.2, 500, 5, 40, 1), [2.433, 249.994, 10, 497.014]),
  ('control: subcritical seed decays', (0.08, 0.2, 1000, 10, 20, 2), [984.011, 10.0, 0, 15.167]),
  ('regression: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('control: overshoot-prone large beta two steps', (2.5, 0.3, 200, 80, 6, 2), [0.0, 156.8, 1, 166.339]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])]]
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:
With large beta*dt the susceptible pool goes negative and recovered exceeds the population.

Frequency-dependent SIR integrated with forward Euler at dt=1/substeps; new infections per substep are beta*S*I/pop*dt capped at S; peak prevalence and its day are sampled at day ends (day 0 is the seed); return [S, peak I, peak day, R] rounded to 3 decimals, or None for invalid input.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(beta, gamma, pop, i0, days, substeps):
    if pop <= 0 or i0 < 0 or i0 > pop or substeps < 1:
        return None
    dt = 1.0 / substeps
    s = float(pop - i0)
    i = float(i0)
    r = 0.0
    peak_i = i
    peak_day = 0
    for day in range(1, days + 1):
        for _ in range(substeps):
            new_inf = min(beta * s * i / pop * dt, s)
            new_rec = gamma * i
            s -= new_inf
            i += new_inf - new_rec
            r += new_rec
        if i > peak_i:
            peak_i = i
            peak_day = day
    return [round(s, 3), round(peak_i, 3), peak_day, round(r, 3)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('regression: fast outbreak daily steps', (0.9, 0.2, 500, 5, 40, 1), [2.433, 249.994, 10, 497.014]),
  ('regression: subcritical seed decays', (0.08, 0.2, 1000, 10, 20, 2), [984.011, 10.0, 0, 15.167]),
  ('regression: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None)],
 [('regression: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('regression: overshoot-prone large beta two steps', (2.5, 0.3, 200, 80, 6, 2), [0.0, 156.8, 1, 166.339]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('control: invalid zero substeps', (0.5, 0.1, 100, 1, 10, 0), None),
  ('regression: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639])],
 [('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('control: invalid zero substeps', (0.5, 0.1, 100, 1, 10, 0), None),
  ('regression: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639]),
  ('regression: large city fine steps',
   (0.4, 0.15, 100000, 20, 50, 8),
   [13105.196, 25867.476, 37, 75829.968]),
  ('regression: small village', (0.6, 0.25, 50, 1, 30, 2), [5.845, 11.78, 12, 43.206]),
  ('regression: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])],
 [('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('regression: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639]),
  ('regression: large city fine steps',
   (0.4, 0.15, 100000, 20, 50, 8),
   [13105.196, 25867.476, 37, 75829.968]),
  ('regression: small village', (0.6, 0.25, 50, 1, 30, 2), [5.845, 11.78, 12, 43.206]),
  ('regression: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])],
 [('regression: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('regression: fast outbreak daily steps', (0.9, 0.2, 500, 5, 40, 1), [2.433, 249.994, 10, 497.014]),
  ('regression: subcritical seed decays', (0.08, 0.2, 1000, 10, 20, 2), [984.011, 10.0, 0, 15.167]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('regression: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])]]
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
N = 1
observations = []
def solve(beta, gamma, pop, i0, days, substeps):
    if pop <= 0 or i0 < 0 or i0 > pop or substeps < 1:
        return None
    dt = 1.0 / substeps
    s = float(pop - i0)
    i = float(i0)
    r = 0.0
    peak_i = i
    peak_day = 0
    for day in range(1, days + 1):
        for _ in range(substeps):
            new_inf = min(beta * s * i / pop * dt, s)
            new_rec = gamma * i0 * dt
            s -= new_inf
            i += new_inf - new_rec
            r += new_rec
        if i > peak_i:
            peak_i = i
            peak_day = day
    return [round(s, 3), round(peak_i, 3), peak_day, round(r, 3)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('regression: fast outbreak daily steps', (0.9, 0.2, 500, 5, 40, 1), [2.433, 249.994, 10, 497.014]),
  ('regression: subcritical seed decays', (0.08, 0.2, 1000, 10, 20, 2), [984.011, 10.0, 0, 15.167]),
  ('regression: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None)],
 [('regression: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('regression: overshoot-prone large beta two steps', (2.5, 0.3, 200, 80, 6, 2), [0.0, 156.8, 1, 166.339]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('control: invalid zero substeps', (0.5, 0.1, 100, 1, 10, 0), None),
  ('regression: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639])],
 [('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('control: invalid zero substeps', (0.5, 0.1, 100, 1, 10, 0), None),
  ('regression: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639]),
  ('regression: large city fine steps',
   (0.4, 0.15, 100000, 20, 50, 8),
   [13105.196, 25867.476, 37, 75829.968]),
  ('regression: small village', (0.6, 0.25, 50, 1, 30, 2), [5.845, 11.78, 12, 43.206]),
  ('regression: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])],
 [('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('regression: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639]),
  ('regression: large city fine steps',
   (0.4, 0.15, 100000, 20, 50, 8),
   [13105.196, 25867.476, 37, 75829.968]),
  ('regression: small village', (0.6, 0.25, 50, 1, 30, 2), [5.845, 11.78, 12, 43.206]),
  ('regression: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])],
 [('regression: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('regression: fast outbreak daily steps', (0.9, 0.2, 500, 5, 40, 1), [2.433, 249.994, 10, 497.014]),
  ('regression: subcritical seed decays', (0.08, 0.2, 1000, 10, 20, 2), [984.011, 10.0, 0, 15.167]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('regression: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])]]
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:
Recovery runs substeps times too fast whenever the day is subdivided.

Frequency-dependent SIR integrated with forward Euler at dt=1/substeps; new infections per substep are beta*S*I/pop*dt capped at S; peak prevalence and its day are sampled at day ends (day 0 is the seed); return [S, peak I, peak day, R] rounded to 3 decimals, or None for invalid input.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(beta, gamma, pop, i0, days, substeps):
    if pop <= 0 or i0 < 0 or i0 > pop or substeps < 1:
        return None
    dt = 1.0 / substeps
    s = float(pop - i0)
    i = float(i0)
    r = 0.0
    peak_i = i
    peak_day = 0
    for day in range(days):
        for _ in range(substeps):
            new_inf = min(beta * s * i / pop * dt, s)
            new_rec = gamma * i * dt
            s -= new_inf
            i += new_inf - new_rec
            r += new_rec
        if i > peak_i:
            peak_i = i
            peak_day = day
    return [round(s, 3), round(peak_i, 3), peak_day, round(r, 3)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('regression: fast outbreak daily steps', (0.9, 0.2, 500, 5, 40, 1), [2.433, 249.994, 10, 497.014]),
  ('regression: subcritical seed decays', (0.08, 0.2, 1000, 10, 20, 2), [984.011, 10.0, 0, 15.167]),
  ('regression: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None)],
 [('regression: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('regression: overshoot-prone large beta two steps', (2.5, 0.3, 200, 80, 6, 2), [0.0, 156.8, 1, 166.339]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('control: invalid zero substeps', (0.5, 0.1, 100, 1, 10, 0), None),
  ('regression: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639])],
 [('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('control: invalid zero substeps', (0.5, 0.1, 100, 1, 10, 0), None),
  ('regression: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639]),
  ('regression: large city fine steps',
   (0.4, 0.15, 100000, 20, 50, 8),
   [13105.196, 25867.476, 37, 75829.968]),
  ('regression: small village', (0.6, 0.25, 50, 1, 30, 2), [5.845, 11.78, 12, 43.206]),
  ('regression: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])],
 [('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('regression: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639]),
  ('regression: large city fine steps',
   (0.4, 0.15, 100000, 20, 50, 8),
   [13105.196, 25867.476, 37, 75829.968]),
  ('regression: small village', (0.6, 0.25, 50, 1, 30, 2), [5.845, 11.78, 12, 43.206]),
  ('regression: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])],
 [('regression: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('regression: fast outbreak daily steps', (0.9, 0.2, 500, 5, 40, 1), [2.433, 249.994, 10, 497.014]),
  ('regression: subcritical seed decays', (0.08, 0.2, 1000, 10, 20, 2), [984.011, 10.0, 0, 15.167]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('regression: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])]]
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
N = 1
observations = []
def solve(beta, gamma, pop, i0, days, substeps):
    if pop <= 0 or i0 < 0 or i0 > pop or substeps < 1:
        return None
    dt = 1.0 / substeps
    s = float(pop - i0)
    i = float(i0)
    r = 0.0
    peak_i = i
    peak_day = 0
    for day in range(1, days):
        for _ in range(substeps):
            new_inf = min(beta * s * i / pop * dt, s)
            new_rec = gamma * i * dt
            s -= new_inf
            i += new_inf - new_rec
            r += new_rec
        if i > peak_i:
            peak_i = i
            peak_day = day
    return [round(s, 3), round(peak_i, 3), peak_day, round(r, 3)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('regression: fast outbreak daily steps', (0.9, 0.2, 500, 5, 40, 1), [2.433, 249.994, 10, 497.014]),
  ('regression: subcritical seed decays', (0.08, 0.2, 1000, 10, 20, 2), [984.011, 10.0, 0, 15.167]),
  ('regression: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None)],
 [('regression: overshoot-prone large beta single step', (3.0, 0.5, 100, 50, 5, 1), [0.0, 75.0, 1, 95.312]),
  ('regression: overshoot-prone large beta two steps', (2.5, 0.3, 200, 80, 6, 2), [0.0, 156.8, 1, 166.339]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('control: invalid zero substeps', (0.5, 0.1, 100, 1, 10, 0), None),
  ('regression: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639])],
 [('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('control: invalid zero substeps', (0.5, 0.1, 100, 1, 10, 0), None),
  ('regression: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639]),
  ('regression: large city fine steps',
   (0.4, 0.15, 100000, 20, 50, 8),
   [13105.196, 25867.476, 37, 75829.968]),
  ('regression: small village', (0.6, 0.25, 50, 1, 30, 2), [5.845, 11.78, 12, 43.206]),
  ('regression: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])],
 [('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('regression: slow recovery long run', (0.25, 0.05, 2000, 2, 90, 3), [19.331, 965.817, 43, 1829.639]),
  ('regression: large city fine steps',
   (0.4, 0.15, 100000, 20, 50, 8),
   [13105.196, 25867.476, 37, 75829.968]),
  ('regression: small village', (0.6, 0.25, 50, 1, 30, 2), [5.845, 11.78, 12, 43.206]),
  ('regression: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])],
 [('regression: mild outbreak in 1000', (0.3, 0.1, 1000, 1, 60, 4), [85.915, 303.71, 39, 810.961]),
  ('regression: fast outbreak daily steps', (0.9, 0.2, 500, 5, 40, 1), [2.433, 249.994, 10, 497.014]),
  ('regression: subcritical seed decays', (0.08, 0.2, 1000, 10, 20, 2), [984.011, 10.0, 0, 15.167]),
  ('control: boundary zero days', (0.5, 0.1, 100, 3, 0, 2), [97.0, 3.0, 0, 0.0]),
  ('control: boundary no seed', (0.5, 0.1, 100, 0, 10, 2), [100.0, 0.0, 0, 0.0]),
  ('control: invalid seed above population', (0.5, 0.1, 100, 150, 10, 2), None),
  ('regression: whole population seeded', (0.5, 0.2, 40, 40, 5, 2), [0.0, 40.0, 0, 26.053])]]
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:
Peak days are reported one day early and the run stops one day short in its own numbering.

Frequency-dependent SIR integrated with forward Euler at dt=1/substeps; new infections per substep are beta*S*I/pop*dt capped at S; peak prevalence and its day are sampled at day ends (day 0 is the seed); return [S, peak I, peak day, R] rounded to 3 decimals, or None for invalid input.

split: open-access