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

N = 1
observations = []
def solve(x):
    if x['walking']:
        return {'tag': 'GREEN', 'reason': 'walking'}
    if not x['breathing']:
        return {'tag': 'RED' if x['breathing_after_airway'] else 'BLACK', 'reason': 'airway'}
    if x['rr'] > 30:
        return {'tag': 'RED', 'reason': 'respiration'}
    if not x['radial_pulse'] and x['cap_refill_s'] > 2:
        return {'tag': 'RED', 'reason': 'perfusion'}
    if not x['follows_commands']:
        return {'tag': 'RED', 'reason': 'mental'}
    return {'tag': 'YELLOW', 'reason': 'delayed'}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 33,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 21,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 9,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 19,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 26,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})],
 [('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 34,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 8,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 27,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})],
 [('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 35,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 23,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 9,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 21,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 28,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})],
 [('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 36,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 24,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 4,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 8,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 29,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})],
 [('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 37,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 25,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 5,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 9,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 23,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})]]
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):
    if x['walking']:
        return {'tag': 'GREEN', 'reason': 'walking'}
    if not x['breathing']:
        return {'tag': 'RED' if x['breathing_after_airway'] else 'BLACK', 'reason': 'airway'}
    if x['rr'] > 30:
        return {'tag': 'RED', 'reason': 'respiration'}
    if not x['radial_pulse'] or x['cap_refill_s'] >= 2:
        return {'tag': 'RED', 'reason': 'perfusion'}
    if not x['follows_commands']:
        return {'tag': 'RED', 'reason': 'mental'}
    return {'tag': 'YELLOW', 'reason': 'delayed'}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 33,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 21,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 9,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 19,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 26,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})],
 [('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 34,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 8,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 27,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})],
 [('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 35,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 23,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 9,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 21,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 28,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})],
 [('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 36,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 24,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 4,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 8,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 29,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})],
 [('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 37,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 25,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 5,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 9,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 23,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})]]
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 casualty without a radial pulse but with brisk refill is tagged YELLOW.

Input {walking, breathing, breathing_after_airway, rr, radial_pulse, cap_refill_s, follows_commands}. Toy order: walking -> GREEN; not breathing -> RED if breathing after airway repositioning else BLACK; rr > 30 -> RED; no radial pulse or refill > 2 s -> RED; not following commands -> RED; else YELLOW. Return {tag, reason}.

split: open-access


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

N = 1
observations = []
def solve(x):
    if not x['breathing']:
        return {'tag': 'RED' if x['breathing_after_airway'] else 'BLACK', 'reason': 'airway'}
    if x['rr'] > 30:
        return {'tag': 'RED', 'reason': 'respiration'}
    if not x['radial_pulse'] or x['cap_refill_s'] > 2:
        return {'tag': 'RED', 'reason': 'perfusion'}
    if not x['follows_commands']:
        return {'tag': 'RED', 'reason': 'mental'}
    return {'tag': 'YELLOW', 'reason': 'delayed'}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 33,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 21,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 9,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 19,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 26,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})],
 [('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 34,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 8,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 27,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})],
 [('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 35,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 23,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 9,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 21,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 28,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})],
 [('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 36,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 24,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 4,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 8,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 29,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})],
 [('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 37,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 25,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 5,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 9,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 23,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    if x['walking'] and x['follows_commands']:
        return {'tag': 'GREEN', 'reason': 'walking'}
    if not x['breathing']:
        return {'tag': 'RED' if x['breathing_after_airway'] else 'BLACK', 'reason': 'airway'}
    if x['rr'] > 30:
        return {'tag': 'RED', 'reason': 'respiration'}
    if not x['radial_pulse'] or x['cap_refill_s'] > 2:
        return {'tag': 'RED', 'reason': 'perfusion'}
    if not x['follows_commands']:
        return {'tag': 'RED', 'reason': 'mental'}
    return {'tag': 'YELLOW', 'reason': 'delayed'}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 33,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 21,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 9,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 19,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 26,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})],
 [('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 34,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 8,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 27,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})],
 [('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 35,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 23,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 9,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 21,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 28,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})],
 [('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 36,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 24,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 4,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 8,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 29,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})],
 [('walking wounded tachypnoeic',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 37,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('walking but confused',
   {'walking': True,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 25,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'GREEN', 'reason': 'walking'}),
  ('apnoeic breathes after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': True,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'airway'}),
  ('apnoeic after repositioning',
   {'walking': False,
    'breathing': False,
    'breathing_after_airway': False,
    'rr': 0,
    'radial_pulse': True,
    'cap_refill_s': 5,
    'follows_commands': True},
   {'tag': 'BLACK', 'reason': 'airway'}),
  ('respiratory rate exactly 30',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('slow breathing but perfusing',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 9,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('no radial pulse with quick refill',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 20,
    'radial_pulse': False,
    'cap_refill_s': 1,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('refill exactly 2 seconds',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 23,
    'radial_pulse': True,
    'cap_refill_s': 2,
    'follows_commands': True},
   {'tag': 'YELLOW', 'reason': 'delayed'}),
  ('refill 3 seconds with pulse',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 22,
    'radial_pulse': True,
    'cap_refill_s': 3,
    'follows_commands': True},
   {'tag': 'RED', 'reason': 'perfusion'}),
  ('cannot follow commands',
   {'walking': False,
    'breathing': True,
    'breathing_after_airway': False,
    'rr': 30,
    'radial_pulse': True,
    'cap_refill_s': 1,
    'follows_commands': False},
   {'tag': 'RED', 'reason': 'mental'})]]
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:
Walking wounded who breathe fast are tagged RED instead of GREEN.

Input {walking, breathing, breathing_after_airway, rr, radial_pulse, cap_refill_s, follows_commands}. Toy order: walking -> GREEN; not breathing -> RED if breathing after airway repositioning else BLACK; rr > 30 -> RED; no radial pulse or refill > 2 s -> RED; not following commands -> RED; else YELLOW. Return {tag, reason}.

split: open-access


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

N = 1
observations = []
def solve(x):
    d = x['last_fall_days']
    fell = d is not None
    s = 25 if fell else 0
    s += 15 if x['secondary_dx'] else 0
    aid = x['aid']
    s += 30 if aid == 'furniture' else 15 if aid in ('crutches', 'cane', 'walker') else 0
    s += 20 if x['iv'] else 0
    g = x['gait']
    s += 20 if g == 'impaired' else 10 if g == 'weak' else 0
    s += 15 if x['mental'] in ('forgets', 'overestimates') else 0
    risk = 'HIGH' if s >= 45 else 'MODERATE' if s >= 25 else 'LOW'
    return {'score': s, 'risk': risk}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('no risk factors',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 0, 'risk': 'LOW'}),
  ('fall exactly 90 days ago',
   {'last_fall_days': 90,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('fall a year ago',
   {'last_fall_days': 301,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 20, 'risk': 'LOW'}),
  ('furniture walking',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'furniture',
    'iv': False,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('walker user',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'walker',
    'iv': False,
    'gait': 'normal',
    'mental': 'forgets'},
   {'score': 45, 'risk': 'HIGH'}),
  ('weak gait',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'cane',
    'iv': True,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'}),
  ('impaired gait',
   {'last_fall_days': 10,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'impaired',
    'mental': 'oriented'},
   {'score': 60, 'risk': 'HIGH'}),
  ('score exactly 40',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'cane',
    'iv': False,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('overestimates own ability',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'overestimates'},
   {'score': 30, 'risk': 'MODERATE'}),
  ('score exactly 25',
   {'last_fall_days': 31,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 25, 'risk': 'MODERATE'}),
  ('score exactly 45',
   {'last_fall_days': 6,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'})],
 [('no risk factors',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'bedrest',
    'mental': 'oriented'},
   {'score': 0, 'risk': 'LOW'}),
  ('fall exactly 90 days ago',
   {'last_fall_days': 90,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 25, 'risk': 'MODERATE'}),
  ('fall a year ago',
   {'last_fall_days': 302,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 20, 'risk': 'LOW'}),
  ('furniture walking',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'furniture',
    'iv': True,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 60, 'risk': 'HIGH'}),
  ('walker user',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'walker',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 30, 'risk': 'MODERATE'}),
  ('weak gait',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'cane',
    'iv': True,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'}),
  ('impaired gait',
   {'last_fall_days': 20,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'impaired',
    'mental': 'oriented'},
   {'score': 60, 'risk': 'HIGH'}),
  ('score exactly 40',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'walker',
    'iv': False,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('overestimates own ability',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'overestimates'},
   {'score': 50, 'risk': 'HIGH'}),
  ('score exactly 25',
   {'last_fall_days': 32,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 25, 'risk': 'MODERATE'}),
  ('score exactly 45',
   {'last_fall_days': 7,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'})],
 [('no risk factors',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'immobile',
    'mental': 'oriented'},
   {'score': 0, 'risk': 'LOW'}),
  ('fall exactly 90 days ago',
   {'last_fall_days': 90,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('fall a year ago',
   {'last_fall_days': 303,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 20, 'risk': 'LOW'}),
  ('furniture walking',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'furniture',
    'iv': False,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('walker user',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'walker',
    'iv': False,
    'gait': 'normal',
    'mental': 'forgets'},
   {'score': 45, 'risk': 'HIGH'}),
  ('weak gait',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'cane',
    'iv': True,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'}),
  ('impaired gait',
   {'last_fall_days': 30,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'impaired',
    'mental': 'oriented'},
   {'score': 60, 'risk': 'HIGH'}),
  ('score exactly 40',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'crutches',
    'iv': False,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('overestimates own ability',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'overestimates'},
   {'score': 30, 'risk': 'MODERATE'}),
  ('score exactly 25',
   {'last_fall_days': 33,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 25, 'risk': 'MODERATE'}),
  ('score exactly 45',
   {'last_fall_days': 8,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'})],
 [('no risk factors',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 0, 'risk': 'LOW'}),
  ('fall exactly 90 days ago',
   {'last_fall_days': 90,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 25, 'risk': 'MODERATE'}),
  ('fall a year ago',
   {'last_fall_days': 304,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 20, 'risk': 'LOW'}),
  ('furniture walking',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'furniture',
    'iv': True,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 60, 'risk': 'HIGH'}),
  ('walker user',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'walker',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 30, 'risk': 'MODERATE'}),
  ('weak gait',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'cane',
    'iv': True,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'}),
  ('impaired gait',
   {'last_fall_days': 40,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'impaired',
    'mental': 'oriented'},
   {'score': 60, 'risk': 'HIGH'}),
  ('score exactly 40',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'cane',
    'iv': False,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('overestimates own ability',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'overestimates'},
   {'score': 50, 'risk': 'HIGH'}),
  ('score exactly 25',
   {'last_fall_days': 34,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 25, 'risk': 'MODERATE'}),
  ('score exactly 45',
   {'last_fall_days': 9,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'})],
 [('no risk factors',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'bedrest',
    'mental': 'oriented'},
   {'score': 0, 'risk': 'LOW'}),
  ('fall exactly 90 days ago',
   {'last_fall_days': 90,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('fall a year ago',
   {'last_fall_days': 305,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 20, 'risk': 'LOW'}),
  ('furniture walking',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'furniture',
    'iv': False,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('walker user',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'walker',
    'iv': False,
    'gait': 'normal',
    'mental': 'forgets'},
   {'score': 45, 'risk': 'HIGH'}),
  ('weak gait',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'cane',
    'iv': True,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'}),
  ('impaired gait',
   {'last_fall_days': 50,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'impaired',
    'mental': 'oriented'},
   {'score': 60, 'risk': 'HIGH'}),
  ('score exactly 40',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'walker',
    'iv': False,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('overestimates own ability',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'overestimates'},
   {'score': 30, 'risk': 'MODERATE'}),
  ('score exactly 25',
   {'last_fall_days': 35,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 25, 'risk': 'MODERATE'}),
  ('score exactly 45',
   {'last_fall_days': 10,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'})]]
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):
    d = x['last_fall_days']
    fell = d is not None and d < 90
    s = 25 if fell else 0
    s += 15 if x['secondary_dx'] else 0
    aid = x['aid']
    s += 30 if aid == 'furniture' else 15 if aid in ('crutches', 'cane', 'walker') else 0
    s += 20 if x['iv'] else 0
    g = x['gait']
    s += 20 if g == 'impaired' else 10 if g == 'weak' else 0
    s += 15 if x['mental'] in ('forgets', 'overestimates') else 0
    risk = 'HIGH' if s >= 45 else 'MODERATE' if s >= 25 else 'LOW'
    return {'score': s, 'risk': risk}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('no risk factors',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 0, 'risk': 'LOW'}),
  ('fall exactly 90 days ago',
   {'last_fall_days': 90,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('fall a year ago',
   {'last_fall_days': 301,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 20, 'risk': 'LOW'}),
  ('furniture walking',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'furniture',
    'iv': False,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('walker user',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'walker',
    'iv': False,
    'gait': 'normal',
    'mental': 'forgets'},
   {'score': 45, 'risk': 'HIGH'}),
  ('weak gait',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'cane',
    'iv': True,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'}),
  ('impaired gait',
   {'last_fall_days': 10,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'impaired',
    'mental': 'oriented'},
   {'score': 60, 'risk': 'HIGH'}),
  ('score exactly 40',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'cane',
    'iv': False,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('overestimates own ability',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'overestimates'},
   {'score': 30, 'risk': 'MODERATE'}),
  ('score exactly 25',
   {'last_fall_days': 31,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 25, 'risk': 'MODERATE'}),
  ('score exactly 45',
   {'last_fall_days': 6,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'})],
 [('no risk factors',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'bedrest',
    'mental': 'oriented'},
   {'score': 0, 'risk': 'LOW'}),
  ('fall exactly 90 days ago',
   {'last_fall_days': 90,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 25, 'risk': 'MODERATE'}),
  ('fall a year ago',
   {'last_fall_days': 302,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 20, 'risk': 'LOW'}),
  ('furniture walking',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'furniture',
    'iv': True,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 60, 'risk': 'HIGH'}),
  ('walker user',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'walker',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 30, 'risk': 'MODERATE'}),
  ('weak gait',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'cane',
    'iv': True,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'}),
  ('impaired gait',
   {'last_fall_days': 20,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'impaired',
    'mental': 'oriented'},
   {'score': 60, 'risk': 'HIGH'}),
  ('score exactly 40',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'walker',
    'iv': False,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('overestimates own ability',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'overestimates'},
   {'score': 50, 'risk': 'HIGH'}),
  ('score exactly 25',
   {'last_fall_days': 32,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 25, 'risk': 'MODERATE'}),
  ('score exactly 45',
   {'last_fall_days': 7,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'})],
 [('no risk factors',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'immobile',
    'mental': 'oriented'},
   {'score': 0, 'risk': 'LOW'}),
  ('fall exactly 90 days ago',
   {'last_fall_days': 90,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('fall a year ago',
   {'last_fall_days': 303,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 20, 'risk': 'LOW'}),
  ('furniture walking',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'furniture',
    'iv': False,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('walker user',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'walker',
    'iv': False,
    'gait': 'normal',
    'mental': 'forgets'},
   {'score': 45, 'risk': 'HIGH'}),
  ('weak gait',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'cane',
    'iv': True,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'}),
  ('impaired gait',
   {'last_fall_days': 30,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'impaired',
    'mental': 'oriented'},
   {'score': 60, 'risk': 'HIGH'}),
  ('score exactly 40',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'crutches',
    'iv': False,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('overestimates own ability',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'overestimates'},
   {'score': 30, 'risk': 'MODERATE'}),
  ('score exactly 25',
   {'last_fall_days': 33,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 25, 'risk': 'MODERATE'}),
  ('score exactly 45',
   {'last_fall_days': 8,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'})],
 [('no risk factors',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 0, 'risk': 'LOW'}),
  ('fall exactly 90 days ago',
   {'last_fall_days': 90,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 25, 'risk': 'MODERATE'}),
  ('fall a year ago',
   {'last_fall_days': 304,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 20, 'risk': 'LOW'}),
  ('furniture walking',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'furniture',
    'iv': True,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 60, 'risk': 'HIGH'}),
  ('walker user',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'walker',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 30, 'risk': 'MODERATE'}),
  ('weak gait',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'cane',
    'iv': True,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'}),
  ('impaired gait',
   {'last_fall_days': 40,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'impaired',
    'mental': 'oriented'},
   {'score': 60, 'risk': 'HIGH'}),
  ('score exactly 40',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'cane',
    'iv': False,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('overestimates own ability',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'overestimates'},
   {'score': 50, 'risk': 'HIGH'}),
  ('score exactly 25',
   {'last_fall_days': 34,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 25, 'risk': 'MODERATE'}),
  ('score exactly 45',
   {'last_fall_days': 9,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'})],
 [('no risk factors',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'bedrest',
    'mental': 'oriented'},
   {'score': 0, 'risk': 'LOW'}),
  ('fall exactly 90 days ago',
   {'last_fall_days': 90,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('fall a year ago',
   {'last_fall_days': 305,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 20, 'risk': 'LOW'}),
  ('furniture walking',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'furniture',
    'iv': False,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('walker user',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'walker',
    'iv': False,
    'gait': 'normal',
    'mental': 'forgets'},
   {'score': 45, 'risk': 'HIGH'}),
  ('weak gait',
   {'last_fall_days': None,
    'secondary_dx': False,
    'aid': 'cane',
    'iv': True,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'}),
  ('impaired gait',
   {'last_fall_days': 50,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'impaired',
    'mental': 'oriented'},
   {'score': 60, 'risk': 'HIGH'}),
  ('score exactly 40',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'walker',
    'iv': False,
    'gait': 'weak',
    'mental': 'oriented'},
   {'score': 40, 'risk': 'MODERATE'}),
  ('overestimates own ability',
   {'last_fall_days': None,
    'secondary_dx': True,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'overestimates'},
   {'score': 30, 'risk': 'MODERATE'}),
  ('score exactly 25',
   {'last_fall_days': 35,
    'secondary_dx': False,
    'aid': 'none',
    'iv': False,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 25, 'risk': 'MODERATE'}),
  ('score exactly 45',
   {'last_fall_days': 10,
    'secondary_dx': False,
    'aid': 'none',
    'iv': True,
    'gait': 'normal',
    'mental': 'oriented'},
   {'score': 45, 'risk': 'HIGH'})]]
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 fall from years ago still adds 25 points.

Input {last_fall_days (or null), secondary_dx, aid, iv, gait, mental}. Toy points: a fall within the last 90 days (inclusive) 25; secondary diagnosis 15; aid none/bedrest/nurse 0, crutches/cane/walker 15, furniture 30; IV access 20; gait normal/bedrest/immobile 0, weak 10, impaired 20; mental status "forgets" or "overestimates" (overestimates own ability) 15, "oriented" 0. Risk: 0-24 LOW, 25-44 MODERATE, >= 45 HIGH. Return {score, risk}.

split: open-access