broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    wt = min(Fraction(str(x['weight_kg'])), 120)
    a = x['aptt']
    r = Fraction(str(x['rate']))
    bolus, hold = 0, 0
    if a < 35:
        bolus, r = 80, r + 4
    elif a <= 45:
        bolus, r = 40, r + 2
    elif a <= 70:
        pass
    elif a <= 90:
        r = r - 2
    else:
        hold, r = 0, r - 3
    r = max(r, Fraction(0))
    bolus_units = math.floor(bolus * wt / 100 + Fraction(1, 2)) * 100
    return {'bolus_units': bolus_units, 'hold_min': hold, 'rate_u_kg_h': float(r), 'rate_u_h': math.floor(r * wt + Fraction(1, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('very low aptt bolus',
   {'weight_kg': 71, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5700, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1562}),
  ('aptt exactly 35',
   {'weight_kg': 61, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2400, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1220}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 17},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 19.0, 'rate_u_h': 1520}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 56, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 81, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 96, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 126, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '81.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3300, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1381})],
 [('very low aptt bolus',
   {'weight_kg': 72, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5800, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1584}),
  ('aptt exactly 35',
   {'weight_kg': 62, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2500, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1240}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 18},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1600}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 57, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 82, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 97, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 127, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '86.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3500, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1466})],
 [('very low aptt bolus',
   {'weight_kg': 73, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5800, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1606}),
  ('aptt exactly 35',
   {'weight_kg': 63, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2500, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1260}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 19},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 21.0, 'rate_u_h': 1680}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 58, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 83, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 98, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 128, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '91.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3700, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1551})],
 [('very low aptt bolus',
   {'weight_kg': 74, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5900, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1628}),
  ('aptt exactly 35',
   {'weight_kg': 64, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2600, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1280}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 20},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1760}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 59, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 84, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 99, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 129, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '76.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3100, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1296})],
 [('very low aptt bolus',
   {'weight_kg': 75, 'aptt': 30, 'rate': 18},
   {'bolus_units': 6000, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1650}),
  ('aptt exactly 35',
   {'weight_kg': 65, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2600, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1300}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 21},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 23.0, 'rate_u_h': 1840}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 60, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 85, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 100, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 130, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '71.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 2900, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1211})]]
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):
    wt = min(Fraction(str(x['weight_kg'])), 120)
    a = x['aptt']
    r = Fraction(str(x['rate']))
    bolus, hold = 0, 0
    if a < 35:
        bolus, r = 80, r + 4
    elif a <= 45:
        bolus, r = 40, r + 2
    elif a <= 70:
        pass
    elif a <= 90:
        r = r - 2
    else:
        hold, r = 60, r - 2
    r = max(r, Fraction(0))
    bolus_units = math.floor(bolus * wt / 100 + Fraction(1, 2)) * 100
    return {'bolus_units': bolus_units, 'hold_min': hold, 'rate_u_kg_h': float(r), 'rate_u_h': math.floor(r * wt + Fraction(1, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('very low aptt bolus',
   {'weight_kg': 71, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5700, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1562}),
  ('aptt exactly 35',
   {'weight_kg': 61, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2400, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1220}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 17},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 19.0, 'rate_u_h': 1520}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 56, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 81, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 96, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 126, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '81.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3300, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1381})],
 [('very low aptt bolus',
   {'weight_kg': 72, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5800, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1584}),
  ('aptt exactly 35',
   {'weight_kg': 62, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2500, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1240}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 18},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1600}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 57, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 82, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 97, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 127, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '86.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3500, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1466})],
 [('very low aptt bolus',
   {'weight_kg': 73, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5800, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1606}),
  ('aptt exactly 35',
   {'weight_kg': 63, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2500, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1260}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 19},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 21.0, 'rate_u_h': 1680}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 58, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 83, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 98, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 128, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '91.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3700, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1551})],
 [('very low aptt bolus',
   {'weight_kg': 74, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5900, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1628}),
  ('aptt exactly 35',
   {'weight_kg': 64, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2600, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1280}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 20},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1760}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 59, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 84, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 99, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 129, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '76.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3100, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1296})],
 [('very low aptt bolus',
   {'weight_kg': 75, 'aptt': 30, 'rate': 18},
   {'bolus_units': 6000, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1650}),
  ('aptt exactly 35',
   {'weight_kg': 65, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2600, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1300}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 21},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 23.0, 'rate_u_h': 1840}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 60, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 85, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 100, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 130, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '71.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 2900, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1211})]]
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:
Very high aPTT results reduce the rate but never pause the infusion.

Input {weight_kg, aptt (integer seconds), rate (units/kg/h)}. Toy nomogram with dosing weight capped at 120 kg: aptt < 35 bolus 80 u/kg and rate +4; 35-45 bolus 40 u/kg and rate +2; 46-70 no change; 71-90 rate -2; > 90 hold 60 minutes and rate -3. Rate is never below 0. Bolus units = bolus u/kg * weight rounded half-up to the nearest 100 units. Return {bolus_units, hold_min, rate_u_kg_h, rate_u_h (half-up integer of rate*weight)}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    wt = min(Fraction(str(x['weight_kg'])), 120)
    a = x['aptt']
    r = Fraction(str(x['rate']))
    bolus, hold = 0, 0
    if a < 35:
        bolus, r = 80, r + 4
    elif a <= 45:
        bolus, r = 40, r + 2
    elif a <= 70:
        pass
    elif a <= 90:
        r = r - 2
    else:
        hold, r = 60, r - 3
    r = max(r, Fraction(0)) if hold else r
    bolus_units = math.floor(bolus * wt / 100 + Fraction(1, 2)) * 100
    return {'bolus_units': bolus_units, 'hold_min': hold, 'rate_u_kg_h': float(r), 'rate_u_h': math.floor(r * wt + Fraction(1, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('very low aptt bolus',
   {'weight_kg': 71, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5700, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1562}),
  ('aptt exactly 35',
   {'weight_kg': 61, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2400, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1220}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 17},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 19.0, 'rate_u_h': 1520}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 56, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 81, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 96, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 126, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '81.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3300, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1381})],
 [('very low aptt bolus',
   {'weight_kg': 72, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5800, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1584}),
  ('aptt exactly 35',
   {'weight_kg': 62, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2500, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1240}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 18},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1600}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 57, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 82, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 97, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 127, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '86.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3500, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1466})],
 [('very low aptt bolus',
   {'weight_kg': 73, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5800, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1606}),
  ('aptt exactly 35',
   {'weight_kg': 63, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2500, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1260}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 19},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 21.0, 'rate_u_h': 1680}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 58, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 83, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 98, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 128, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '91.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3700, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1551})],
 [('very low aptt bolus',
   {'weight_kg': 74, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5900, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1628}),
  ('aptt exactly 35',
   {'weight_kg': 64, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2600, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1280}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 20},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1760}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 59, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 84, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 99, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 129, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '76.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3100, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1296})],
 [('very low aptt bolus',
   {'weight_kg': 75, 'aptt': 30, 'rate': 18},
   {'bolus_units': 6000, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1650}),
  ('aptt exactly 35',
   {'weight_kg': 65, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2600, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1300}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 21},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 23.0, 'rate_u_h': 1840}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 60, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 85, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 100, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 130, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '71.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 2900, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1211})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    wt = min(Fraction(str(x['weight_kg'])), 120)
    a = x['aptt']
    r = Fraction(str(x['rate']))
    bolus, hold = 0, 0
    if a < 35:
        bolus, r = 80, r + 4
    elif a <= 45:
        bolus, r = 40, r + 2
    elif a <= 70:
        pass
    elif a <= 90:
        r = r - 2
    else:
        hold, r = 60, r - 3
    r = max(r, Fraction(1))
    bolus_units = math.floor(bolus * wt / 100 + Fraction(1, 2)) * 100
    return {'bolus_units': bolus_units, 'hold_min': hold, 'rate_u_kg_h': float(r), 'rate_u_h': math.floor(r * wt + Fraction(1, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('very low aptt bolus',
   {'weight_kg': 71, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5700, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1562}),
  ('aptt exactly 35',
   {'weight_kg': 61, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2400, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1220}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 17},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 19.0, 'rate_u_h': 1520}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 56, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 81, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 96, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 126, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '81.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3300, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1381})],
 [('very low aptt bolus',
   {'weight_kg': 72, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5800, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1584}),
  ('aptt exactly 35',
   {'weight_kg': 62, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2500, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1240}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 18},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1600}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 57, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 82, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 97, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 127, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '86.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3500, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1466})],
 [('very low aptt bolus',
   {'weight_kg': 73, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5800, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1606}),
  ('aptt exactly 35',
   {'weight_kg': 63, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2500, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1260}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 19},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 21.0, 'rate_u_h': 1680}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 58, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 83, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 98, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 128, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '91.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3700, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1551})],
 [('very low aptt bolus',
   {'weight_kg': 74, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5900, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1628}),
  ('aptt exactly 35',
   {'weight_kg': 64, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2600, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1280}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 20},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1760}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 59, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 84, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 99, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 129, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '76.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3100, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1296})],
 [('very low aptt bolus',
   {'weight_kg': 75, 'aptt': 30, 'rate': 18},
   {'bolus_units': 6000, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1650}),
  ('aptt exactly 35',
   {'weight_kg': 65, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2600, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1300}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 21},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 23.0, 'rate_u_h': 1840}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 60, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 85, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 100, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 130, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '71.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 2900, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1211})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A low rate reduced for aPTT 81 s is returned as a negative infusion rate.

Input {weight_kg, aptt (integer seconds), rate (units/kg/h)}. Toy nomogram with dosing weight capped at 120 kg: aptt < 35 bolus 80 u/kg and rate +4; 35-45 bolus 40 u/kg and rate +2; 46-70 no change; 71-90 rate -2; > 90 hold 60 minutes and rate -3. Rate is never below 0. Bolus units = bolus u/kg * weight rounded half-up to the nearest 100 units. Return {bolus_units, hold_min, rate_u_kg_h, rate_u_h (half-up integer of rate*weight)}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    wt = min(Fraction(str(x['weight_kg'])), 120)
    a = x['aptt']
    r = Fraction(str(x['rate']))
    bolus, hold = 0, 0
    if a < 35:
        bolus, r = 80, r + 4
    elif a <= 45:
        bolus, r = 40, r + 2
    elif a <= 70:
        pass
    elif a <= 90:
        r = r - 2
    else:
        hold, r = 60, r - 3
    r = max(r, Fraction(0))
    bolus_units = bolus * wt // 100 * 100
    return {'bolus_units': bolus_units, 'hold_min': hold, 'rate_u_kg_h': float(r), 'rate_u_h': math.floor(r * wt + Fraction(1, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('very low aptt bolus',
   {'weight_kg': 71, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5700, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1562}),
  ('aptt exactly 35',
   {'weight_kg': 61, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2400, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1220}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 17},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 19.0, 'rate_u_h': 1520}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 56, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 81, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 96, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 126, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '81.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3300, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1381})],
 [('very low aptt bolus',
   {'weight_kg': 72, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5800, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1584}),
  ('aptt exactly 35',
   {'weight_kg': 62, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2500, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1240}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 18},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1600}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 57, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 82, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 97, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 127, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '86.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3500, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1466})],
 [('very low aptt bolus',
   {'weight_kg': 73, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5800, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1606}),
  ('aptt exactly 35',
   {'weight_kg': 63, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2500, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1260}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 19},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 21.0, 'rate_u_h': 1680}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 58, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 83, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 98, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 128, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '91.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3700, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1551})],
 [('very low aptt bolus',
   {'weight_kg': 74, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5900, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1628}),
  ('aptt exactly 35',
   {'weight_kg': 64, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2600, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1280}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 20},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1760}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 59, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 84, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 99, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 129, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '76.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3100, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1296})],
 [('very low aptt bolus',
   {'weight_kg': 75, 'aptt': 30, 'rate': 18},
   {'bolus_units': 6000, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1650}),
  ('aptt exactly 35',
   {'weight_kg': 65, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2600, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1300}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 21},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 23.0, 'rate_u_h': 1840}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 60, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 85, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 100, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 130, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '71.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 2900, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1211})]]
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):
    wt = min(Fraction(str(x['weight_kg'])), 120)
    a = x['aptt']
    r = Fraction(str(x['rate']))
    bolus, hold = 0, 0
    if a < 35:
        bolus, r = 80, r + 4
    elif a <= 45:
        bolus, r = 40, r + 2
    elif a <= 70:
        pass
    elif a <= 90:
        r = r - 2
    else:
        hold, r = 60, r - 3
    r = max(r, Fraction(0))
    bolus_units = int(round(bolus * wt, -2))
    return {'bolus_units': bolus_units, 'hold_min': hold, 'rate_u_kg_h': float(r), 'rate_u_h': math.floor(r * wt + Fraction(1, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('very low aptt bolus',
   {'weight_kg': 71, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5700, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1562}),
  ('aptt exactly 35',
   {'weight_kg': 61, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2400, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1220}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 17},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 19.0, 'rate_u_h': 1520}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 56, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 81, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 96, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 126, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '81.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3300, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1381})],
 [('very low aptt bolus',
   {'weight_kg': 72, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5800, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1584}),
  ('aptt exactly 35',
   {'weight_kg': 62, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2500, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1240}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 18},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1600}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 57, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 82, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 97, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 127, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '86.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3500, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1466})],
 [('very low aptt bolus',
   {'weight_kg': 73, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5800, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1606}),
  ('aptt exactly 35',
   {'weight_kg': 63, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2500, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1260}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 19},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 21.0, 'rate_u_h': 1680}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 58, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 83, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 98, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 128, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '91.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3700, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1551})],
 [('very low aptt bolus',
   {'weight_kg': 74, 'aptt': 30, 'rate': 18},
   {'bolus_units': 5900, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1628}),
  ('aptt exactly 35',
   {'weight_kg': 64, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2600, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1280}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 20},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1760}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 59, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 84, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 99, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 129, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '76.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 3100, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1296})],
 [('very low aptt bolus',
   {'weight_kg': 75, 'aptt': 30, 'rate': 18},
   {'bolus_units': 6000, 'hold_min': 0, 'rate_u_kg_h': 22.0, 'rate_u_h': 1650}),
  ('aptt exactly 35',
   {'weight_kg': 65, 'aptt': 35, 'rate': 18},
   {'bolus_units': 2600, 'hold_min': 0, 'rate_u_kg_h': 20.0, 'rate_u_h': 1300}),
  ('aptt exactly 45',
   {'weight_kg': 80, 'aptt': 45, 'rate': 21},
   {'bolus_units': 3200, 'hold_min': 0, 'rate_u_kg_h': 23.0, 'rate_u_h': 1840}),
  ('therapeutic control',
   {'weight_kg': 75, 'aptt': 60, 'rate': 18},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 18.0, 'rate_u_h': 1350}),
  ('reduction clamps at zero',
   {'weight_kg': 70, 'aptt': 85, 'rate': 1},
   {'bolus_units': 0, 'hold_min': 0, 'rate_u_kg_h': 0.0, 'rate_u_h': 0}),
  ('supratherapeutic hold',
   {'weight_kg': 90, 'aptt': 100, 'rate': 12},
   {'bolus_units': 0, 'hold_min': 60, 'rate_u_kg_h': 9.0, 'rate_u_h': 810}),
  ('weight above cap',
   {'weight_kg': 130, 'aptt': 40, 'rate': 15},
   {'bolus_units': 4800, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 2040}),
  ('half-hundred bolus rounds up',
   {'weight_kg': '71.25', 'aptt': 40, 'rate': 15},
   {'bolus_units': 2900, 'hold_min': 0, 'rate_u_kg_h': 17.0, 'rate_u_h': 1211})]]
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 3250 unit bolus is drawn up as 3200 units.

Input {weight_kg, aptt (integer seconds), rate (units/kg/h)}. Toy nomogram with dosing weight capped at 120 kg: aptt < 35 bolus 80 u/kg and rate +4; 35-45 bolus 40 u/kg and rate +2; 46-70 no change; 71-90 rate -2; > 90 hold 60 minutes and rate -3. Rate is never below 0. Bolus units = bolus u/kg * weight rounded half-up to the nearest 100 units. Return {bolus_units, hold_min, rate_u_kg_h, rate_u_h (half-up integer of rate*weight)}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    h = math.isqrt(100 * x['height_cm'] * x['weight_kg']) // 6
    h = min(h, 200)
    dose = Fraction(x['mg_m2'] * h, 100)
    best = None
    for b in sorted(x['bands']):
        d = abs(b - dose)
        if d * 20 <= dose and (best is None or d < best[0]):
            best = (d, b)
    if best is None:
        return {'bsa': h / 100, 'dose_mg': math.floor(dose + Fraction(1, 2)), 'banded': False}
    return {'bsa': h / 100, 'dose_mg': best[1], 'banded': True}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('typical adult banded',
   {'height_cm': 170, 'weight_kg': 71, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.83, 'dose_mg': 180, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 55, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.59, 'dose_mg': 16, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 91, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [189, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 151]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 50, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 91, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 56, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.58, 'dose_mg': 95, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 72, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.84, 'dose_mg': 180, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 60, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.66, 'dose_mg': 17, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 92, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [188, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 152]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 250, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 453, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 57, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.59, 'dose_mg': 95, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 73, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.86, 'dose_mg': 190, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 63, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.7, 'dose_mg': 17, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 93, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [187, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 153]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 450, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 815, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 58, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.61, 'dose_mg': 97, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 74, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.87, 'dose_mg': 190, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 72, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.82, 'dose_mg': 18, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 94, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [186, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 154]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 650, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 1177, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 59, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.62, 'dose_mg': 97, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 75, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.88, 'dose_mg': 190, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 76, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.87, 'dose_mg': 19, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 95, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [185, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 155]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 850, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 1539, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 60, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.63, 'dose_mg': 98, 'banded': False})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    h = (math.isqrt(x['height_cm'] * x['weight_kg']) * 10 + 3) // 6
    h = min(h, 200)
    dose = Fraction(x['mg_m2'] * h, 100)
    best = None
    for b in sorted(x['bands']):
        d = abs(b - dose)
        if d * 20 <= dose and (best is None or d < best[0]):
            best = (d, b)
    if best is None:
        return {'bsa': h / 100, 'dose_mg': math.floor(dose + Fraction(1, 2)), 'banded': False}
    return {'bsa': h / 100, 'dose_mg': best[1], 'banded': True}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('typical adult banded',
   {'height_cm': 170, 'weight_kg': 71, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.83, 'dose_mg': 180, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 55, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.59, 'dose_mg': 16, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 91, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [189, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 151]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 50, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 91, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 56, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.58, 'dose_mg': 95, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 72, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.84, 'dose_mg': 180, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 60, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.66, 'dose_mg': 17, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 92, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [188, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 152]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 250, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 453, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 57, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.59, 'dose_mg': 95, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 73, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.86, 'dose_mg': 190, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 63, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.7, 'dose_mg': 17, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 93, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [187, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 153]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 450, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 815, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 58, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.61, 'dose_mg': 97, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 74, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.87, 'dose_mg': 190, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 72, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.82, 'dose_mg': 18, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 94, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [186, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 154]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 650, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 1177, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 59, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.62, 'dose_mg': 97, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 75, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.88, 'dose_mg': 190, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 76, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.87, 'dose_mg': 19, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 95, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [185, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 155]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 850, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 1539, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 60, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.63, 'dose_mg': 98, 'banded': False})]]
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:
BSA values are systematically 0.01 m2 low (1.82 reported as 1.81).

Input {height_cm, weight_kg (integers), mg_m2, bands}. BSA (Mosteller) = sqrt(height*weight/3600) rounded half-up to 0.01 m2, computed exactly as (isqrt(100*h*w)+3)//6 hundredths, and capped at 2.00 m2. dose = mg_m2 * BSA. Dose banding: the band with the smallest absolute difference that is within 5% of the dose (difference*20 <= dose) is used, ties going to the lower band; otherwise the dose is rounded half-up to a whole mg. Return {bsa, dose_mg, banded}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    h = (math.isqrt(100 * x['height_cm'] * x['weight_kg']) + 3) // 6
    h = min(h, 2)
    dose = Fraction(x['mg_m2'] * h, 100)
    best = None
    for b in sorted(x['bands']):
        d = abs(b - dose)
        if d * 20 <= dose and (best is None or d < best[0]):
            best = (d, b)
    if best is None:
        return {'bsa': h / 100, 'dose_mg': math.floor(dose + Fraction(1, 2)), 'banded': False}
    return {'bsa': h / 100, 'dose_mg': best[1], 'banded': True}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('typical adult banded',
   {'height_cm': 170, 'weight_kg': 71, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.83, 'dose_mg': 180, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 55, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.59, 'dose_mg': 16, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 91, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [189, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 151]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 50, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 91, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 56, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.58, 'dose_mg': 95, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 72, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.84, 'dose_mg': 180, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 60, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.66, 'dose_mg': 17, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 92, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [188, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 152]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 250, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 453, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 57, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.59, 'dose_mg': 95, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 73, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.86, 'dose_mg': 190, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 63, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.7, 'dose_mg': 17, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 93, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [187, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 153]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 450, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 815, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 58, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.61, 'dose_mg': 97, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 74, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.87, 'dose_mg': 190, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 72, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.82, 'dose_mg': 18, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 94, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [186, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 154]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 650, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 1177, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 59, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.62, 'dose_mg': 97, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 75, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.88, 'dose_mg': 190, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 76, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.87, 'dose_mg': 19, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 95, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [185, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 155]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 850, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 1539, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 60, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.63, 'dose_mg': 98, 'banded': False})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    h = (math.isqrt(100 * x['height_cm'] * x['weight_kg']) + 3) // 6
    h = min(h, 200) if x['weight_kg'] > 100 else h
    dose = Fraction(x['mg_m2'] * h, 100)
    best = None
    for b in sorted(x['bands']):
        d = abs(b - dose)
        if d * 20 <= dose and (best is None or d < best[0]):
            best = (d, b)
    if best is None:
        return {'bsa': h / 100, 'dose_mg': math.floor(dose + Fraction(1, 2)), 'banded': False}
    return {'bsa': h / 100, 'dose_mg': best[1], 'banded': True}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('typical adult banded',
   {'height_cm': 170, 'weight_kg': 71, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.83, 'dose_mg': 180, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 55, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.59, 'dose_mg': 16, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 91, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [189, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 151]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 50, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 91, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 56, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.58, 'dose_mg': 95, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 72, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.84, 'dose_mg': 180, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 60, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.66, 'dose_mg': 17, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 92, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [188, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 152]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 250, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 453, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 57, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.59, 'dose_mg': 95, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 73, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.86, 'dose_mg': 190, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 63, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.7, 'dose_mg': 17, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 93, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [187, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 153]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 450, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 815, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 58, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.61, 'dose_mg': 97, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 74, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.87, 'dose_mg': 190, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 72, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.82, 'dose_mg': 18, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 94, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [186, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 154]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 650, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 1177, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 59, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.62, 'dose_mg': 97, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 75, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.88, 'dose_mg': 190, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 76, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.87, 'dose_mg': 19, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 95, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [185, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 155]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 850, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 1539, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 60, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.63, 'dose_mg': 98, 'banded': False})]]
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:
Every patient is dosed on a BSA of 0.02 m2.

Input {height_cm, weight_kg (integers), mg_m2, bands}. BSA (Mosteller) = sqrt(height*weight/3600) rounded half-up to 0.01 m2, computed exactly as (isqrt(100*h*w)+3)//6 hundredths, and capped at 2.00 m2. dose = mg_m2 * BSA. Dose banding: the band with the smallest absolute difference that is within 5% of the dose (difference*20 <= dose) is used, ties going to the lower band; otherwise the dose is rounded half-up to a whole mg. Return {bsa, dose_mg, banded}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    h = (math.isqrt(100 * x['height_cm'] * x['weight_kg']) + 3) // 6
    h = min(h, 200)
    dose = Fraction(x['mg_m2'] * h, 100)
    best = None
    for b in sorted(x['bands']):
        d = abs(b - dose)
        if d * 20 < dose and (best is None or d < best[0]):
            best = (d, b)
    if best is None:
        return {'bsa': h / 100, 'dose_mg': math.floor(dose + Fraction(1, 2)), 'banded': False}
    return {'bsa': h / 100, 'dose_mg': best[1], 'banded': True}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('typical adult banded',
   {'height_cm': 170, 'weight_kg': 71, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.83, 'dose_mg': 180, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 55, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.59, 'dose_mg': 16, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 91, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [189, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 151]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 50, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 91, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 56, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.58, 'dose_mg': 95, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 72, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.84, 'dose_mg': 180, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 60, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.66, 'dose_mg': 17, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 92, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [188, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 152]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 250, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 453, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 57, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.59, 'dose_mg': 95, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 73, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.86, 'dose_mg': 190, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 63, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.7, 'dose_mg': 17, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 93, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [187, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 153]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 450, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 815, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 58, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.61, 'dose_mg': 97, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 74, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.87, 'dose_mg': 190, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 72, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.82, 'dose_mg': 18, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 94, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [186, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 154]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 650, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 1177, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 59, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.62, 'dose_mg': 97, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 75, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.88, 'dose_mg': 190, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 76, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.87, 'dose_mg': 19, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 95, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [185, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 155]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 850, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 1539, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 60, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.63, 'dose_mg': 98, 'banded': False})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    h = (math.isqrt(100 * x['height_cm'] * x['weight_kg']) + 3) // 6
    h = min(h, 200)
    dose = Fraction(x['mg_m2'] * h, 100)
    best = None
    for b in sorted(x['bands']):
        d = abs(b - dose)
        if d <= 5 and (best is None or d < best[0]):
            best = (d, b)
    if best is None:
        return {'bsa': h / 100, 'dose_mg': math.floor(dose + Fraction(1, 2)), 'banded': False}
    return {'bsa': h / 100, 'dose_mg': best[1], 'banded': True}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('typical adult banded',
   {'height_cm': 170, 'weight_kg': 71, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.83, 'dose_mg': 180, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 55, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.59, 'dose_mg': 16, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 91, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [189, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 151]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 50, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 91, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 56, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.58, 'dose_mg': 95, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 72, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.84, 'dose_mg': 180, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 60, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.66, 'dose_mg': 17, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 92, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [188, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 152]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 250, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 453, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 57, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.59, 'dose_mg': 95, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 73, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.86, 'dose_mg': 190, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 63, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.7, 'dose_mg': 17, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 93, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [187, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 153]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 450, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 815, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 58, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.61, 'dose_mg': 97, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 74, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.87, 'dose_mg': 190, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 72, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.82, 'dose_mg': 18, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 94, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [186, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 154]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 650, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 1177, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 59, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.62, 'dose_mg': 97, 'banded': False})],
 [('typical adult banded',
   {'height_cm': 170, 'weight_kg': 75, 'mg_m2': 100, 'bands': [170, 180, 190, 200]},
   {'bsa': 1.88, 'dose_mg': 190, 'banded': True}),
  ('BSA hundredths rounding',
   {'height_cm': 165, 'weight_kg': 76, 'mg_m2': 10, 'bands': []},
   {'bsa': 1.87, 'dose_mg': 19, 'banded': False}),
  ('tall patient capped at 2.00',
   {'height_cm': 200, 'weight_kg': 95, 'mg_m2': 75, 'bands': [140, 150, 160]},
   {'bsa': 2.0, 'dose_mg': 150, 'banded': True}),
  ('band exactly 5 percent away',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [185, 190, 250]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('equidistant bands prefer lower',
   {'height_cm': 200, 'weight_kg': 100, 'mg_m2': 100, 'bands': [210, 190, 155]},
   {'bsa': 2.0, 'dose_mg': 190, 'banded': True}),
  ('unbanded half milligram rounds up',
   {'height_cm': 150, 'weight_kg': 79, 'mg_m2': 850, 'bands': [1]},
   {'bsa': 1.81, 'dose_mg': 1539, 'banded': False}),
  ('no band within tolerance',
   {'height_cm': 160, 'weight_kg': 60, 'mg_m2': 60, 'bands': [50, 150]},
   {'bsa': 1.63, 'dose_mg': 98, 'banded': False})]]
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 band exactly 5% from the calculated dose is rejected.

Input {height_cm, weight_kg (integers), mg_m2, bands}. BSA (Mosteller) = sqrt(height*weight/3600) rounded half-up to 0.01 m2, computed exactly as (isqrt(100*h*w)+3)//6 hundredths, and capped at 2.00 m2. dose = mg_m2 * BSA. Dose banding: the band with the smallest absolute difference that is within 5% of the dose (difference*20 <= dose) is used, ties going to the lower band; otherwise the dose is rounded half-up to a whole mg. Return {bsa, dose_mg, banded}.

split: open-access