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

N = 1
observations = []
def solve(x):
    hr = x['hr']
    pts = 0 if hr == 0 else 1 if hr < 100 else 2
    pts += ['absent', 'weak', 'good'].index(x['resp'])
    pts += ['limp', 'some', 'active'].index(x['tone'])
    pts += ['none', 'grimace', 'cry'].index(x['reflex'])
    pts += ['blue', 'acro', 'pink'].index(x['color'])
    cat = 'REASSURING' if pts >= 7 else 'MODERATE' if pts >= 4 else 'LOW'
    rep = 5 if x['minute'] == 1 else x['minute'] + 5 if pts < 7 and x['minute'] <= 20 else None
    return {'score': pts, 'category': cat, 'repeat_at': rep}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('vigorous newborn',
   {'hr': 140, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'pink', 'minute': 1},
   {'score': 10, 'category': 'REASSURING', 'repeat_at': 5}),
  ('absent heart rate',
   {'hr': 0, 'resp': 'absent', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 5},
   {'score': 0, 'category': 'LOW', 'repeat_at': 10}),
  ('slow heart rate 50',
   {'hr': 51, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 5}),
  ('total exactly 7',
   {'hr': 120, 'resp': 'good', 'tone': 'some', 'reflex': 'grimace', 'color': 'acro', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 4',
   {'hr': 90, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 10},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 15}),
  ('total 7 with slow heart rate',
   {'hr': 65, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'blue', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 3',
   {'hr': 41, 'resp': 'weak', 'tone': 'some', 'reflex': 'none', 'color': 'blue', 'minute': 1},
   {'score': 3, 'category': 'LOW', 'repeat_at': 5}),
  ('low score at 15 minutes',
   {'hr': 80, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 15},
   {'score': 2, 'category': 'LOW', 'repeat_at': 20}),
  ('low score at 20 minutes stops',
   {'hr': 81, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 20},
   {'score': 2, 'category': 'LOW', 'repeat_at': None}),
  ('moderate at one minute',
   {'hr': 110, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 5, 'category': 'MODERATE', 'repeat_at': 5})],
 [('vigorous newborn',
   {'hr': 140, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'acro', 'minute': 1},
   {'score': 9, 'category': 'REASSURING', 'repeat_at': 5}),
  ('absent heart rate',
   {'hr': 0, 'resp': 'absent', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 10},
   {'score': 0, 'category': 'LOW', 'repeat_at': 15}),
  ('slow heart rate 50',
   {'hr': 52, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 5}),
  ('total exactly 7',
   {'hr': 120, 'resp': 'good', 'tone': 'some', 'reflex': 'grimace', 'color': 'acro', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 4',
   {'hr': 90, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 5},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 10}),
  ('total 7 with slow heart rate',
   {'hr': 70, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'blue', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 3',
   {'hr': 42, 'resp': 'weak', 'tone': 'some', 'reflex': 'none', 'color': 'blue', 'minute': 1},
   {'score': 3, 'category': 'LOW', 'repeat_at': 5}),
  ('low score at 15 minutes',
   {'hr': 80, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 15},
   {'score': 2, 'category': 'LOW', 'repeat_at': 20}),
  ('low score at 20 minutes stops',
   {'hr': 82, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 20},
   {'score': 2, 'category': 'LOW', 'repeat_at': None}),
  ('moderate at one minute',
   {'hr': 110, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 5, 'category': 'MODERATE', 'repeat_at': 5})],
 [('vigorous newborn',
   {'hr': 140, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'pink', 'minute': 1},
   {'score': 10, 'category': 'REASSURING', 'repeat_at': 5}),
  ('absent heart rate',
   {'hr': 0, 'resp': 'absent', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 15},
   {'score': 0, 'category': 'LOW', 'repeat_at': 20}),
  ('slow heart rate 50',
   {'hr': 53, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 5}),
  ('total exactly 7',
   {'hr': 120, 'resp': 'good', 'tone': 'some', 'reflex': 'grimace', 'color': 'acro', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 4',
   {'hr': 90, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 10},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 15}),
  ('total 7 with slow heart rate',
   {'hr': 75, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'blue', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 3',
   {'hr': 43, 'resp': 'weak', 'tone': 'some', 'reflex': 'none', 'color': 'blue', 'minute': 1},
   {'score': 3, 'category': 'LOW', 'repeat_at': 5}),
  ('low score at 15 minutes',
   {'hr': 80, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 15},
   {'score': 2, 'category': 'LOW', 'repeat_at': 20}),
  ('low score at 20 minutes stops',
   {'hr': 83, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 20},
   {'score': 2, 'category': 'LOW', 'repeat_at': None}),
  ('moderate at one minute',
   {'hr': 110, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 5, 'category': 'MODERATE', 'repeat_at': 5})],
 [('vigorous newborn',
   {'hr': 140, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'acro', 'minute': 1},
   {'score': 9, 'category': 'REASSURING', 'repeat_at': 5}),
  ('absent heart rate',
   {'hr': 0, 'resp': 'absent', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 20},
   {'score': 0, 'category': 'LOW', 'repeat_at': None}),
  ('slow heart rate 50',
   {'hr': 54, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 5}),
  ('total exactly 7',
   {'hr': 120, 'resp': 'good', 'tone': 'some', 'reflex': 'grimace', 'color': 'acro', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 4',
   {'hr': 90, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 5},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 10}),
  ('total 7 with slow heart rate',
   {'hr': 80, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'blue', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 3',
   {'hr': 44, 'resp': 'weak', 'tone': 'some', 'reflex': 'none', 'color': 'blue', 'minute': 1},
   {'score': 3, 'category': 'LOW', 'repeat_at': 5}),
  ('low score at 15 minutes',
   {'hr': 80, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 15},
   {'score': 2, 'category': 'LOW', 'repeat_at': 20}),
  ('low score at 20 minutes stops',
   {'hr': 84, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 20},
   {'score': 2, 'category': 'LOW', 'repeat_at': None}),
  ('moderate at one minute',
   {'hr': 110, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 5, 'category': 'MODERATE', 'repeat_at': 5})],
 [('vigorous newborn',
   {'hr': 140, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'pink', 'minute': 1},
   {'score': 10, 'category': 'REASSURING', 'repeat_at': 5}),
  ('absent heart rate',
   {'hr': 0, 'resp': 'absent', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 25},
   {'score': 0, 'category': 'LOW', 'repeat_at': None}),
  ('slow heart rate 50',
   {'hr': 55, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 5}),
  ('total exactly 7',
   {'hr': 120, 'resp': 'good', 'tone': 'some', 'reflex': 'grimace', 'color': 'acro', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 4',
   {'hr': 90, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 10},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 15}),
  ('total 7 with slow heart rate',
   {'hr': 85, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'blue', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 3',
   {'hr': 45, 'resp': 'weak', 'tone': 'some', 'reflex': 'none', 'color': 'blue', 'minute': 1},
   {'score': 3, 'category': 'LOW', 'repeat_at': 5}),
  ('low score at 15 minutes',
   {'hr': 80, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 15},
   {'score': 2, 'category': 'LOW', 'repeat_at': 20}),
  ('low score at 20 minutes stops',
   {'hr': 85, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 20},
   {'score': 2, 'category': 'LOW', 'repeat_at': None}),
  ('moderate at one minute',
   {'hr': 110, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 5, 'category': 'MODERATE', 'repeat_at': 5})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    hr = x['hr']
    pts = 0 if hr == 0 else 1 if hr < 100 else 2
    pts += ['absent', 'weak', 'good'].index(x['resp'])
    pts += ['limp', 'some', 'active'].index(x['tone'])
    pts += ['none', 'grimace', 'cry'].index(x['reflex'])
    pts += ['blue', 'acro', 'pink'].index(x['color'])
    cat = 'REASSURING' if pts >= 7 else 'MODERATE' if pts >= 4 else 'LOW'
    rep = 5 if x['minute'] == 1 else x['minute'] + 5 if pts < 7 and x['minute'] < 15 else None
    return {'score': pts, 'category': cat, 'repeat_at': rep}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('vigorous newborn',
   {'hr': 140, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'pink', 'minute': 1},
   {'score': 10, 'category': 'REASSURING', 'repeat_at': 5}),
  ('absent heart rate',
   {'hr': 0, 'resp': 'absent', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 5},
   {'score': 0, 'category': 'LOW', 'repeat_at': 10}),
  ('slow heart rate 50',
   {'hr': 51, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 5}),
  ('total exactly 7',
   {'hr': 120, 'resp': 'good', 'tone': 'some', 'reflex': 'grimace', 'color': 'acro', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 4',
   {'hr': 90, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 10},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 15}),
  ('total 7 with slow heart rate',
   {'hr': 65, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'blue', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 3',
   {'hr': 41, 'resp': 'weak', 'tone': 'some', 'reflex': 'none', 'color': 'blue', 'minute': 1},
   {'score': 3, 'category': 'LOW', 'repeat_at': 5}),
  ('low score at 15 minutes',
   {'hr': 80, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 15},
   {'score': 2, 'category': 'LOW', 'repeat_at': 20}),
  ('low score at 20 minutes stops',
   {'hr': 81, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 20},
   {'score': 2, 'category': 'LOW', 'repeat_at': None}),
  ('moderate at one minute',
   {'hr': 110, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 5, 'category': 'MODERATE', 'repeat_at': 5})],
 [('vigorous newborn',
   {'hr': 140, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'acro', 'minute': 1},
   {'score': 9, 'category': 'REASSURING', 'repeat_at': 5}),
  ('absent heart rate',
   {'hr': 0, 'resp': 'absent', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 10},
   {'score': 0, 'category': 'LOW', 'repeat_at': 15}),
  ('slow heart rate 50',
   {'hr': 52, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 5}),
  ('total exactly 7',
   {'hr': 120, 'resp': 'good', 'tone': 'some', 'reflex': 'grimace', 'color': 'acro', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 4',
   {'hr': 90, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 5},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 10}),
  ('total 7 with slow heart rate',
   {'hr': 70, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'blue', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 3',
   {'hr': 42, 'resp': 'weak', 'tone': 'some', 'reflex': 'none', 'color': 'blue', 'minute': 1},
   {'score': 3, 'category': 'LOW', 'repeat_at': 5}),
  ('low score at 15 minutes',
   {'hr': 80, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 15},
   {'score': 2, 'category': 'LOW', 'repeat_at': 20}),
  ('low score at 20 minutes stops',
   {'hr': 82, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 20},
   {'score': 2, 'category': 'LOW', 'repeat_at': None}),
  ('moderate at one minute',
   {'hr': 110, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 5, 'category': 'MODERATE', 'repeat_at': 5})],
 [('vigorous newborn',
   {'hr': 140, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'pink', 'minute': 1},
   {'score': 10, 'category': 'REASSURING', 'repeat_at': 5}),
  ('absent heart rate',
   {'hr': 0, 'resp': 'absent', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 15},
   {'score': 0, 'category': 'LOW', 'repeat_at': 20}),
  ('slow heart rate 50',
   {'hr': 53, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 5}),
  ('total exactly 7',
   {'hr': 120, 'resp': 'good', 'tone': 'some', 'reflex': 'grimace', 'color': 'acro', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 4',
   {'hr': 90, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 10},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 15}),
  ('total 7 with slow heart rate',
   {'hr': 75, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'blue', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 3',
   {'hr': 43, 'resp': 'weak', 'tone': 'some', 'reflex': 'none', 'color': 'blue', 'minute': 1},
   {'score': 3, 'category': 'LOW', 'repeat_at': 5}),
  ('low score at 15 minutes',
   {'hr': 80, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 15},
   {'score': 2, 'category': 'LOW', 'repeat_at': 20}),
  ('low score at 20 minutes stops',
   {'hr': 83, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 20},
   {'score': 2, 'category': 'LOW', 'repeat_at': None}),
  ('moderate at one minute',
   {'hr': 110, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 5, 'category': 'MODERATE', 'repeat_at': 5})],
 [('vigorous newborn',
   {'hr': 140, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'acro', 'minute': 1},
   {'score': 9, 'category': 'REASSURING', 'repeat_at': 5}),
  ('absent heart rate',
   {'hr': 0, 'resp': 'absent', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 20},
   {'score': 0, 'category': 'LOW', 'repeat_at': None}),
  ('slow heart rate 50',
   {'hr': 54, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 5}),
  ('total exactly 7',
   {'hr': 120, 'resp': 'good', 'tone': 'some', 'reflex': 'grimace', 'color': 'acro', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 4',
   {'hr': 90, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 5},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 10}),
  ('total 7 with slow heart rate',
   {'hr': 80, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'blue', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 3',
   {'hr': 44, 'resp': 'weak', 'tone': 'some', 'reflex': 'none', 'color': 'blue', 'minute': 1},
   {'score': 3, 'category': 'LOW', 'repeat_at': 5}),
  ('low score at 15 minutes',
   {'hr': 80, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 15},
   {'score': 2, 'category': 'LOW', 'repeat_at': 20}),
  ('low score at 20 minutes stops',
   {'hr': 84, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 20},
   {'score': 2, 'category': 'LOW', 'repeat_at': None}),
  ('moderate at one minute',
   {'hr': 110, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 5, 'category': 'MODERATE', 'repeat_at': 5})],
 [('vigorous newborn',
   {'hr': 140, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'pink', 'minute': 1},
   {'score': 10, 'category': 'REASSURING', 'repeat_at': 5}),
  ('absent heart rate',
   {'hr': 0, 'resp': 'absent', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 25},
   {'score': 0, 'category': 'LOW', 'repeat_at': None}),
  ('slow heart rate 50',
   {'hr': 55, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 5}),
  ('total exactly 7',
   {'hr': 120, 'resp': 'good', 'tone': 'some', 'reflex': 'grimace', 'color': 'acro', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 4',
   {'hr': 90, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 10},
   {'score': 4, 'category': 'MODERATE', 'repeat_at': 15}),
  ('total 7 with slow heart rate',
   {'hr': 85, 'resp': 'good', 'tone': 'active', 'reflex': 'cry', 'color': 'blue', 'minute': 5},
   {'score': 7, 'category': 'REASSURING', 'repeat_at': None}),
  ('total exactly 3',
   {'hr': 45, 'resp': 'weak', 'tone': 'some', 'reflex': 'none', 'color': 'blue', 'minute': 1},
   {'score': 3, 'category': 'LOW', 'repeat_at': 5}),
  ('low score at 15 minutes',
   {'hr': 80, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 15},
   {'score': 2, 'category': 'LOW', 'repeat_at': 20}),
  ('low score at 20 minutes stops',
   {'hr': 85, 'resp': 'weak', 'tone': 'limp', 'reflex': 'none', 'color': 'blue', 'minute': 20},
   {'score': 2, 'category': 'LOW', 'repeat_at': None}),
  ('moderate at one minute',
   {'hr': 110, 'resp': 'weak', 'tone': 'some', 'reflex': 'grimace', 'color': 'blue', 'minute': 1},
   {'score': 5, 'category': 'MODERATE', 'repeat_at': 5})]]
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 low score at 20 minutes schedules another assessment at 25 minutes.

Input {hr, resp (absent|weak|good), tone (limp|some|active), reflex (none|grimace|cry), color (blue|acro|pink), minute}. Heart rate: 0 scores 0, 1-99 scores 1, >= 100 scores 2; the other signs score 0/1/2 in the listed order. Category: 7-10 REASSURING, 4-6 MODERATE, 0-3 LOW. repeat_at is 5 after any 1-minute score; after later scores it is minute + 5 when the total is below 7 and minute < 20, else null. Return {score, category, repeat_at}.

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):
    h = 0
    h += 6 if x['dvt_signs'] else 0
    h += 6 if x['pe_most_likely'] else 0
    h += 3 if x['hr'] > 100 else 0
    h += 3 if x['immobile_days'] >= 3 else 0
    h += 3 if x['surgery_weeks_ago'] is not None and x['surgery_weeks_ago'] <= 4 else 0
    h += 3 if x['prior_vte'] else 0
    h += 2 if x['hemoptysis'] else 0
    h += 2 if x['malignancy'] else 0
    likely = h > 8
    recent_surg = x['surgery_weeks_ago'] is not None and x['surgery_weeks_ago'] <= 4
    if likely:
        nxt = 'IMAGING'
    elif x['age'] < 50 and x['hr'] < 100 and x['spo2'] >= 95 and not (x['hemoptysis'] or x['estrogen'] or x['prior_vte'] or recent_surg):
        nxt = 'RULED_OUT'
    else:
        nxt = 'D_DIMER'
    return {'score': h / 2, 'category': 'LIKELY' if likely else 'UNLIKELY', 'next': nxt}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 26,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 4,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 31,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 61,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 102,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 31,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 6,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 29,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 41,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})],
 [('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 27,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 5,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': True,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 5.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 32,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 62,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 103,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 32,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 7,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 30,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 42,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})],
 [('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 28,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 6,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 33,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 63,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 104,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 33,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 8,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 31,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 43,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})],
 [('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 29,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 7,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': True,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 5.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 34,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 64,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 105,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 34,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 9,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 32,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 44,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})],
 [('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 30,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 8,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 65,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 106,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 10,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 33,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 45,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})]]
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):
    h = 0
    h += 6 if x['dvt_signs'] else 0
    h += 6 if x['pe_most_likely'] else 0
    h += 3 if x['hr'] > 100 else 0
    h += 3 if x['immobile_days'] >= 3 or x['surgery_weeks_ago'] else 0
    h += 3 if x['prior_vte'] else 0
    h += 2 if x['hemoptysis'] else 0
    h += 2 if x['malignancy'] else 0
    likely = h > 8
    recent_surg = x['surgery_weeks_ago'] is not None and x['surgery_weeks_ago'] <= 4
    if likely:
        nxt = 'IMAGING'
    elif x['age'] < 50 and x['hr'] < 100 and x['spo2'] >= 95 and not (x['hemoptysis'] or x['estrogen'] or x['prior_vte'] or recent_surg):
        nxt = 'RULED_OUT'
    else:
        nxt = 'D_DIMER'
    return {'score': h / 2, 'category': 'LIKELY' if likely else 'UNLIKELY', 'next': nxt}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 26,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 4,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 31,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 61,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 102,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 31,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 6,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 29,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 41,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})],
 [('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 27,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 5,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': True,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 5.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 32,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 62,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 103,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 32,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 7,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 30,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 42,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})],
 [('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 28,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 6,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 33,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 63,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 104,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 33,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 8,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 31,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 43,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})],
 [('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 29,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 7,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': True,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 5.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 34,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 64,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 105,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 34,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 9,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 32,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 44,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})],
 [('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 30,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 8,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 65,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 106,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 10,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 33,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 45,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})]]
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 bed-bound post-operative patient scores 3 points for the single immobilisation item.

Input {dvt_signs, pe_most_likely, hr, immobile_days, surgery_weeks_ago (or null), prior_vte, hemoptysis, malignancy, age, spo2, estrogen}. Toy points: DVT signs 3, alternative less likely 3, hr > 100 1.5, immobilisation >= 3 days OR surgery within 4 weeks 1.5 (counted once), prior VTE 1.5, haemoptysis 1, malignancy 1. Score > 4 is LIKELY (next IMAGING). UNLIKELY patients are RULED_OUT when age < 50, hr < 100, spo2 >= 95 and none of haemoptysis, estrogen, prior VTE or surgery within 4 weeks; otherwise next D_DIMER. Return {score, category, next}.

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):
    h = 0
    h += 6 if x['dvt_signs'] else 0
    h += 6 if x['pe_most_likely'] else 0
    h += 3 if x['hr'] > 100 else 0
    h += 3 if x['immobile_days'] >= 3 or (x['surgery_weeks_ago'] is not None and x['surgery_weeks_ago'] <= 4) else 0
    h += 3 if x['prior_vte'] else 0
    h += 2 if x['hemoptysis'] else 0
    h += 2 if x['malignancy'] else 0
    likely = h >= 8
    recent_surg = x['surgery_weeks_ago'] is not None and x['surgery_weeks_ago'] <= 4
    if likely:
        nxt = 'IMAGING'
    elif x['age'] < 50 and x['hr'] < 100 and x['spo2'] >= 95 and not (x['hemoptysis'] or x['estrogen'] or x['prior_vte'] or recent_surg):
        nxt = 'RULED_OUT'
    else:
        nxt = 'D_DIMER'
    return {'score': h / 2, 'category': 'LIKELY' if likely else 'UNLIKELY', 'next': nxt}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 26,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 4,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 31,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 61,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 102,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 31,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 6,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 29,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 41,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})],
 [('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 27,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 5,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': True,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 5.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 32,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 62,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 103,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 32,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 7,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 30,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 42,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})],
 [('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 28,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 6,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 33,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 63,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 104,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 33,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 8,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 31,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 43,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})],
 [('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 29,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 7,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': True,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 5.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 34,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 64,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 105,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 34,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 9,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 32,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 44,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})],
 [('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 30,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 8,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 65,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 106,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 10,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 33,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 45,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})]]
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):
    h = 0
    h += 6 if x['dvt_signs'] else 0
    h += 6 if x['pe_most_likely'] else 0
    h += 3 if x['hr'] > 100 else 0
    h += 3 if x['immobile_days'] >= 3 or (x['surgery_weeks_ago'] is not None and x['surgery_weeks_ago'] <= 4) else 0
    h += 3 if x['prior_vte'] else 0
    h += 2 if x['hemoptysis'] else 0
    h += 2 if x['malignancy'] else 0
    likely = round(h / 2) > 4
    recent_surg = x['surgery_weeks_ago'] is not None and x['surgery_weeks_ago'] <= 4
    if likely:
        nxt = 'IMAGING'
    elif x['age'] < 50 and x['hr'] < 100 and x['spo2'] >= 95 and not (x['hemoptysis'] or x['estrogen'] or x['prior_vte'] or recent_surg):
        nxt = 'RULED_OUT'
    else:
        nxt = 'D_DIMER'
    return {'score': h / 2, 'category': 'LIKELY' if likely else 'UNLIKELY', 'next': nxt}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 26,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 4,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 31,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 61,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 102,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 31,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 6,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 29,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 41,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})],
 [('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 27,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 5,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': True,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 5.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 32,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 62,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 103,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 32,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 7,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 30,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 42,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})],
 [('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 28,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 6,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 33,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 63,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 104,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 33,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 8,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 31,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 43,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})],
 [('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 29,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 7,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': True,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 5.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 34,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 64,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 105,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 34,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 9,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 32,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 44,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})],
 [('low risk young patient',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 30,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('immobilised after surgery counted once',
   {'dvt_signs': True,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 8,
    'surgery_weeks_ago': 2,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('surgery on the day counts',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 0,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 40,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.5 is likely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.5, 'category': 'LIKELY', 'next': 'IMAGING'}),
  ('score 4.0 unlikely',
   {'dvt_signs': False,
    'pe_most_likely': True,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': True,
    'age': 65,
    'spo2': 98,
    'estrogen': False},
   {'score': 4.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('half point score reported',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 106,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 55,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('surgery exactly 4 weeks ago excludes rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 4,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('remote surgery allows rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': 10,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 35,
    'spo2': 98,
    'estrogen': False},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'RULED_OUT'}),
  ('estrogen use blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': False,
    'hemoptysis': False,
    'malignancy': False,
    'age': 33,
    'spo2': 98,
    'estrogen': True},
   {'score': 0.0, 'category': 'UNLIKELY', 'next': 'D_DIMER'}),
  ('prior VTE blocks rule-out',
   {'dvt_signs': False,
    'pe_most_likely': False,
    'hr': 80,
    'immobile_days': 0,
    'surgery_weeks_ago': None,
    'prior_vte': True,
    'hemoptysis': False,
    'malignancy': False,
    'age': 45,
    'spo2': 98,
    'estrogen': False},
   {'score': 1.5, 'category': 'UNLIKELY', 'next': 'D_DIMER'})]]
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 score of exactly 4.0 is classified as likely.

Input {dvt_signs, pe_most_likely, hr, immobile_days, surgery_weeks_ago (or null), prior_vte, hemoptysis, malignancy, age, spo2, estrogen}. Toy points: DVT signs 3, alternative less likely 3, hr > 100 1.5, immobilisation >= 3 days OR surgery within 4 weeks 1.5 (counted once), prior VTE 1.5, haemoptysis 1, malignancy 1. Score > 4 is LIKELY (next IMAGING). UNLIKELY patients are RULED_OUT when age < 50, hr < 100, spo2 >= 95 and none of haemoptysis, estrogen, prior VTE or surgery within 4 weeks; otherwise next D_DIMER. Return {score, category, next}.

split: open-access