broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    a = x['age']
    if a < 3:
        return {'error': 'NOT_APPLICABLE'}
    t = Fraction(str(x['temp'])) * 10
    s = (1 if t > 380 else 0) + bool(x['cough_absent']) + bool(x['exudate']) + bool(x['nodes'])
    s += 1 if a <= 14 else 0 if a <= 44 else -1
    act = 'NO_TEST' if s <= 1 else 'TEST' if s <= 3 else 'TEST_OR_EMPIRIC'
    return {'score': max(s, 0), 'action': act}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('adult control',
   {'age': 26, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': 0, 'action': 'NO_TEST'}),
  ('toddler below eligibility',
   {'age': 2, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'error': 'NOT_APPLICABLE'}),
  ('three-year-old eligible',
   {'age': 3, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': 1, 'action': 'NO_TEST'}),
  ('fourteen-year-old gets child point',
   {'age': 14, 'temp': '38.1', 'cough_absent': False, 'exudate': False, 'nodes': True},
   {'score': 3, 'action': 'TEST'}),
  ('fifteen-year-old no modifier',
   {'age': 15, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('44-year-old no modifier',
   {'age': 44, 'temp': '37.1', 'cough_absent': True, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('older adult negative score',
   {'age': 51, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': -1, 'action': 'NO_TEST'}),
  ('temperature 38.0 not fever',
   {'age': 30, 'temp': '38.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('temperature 38.x is fever',
   {'age': 30, 'temp': '38.1', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('all criteria child',
   {'age': 8, 'temp': '38.9', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 5, 'action': 'TEST_OR_EMPIRIC'}),
  ('elderly with all criteria',
   {'age': 80, 'temp': '38.5', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 3, 'action': 'TEST'})],
 [('adult control',
   {'age': 27, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': 0, 'action': 'NO_TEST'}),
  ('toddler below eligibility',
   {'age': 2, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'error': 'NOT_APPLICABLE'}),
  ('three-year-old eligible',
   {'age': 3, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('fourteen-year-old gets child point',
   {'age': 14, 'temp': '38.2', 'cough_absent': False, 'exudate': False, 'nodes': True},
   {'score': 3, 'action': 'TEST'}),
  ('fifteen-year-old no modifier',
   {'age': 15, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('44-year-old no modifier',
   {'age': 44, 'temp': '37.2', 'cough_absent': True, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('older adult negative score',
   {'age': 52, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': -1, 'action': 'NO_TEST'}),
  ('temperature 38.0 not fever',
   {'age': 30, 'temp': '38.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('temperature 38.x is fever',
   {'age': 30, 'temp': '38.2', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('all criteria child',
   {'age': 8, 'temp': '38.9', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 5, 'action': 'TEST_OR_EMPIRIC'}),
  ('elderly with all criteria',
   {'age': 80, 'temp': '38.5', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 3, 'action': 'TEST'})],
 [('adult control',
   {'age': 28, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': 0, 'action': 'NO_TEST'}),
  ('toddler below eligibility',
   {'age': 2, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'error': 'NOT_APPLICABLE'}),
  ('three-year-old eligible',
   {'age': 3, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': 1, 'action': 'NO_TEST'}),
  ('fourteen-year-old gets child point',
   {'age': 14, 'temp': '38.3', 'cough_absent': False, 'exudate': False, 'nodes': True},
   {'score': 3, 'action': 'TEST'}),
  ('fifteen-year-old no modifier',
   {'age': 15, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('44-year-old no modifier',
   {'age': 44, 'temp': '37.3', 'cough_absent': True, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('older adult negative score',
   {'age': 53, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': -1, 'action': 'NO_TEST'}),
  ('temperature 38.0 not fever',
   {'age': 30, 'temp': '38.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('temperature 38.x is fever',
   {'age': 30, 'temp': '38.3', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('all criteria child',
   {'age': 8, 'temp': '38.9', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 5, 'action': 'TEST_OR_EMPIRIC'}),
  ('elderly with all criteria',
   {'age': 80, 'temp': '38.5', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 3, 'action': 'TEST'})],
 [('adult control',
   {'age': 29, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': 0, 'action': 'NO_TEST'}),
  ('toddler below eligibility',
   {'age': 2, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'error': 'NOT_APPLICABLE'}),
  ('three-year-old eligible',
   {'age': 3, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('fourteen-year-old gets child point',
   {'age': 14, 'temp': '38.4', 'cough_absent': False, 'exudate': False, 'nodes': True},
   {'score': 3, 'action': 'TEST'}),
  ('fifteen-year-old no modifier',
   {'age': 15, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('44-year-old no modifier',
   {'age': 44, 'temp': '37.4', 'cough_absent': True, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('older adult negative score',
   {'age': 54, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': -1, 'action': 'NO_TEST'}),
  ('temperature 38.0 not fever',
   {'age': 30, 'temp': '38.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('temperature 38.x is fever',
   {'age': 30, 'temp': '38.4', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('all criteria child',
   {'age': 8, 'temp': '38.9', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 5, 'action': 'TEST_OR_EMPIRIC'}),
  ('elderly with all criteria',
   {'age': 80, 'temp': '38.5', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 3, 'action': 'TEST'})],
 [('adult control',
   {'age': 30, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': 0, 'action': 'NO_TEST'}),
  ('toddler below eligibility',
   {'age': 2, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'error': 'NOT_APPLICABLE'}),
  ('three-year-old eligible',
   {'age': 3, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': 1, 'action': 'NO_TEST'}),
  ('fourteen-year-old gets child point',
   {'age': 14, 'temp': '38.5', 'cough_absent': False, 'exudate': False, 'nodes': True},
   {'score': 3, 'action': 'TEST'}),
  ('fifteen-year-old no modifier',
   {'age': 15, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('44-year-old no modifier',
   {'age': 44, 'temp': '37.5', 'cough_absent': True, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('older adult negative score',
   {'age': 55, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': -1, 'action': 'NO_TEST'}),
  ('temperature 38.0 not fever',
   {'age': 30, 'temp': '38.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('temperature 38.x is fever',
   {'age': 30, 'temp': '38.5', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('all criteria child',
   {'age': 8, 'temp': '38.9', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 5, 'action': 'TEST_OR_EMPIRIC'}),
  ('elderly with all criteria',
   {'age': 80, 'temp': '38.5', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 3, 'action': 'TEST'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    a = x['age']
    if a < 3:
        return {'error': 'NOT_APPLICABLE'}
    t = Fraction(str(x['temp'])) * 10
    s = (1 if t > 380 else 0) + bool(x['cough_absent']) + bool(x['exudate']) + bool(x['nodes'])
    s += 1 if a <= 14 else 0 if a <= 44 else -1
    act = 'NO_TEST' if s <= 1 else 'TEST' if s <= 3 else 'TEST_OR_EMPIRIC'
    return {'score': abs(s), 'action': act}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('adult control',
   {'age': 26, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': 0, 'action': 'NO_TEST'}),
  ('toddler below eligibility',
   {'age': 2, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'error': 'NOT_APPLICABLE'}),
  ('three-year-old eligible',
   {'age': 3, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': 1, 'action': 'NO_TEST'}),
  ('fourteen-year-old gets child point',
   {'age': 14, 'temp': '38.1', 'cough_absent': False, 'exudate': False, 'nodes': True},
   {'score': 3, 'action': 'TEST'}),
  ('fifteen-year-old no modifier',
   {'age': 15, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('44-year-old no modifier',
   {'age': 44, 'temp': '37.1', 'cough_absent': True, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('older adult negative score',
   {'age': 51, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': -1, 'action': 'NO_TEST'}),
  ('temperature 38.0 not fever',
   {'age': 30, 'temp': '38.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('temperature 38.x is fever',
   {'age': 30, 'temp': '38.1', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('all criteria child',
   {'age': 8, 'temp': '38.9', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 5, 'action': 'TEST_OR_EMPIRIC'}),
  ('elderly with all criteria',
   {'age': 80, 'temp': '38.5', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 3, 'action': 'TEST'})],
 [('adult control',
   {'age': 27, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': 0, 'action': 'NO_TEST'}),
  ('toddler below eligibility',
   {'age': 2, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'error': 'NOT_APPLICABLE'}),
  ('three-year-old eligible',
   {'age': 3, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('fourteen-year-old gets child point',
   {'age': 14, 'temp': '38.2', 'cough_absent': False, 'exudate': False, 'nodes': True},
   {'score': 3, 'action': 'TEST'}),
  ('fifteen-year-old no modifier',
   {'age': 15, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('44-year-old no modifier',
   {'age': 44, 'temp': '37.2', 'cough_absent': True, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('older adult negative score',
   {'age': 52, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': -1, 'action': 'NO_TEST'}),
  ('temperature 38.0 not fever',
   {'age': 30, 'temp': '38.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('temperature 38.x is fever',
   {'age': 30, 'temp': '38.2', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('all criteria child',
   {'age': 8, 'temp': '38.9', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 5, 'action': 'TEST_OR_EMPIRIC'}),
  ('elderly with all criteria',
   {'age': 80, 'temp': '38.5', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 3, 'action': 'TEST'})],
 [('adult control',
   {'age': 28, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': 0, 'action': 'NO_TEST'}),
  ('toddler below eligibility',
   {'age': 2, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'error': 'NOT_APPLICABLE'}),
  ('three-year-old eligible',
   {'age': 3, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': 1, 'action': 'NO_TEST'}),
  ('fourteen-year-old gets child point',
   {'age': 14, 'temp': '38.3', 'cough_absent': False, 'exudate': False, 'nodes': True},
   {'score': 3, 'action': 'TEST'}),
  ('fifteen-year-old no modifier',
   {'age': 15, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('44-year-old no modifier',
   {'age': 44, 'temp': '37.3', 'cough_absent': True, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('older adult negative score',
   {'age': 53, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': -1, 'action': 'NO_TEST'}),
  ('temperature 38.0 not fever',
   {'age': 30, 'temp': '38.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('temperature 38.x is fever',
   {'age': 30, 'temp': '38.3', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('all criteria child',
   {'age': 8, 'temp': '38.9', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 5, 'action': 'TEST_OR_EMPIRIC'}),
  ('elderly with all criteria',
   {'age': 80, 'temp': '38.5', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 3, 'action': 'TEST'})],
 [('adult control',
   {'age': 29, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': 0, 'action': 'NO_TEST'}),
  ('toddler below eligibility',
   {'age': 2, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'error': 'NOT_APPLICABLE'}),
  ('three-year-old eligible',
   {'age': 3, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('fourteen-year-old gets child point',
   {'age': 14, 'temp': '38.4', 'cough_absent': False, 'exudate': False, 'nodes': True},
   {'score': 3, 'action': 'TEST'}),
  ('fifteen-year-old no modifier',
   {'age': 15, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('44-year-old no modifier',
   {'age': 44, 'temp': '37.4', 'cough_absent': True, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('older adult negative score',
   {'age': 54, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': -1, 'action': 'NO_TEST'}),
  ('temperature 38.0 not fever',
   {'age': 30, 'temp': '38.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('temperature 38.x is fever',
   {'age': 30, 'temp': '38.4', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('all criteria child',
   {'age': 8, 'temp': '38.9', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 5, 'action': 'TEST_OR_EMPIRIC'}),
  ('elderly with all criteria',
   {'age': 80, 'temp': '38.5', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 3, 'action': 'TEST'})],
 [('adult control',
   {'age': 30, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': 0, 'action': 'NO_TEST'}),
  ('toddler below eligibility',
   {'age': 2, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'error': 'NOT_APPLICABLE'}),
  ('three-year-old eligible',
   {'age': 3, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': 1, 'action': 'NO_TEST'}),
  ('fourteen-year-old gets child point',
   {'age': 14, 'temp': '38.5', 'cough_absent': False, 'exudate': False, 'nodes': True},
   {'score': 3, 'action': 'TEST'}),
  ('fifteen-year-old no modifier',
   {'age': 15, 'temp': '37.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('44-year-old no modifier',
   {'age': 44, 'temp': '37.5', 'cough_absent': True, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('older adult negative score',
   {'age': 55, 'temp': '37.0', 'cough_absent': False, 'exudate': False, 'nodes': False},
   {'score': -1, 'action': 'NO_TEST'}),
  ('temperature 38.0 not fever',
   {'age': 30, 'temp': '38.0', 'cough_absent': False, 'exudate': True, 'nodes': True},
   {'score': 2, 'action': 'TEST'}),
  ('temperature 38.x is fever',
   {'age': 30, 'temp': '38.5', 'cough_absent': False, 'exudate': True, 'nodes': False},
   {'score': 2, 'action': 'TEST'}),
  ('all criteria child',
   {'age': 8, 'temp': '38.9', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 5, 'action': 'TEST_OR_EMPIRIC'}),
  ('elderly with all criteria',
   {'age': 80, 'temp': '38.5', 'cough_absent': True, 'exudate': True, 'nodes': True},
   {'score': 3, 'action': 'TEST'})]]
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 negative age-adjusted score is reported as 0.

Input {age, temp (1 dp), cough_absent, exudate, nodes}. Ages below 3 return {error NOT_APPLICABLE}. Points: temp > 38.0, absent cough, tonsillar exudate, tender nodes (1 each); age 3-14 +1, 15-44 0, >= 45 -1. The score is reported as computed (can be -1). Action: <= 1 NO_TEST, 2-3 TEST, >= 4 TEST_OR_EMPIRIC. Return {score, action}.

split: open-access


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': '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']:
        return {'tag': 'GREEN', 'reason': 'walking'}
    if not x['breathing']:
        return {'tag': 'YELLOW' 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:
Casualties who start breathing after airway repositioning are tagged expectant.

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 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)

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 or x['rr'] < 10:
        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 breathing exactly 30 times a minute is tagged RED.

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