broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    w = Fraction(str(x['weight_kg']))
    per_day = 24 // x['interval_h'] + 1
    daily = min(Fraction(str(x['mg_per_kg_day'])) * w, x['max_daily_mg'])
    dose = min(daily / per_day, x['max_single_mg'])
    inc = Fraction(str(x['round_mg']))
    dose = math.floor(dose / inc) * inc
    return {'doses_per_day': per_day, 'dose_mg': float(dose), 'daily_mg': float(dose * per_day)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('every 8 hours normal order',
   {'weight_kg': 21,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 220.0, 'daily_mg': 660.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 11,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 110.0, 'daily_mg': 440.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 61,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 41,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 14,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 10.0, 'daily_mg': 10.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 22,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 165.0, 'daily_mg': 330.0})],
 [('every 8 hours normal order',
   {'weight_kg': 22,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 230.0, 'daily_mg': 690.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 12,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 120.0, 'daily_mg': 480.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 62,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 42,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 19,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 15.0, 'daily_mg': 15.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 24,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 180.0, 'daily_mg': 360.0})],
 [('every 8 hours normal order',
   {'weight_kg': 23,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 245.0, 'daily_mg': 735.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 13,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 130.0, 'daily_mg': 520.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 63,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 43,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 24,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 20.0, 'daily_mg': 20.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 26,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 195.0, 'daily_mg': 390.0})],
 [('every 8 hours normal order',
   {'weight_kg': 24,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 255.0, 'daily_mg': 765.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 14,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 140.0, 'daily_mg': 560.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 64,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 44,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 29,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 25.0, 'daily_mg': 25.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 28,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 210.0, 'daily_mg': 420.0})],
 [('every 8 hours normal order',
   {'weight_kg': 25,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 265.0, 'daily_mg': 795.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 15,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 150.0, 'daily_mg': 600.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 65,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 45,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 34,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 30.0, 'daily_mg': 30.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 30,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 225.0, 'daily_mg': 450.0})]]
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):
    w = Fraction(str(x['weight_kg']))
    per_day = 24 // x['interval_h'] + 1 if x['interval_h'] < 12 else 24 // x['interval_h']
    daily = min(Fraction(str(x['mg_per_kg_day'])) * w, x['max_daily_mg'])
    dose = min(daily / per_day, x['max_single_mg'])
    inc = Fraction(str(x['round_mg']))
    dose = math.floor(dose / inc) * inc
    return {'doses_per_day': per_day, 'dose_mg': float(dose), 'daily_mg': float(dose * per_day)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('every 8 hours normal order',
   {'weight_kg': 21,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 220.0, 'daily_mg': 660.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 11,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 110.0, 'daily_mg': 440.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 61,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 41,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 14,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 10.0, 'daily_mg': 10.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 22,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 165.0, 'daily_mg': 330.0})],
 [('every 8 hours normal order',
   {'weight_kg': 22,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 230.0, 'daily_mg': 690.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 12,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 120.0, 'daily_mg': 480.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 62,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 42,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 19,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 15.0, 'daily_mg': 15.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 24,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 180.0, 'daily_mg': 360.0})],
 [('every 8 hours normal order',
   {'weight_kg': 23,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 245.0, 'daily_mg': 735.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 13,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 130.0, 'daily_mg': 520.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 63,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 43,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 24,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 20.0, 'daily_mg': 20.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 26,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 195.0, 'daily_mg': 390.0})],
 [('every 8 hours normal order',
   {'weight_kg': 24,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 255.0, 'daily_mg': 765.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 14,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 140.0, 'daily_mg': 560.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 64,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 44,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 29,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 25.0, 'daily_mg': 25.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 28,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 210.0, 'daily_mg': 420.0})],
 [('every 8 hours normal order',
   {'weight_kg': 25,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 265.0, 'daily_mg': 795.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 15,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 150.0, 'daily_mg': 600.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 65,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 45,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 34,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 30.0, 'daily_mg': 30.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 30,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 225.0, 'daily_mg': 450.0})]]
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:
An every-8-hour order is split into four doses, so each dose is a quarter of the daily amount.

Input {weight_kg, mg_per_kg_day, interval_h (divides 24), max_single_mg, max_daily_mg, round_mg}. Toy rule: doses/day = 24 / interval_h; daily = min(mg_per_kg_day * weight, max_daily_mg); per-dose = min(daily / doses, max_single_mg), then rounded DOWN to a multiple of round_mg. Return {doses_per_day, dose_mg, daily_mg = dose_mg * doses_per_day}.

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):
    w = Fraction(str(x['weight_kg']))
    per_day = 24 // x['interval_h']
    daily = Fraction(str(x['mg_per_kg_day'])) * w
    dose = min(daily / per_day, x['max_single_mg'])
    inc = Fraction(str(x['round_mg']))
    dose = math.floor(dose / inc) * inc
    return {'doses_per_day': per_day, 'dose_mg': float(dose), 'daily_mg': float(dose * per_day)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('every 8 hours normal order',
   {'weight_kg': 21,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 220.0, 'daily_mg': 660.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 11,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 110.0, 'daily_mg': 440.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 61,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 41,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 14,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 10.0, 'daily_mg': 10.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 22,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 165.0, 'daily_mg': 330.0})],
 [('every 8 hours normal order',
   {'weight_kg': 22,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 230.0, 'daily_mg': 690.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 12,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 120.0, 'daily_mg': 480.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 62,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 42,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 19,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 15.0, 'daily_mg': 15.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 24,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 180.0, 'daily_mg': 360.0})],
 [('every 8 hours normal order',
   {'weight_kg': 23,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 245.0, 'daily_mg': 735.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 13,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 130.0, 'daily_mg': 520.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 63,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 43,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 24,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 20.0, 'daily_mg': 20.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 26,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 195.0, 'daily_mg': 390.0})],
 [('every 8 hours normal order',
   {'weight_kg': 24,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 255.0, 'daily_mg': 765.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 14,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 140.0, 'daily_mg': 560.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 64,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 44,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 29,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 25.0, 'daily_mg': 25.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 28,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 210.0, 'daily_mg': 420.0})],
 [('every 8 hours normal order',
   {'weight_kg': 25,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 265.0, 'daily_mg': 795.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 15,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 150.0, 'daily_mg': 600.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 65,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 45,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 34,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 30.0, 'daily_mg': 30.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 30,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 225.0, 'daily_mg': 450.0})]]
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):
    w = Fraction(str(x['weight_kg']))
    per_day = 24 // x['interval_h']
    daily = min(Fraction(str(x['mg_per_kg_day'])) * w, x['max_daily_mg'] * per_day)
    dose = min(daily / per_day, x['max_single_mg'])
    inc = Fraction(str(x['round_mg']))
    dose = math.floor(dose / inc) * inc
    return {'doses_per_day': per_day, 'dose_mg': float(dose), 'daily_mg': float(dose * per_day)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('every 8 hours normal order',
   {'weight_kg': 21,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 220.0, 'daily_mg': 660.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 11,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 110.0, 'daily_mg': 440.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 61,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 41,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 14,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 10.0, 'daily_mg': 10.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 22,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 165.0, 'daily_mg': 330.0})],
 [('every 8 hours normal order',
   {'weight_kg': 22,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 230.0, 'daily_mg': 690.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 12,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 120.0, 'daily_mg': 480.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 62,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 42,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 19,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 15.0, 'daily_mg': 15.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 24,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 180.0, 'daily_mg': 360.0})],
 [('every 8 hours normal order',
   {'weight_kg': 23,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 245.0, 'daily_mg': 735.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 13,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 130.0, 'daily_mg': 520.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 63,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 43,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 24,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 20.0, 'daily_mg': 20.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 26,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 195.0, 'daily_mg': 390.0})],
 [('every 8 hours normal order',
   {'weight_kg': 24,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 255.0, 'daily_mg': 765.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 14,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 140.0, 'daily_mg': 560.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 64,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 44,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 29,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 25.0, 'daily_mg': 25.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 28,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 210.0, 'daily_mg': 420.0})],
 [('every 8 hours normal order',
   {'weight_kg': 25,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 265.0, 'daily_mg': 795.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 15,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 150.0, 'daily_mg': 600.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 65,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 45,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 34,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 30.0, 'daily_mg': 30.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 30,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 225.0, 'daily_mg': 450.0})]]
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:
Large children receive more than the maximum daily amount when the single-dose cap is loose.

Input {weight_kg, mg_per_kg_day, interval_h (divides 24), max_single_mg, max_daily_mg, round_mg}. Toy rule: doses/day = 24 / interval_h; daily = min(mg_per_kg_day * weight, max_daily_mg); per-dose = min(daily / doses, max_single_mg), then rounded DOWN to a multiple of round_mg. Return {doses_per_day, dose_mg, daily_mg = dose_mg * doses_per_day}.

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):
    w = Fraction(str(x['weight_kg']))
    per_day = 24 // x['interval_h']
    daily = min(Fraction(str(x['mg_per_kg_day'])) * w, x['max_daily_mg'])
    dose = daily / per_day
    inc = Fraction(str(x['round_mg']))
    dose = math.floor(dose / inc) * inc
    return {'doses_per_day': per_day, 'dose_mg': float(dose), 'daily_mg': float(dose * per_day)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('every 8 hours normal order',
   {'weight_kg': 21,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 220.0, 'daily_mg': 660.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 11,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 110.0, 'daily_mg': 440.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 61,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 41,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 14,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 10.0, 'daily_mg': 10.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 22,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 165.0, 'daily_mg': 330.0})],
 [('every 8 hours normal order',
   {'weight_kg': 22,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 230.0, 'daily_mg': 690.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 12,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 120.0, 'daily_mg': 480.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 62,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 42,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 19,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 15.0, 'daily_mg': 15.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 24,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 180.0, 'daily_mg': 360.0})],
 [('every 8 hours normal order',
   {'weight_kg': 23,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 245.0, 'daily_mg': 735.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 13,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 130.0, 'daily_mg': 520.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 63,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 43,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 24,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 20.0, 'daily_mg': 20.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 26,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 195.0, 'daily_mg': 390.0})],
 [('every 8 hours normal order',
   {'weight_kg': 24,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 255.0, 'daily_mg': 765.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 14,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 140.0, 'daily_mg': 560.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 64,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 44,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 29,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 25.0, 'daily_mg': 25.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 28,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 210.0, 'daily_mg': 420.0})],
 [('every 8 hours normal order',
   {'weight_kg': 25,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 265.0, 'daily_mg': 795.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 15,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 150.0, 'daily_mg': 600.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 65,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 45,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 34,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 30.0, 'daily_mg': 30.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 30,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 225.0, 'daily_mg': 450.0})]]
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):
    w = Fraction(str(x['weight_kg']))
    per_day = 24 // x['interval_h']
    daily = min(Fraction(str(x['mg_per_kg_day'])) * w, x['max_daily_mg'])
    dose = min(daily, x['max_single_mg']) / per_day
    inc = Fraction(str(x['round_mg']))
    dose = math.floor(dose / inc) * inc
    return {'doses_per_day': per_day, 'dose_mg': float(dose), 'daily_mg': float(dose * per_day)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('every 8 hours normal order',
   {'weight_kg': 21,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 220.0, 'daily_mg': 660.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 11,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 110.0, 'daily_mg': 440.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 61,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 41,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 14,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 10.0, 'daily_mg': 10.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 22,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 165.0, 'daily_mg': 330.0})],
 [('every 8 hours normal order',
   {'weight_kg': 22,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 230.0, 'daily_mg': 690.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 12,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 120.0, 'daily_mg': 480.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 62,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 42,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 19,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 15.0, 'daily_mg': 15.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 24,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 180.0, 'daily_mg': 360.0})],
 [('every 8 hours normal order',
   {'weight_kg': 23,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 245.0, 'daily_mg': 735.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 13,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 130.0, 'daily_mg': 520.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 63,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 43,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 24,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 20.0, 'daily_mg': 20.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 26,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 195.0, 'daily_mg': 390.0})],
 [('every 8 hours normal order',
   {'weight_kg': 24,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 255.0, 'daily_mg': 765.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 14,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 140.0, 'daily_mg': 560.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 64,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 44,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 29,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 25.0, 'daily_mg': 25.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 28,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 210.0, 'daily_mg': 420.0})],
 [('every 8 hours normal order',
   {'weight_kg': 25,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 265.0, 'daily_mg': 795.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 15,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 150.0, 'daily_mg': 600.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 65,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 45,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 34,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 30.0, 'daily_mg': 30.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 30,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 225.0, 'daily_mg': 450.0})]]
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:
Individual doses above max_single_mg are produced for heavy patients on high mg/kg/day orders.

Input {weight_kg, mg_per_kg_day, interval_h (divides 24), max_single_mg, max_daily_mg, round_mg}. Toy rule: doses/day = 24 / interval_h; daily = min(mg_per_kg_day * weight, max_daily_mg); per-dose = min(daily / doses, max_single_mg), then rounded DOWN to a multiple of round_mg. Return {doses_per_day, dose_mg, daily_mg = dose_mg * doses_per_day}.

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):
    w = Fraction(str(x['weight_kg']))
    per_day = 24 // x['interval_h']
    daily = min(Fraction(str(x['mg_per_kg_day'])) * w, x['max_daily_mg'])
    dose = min(daily / per_day, x['max_single_mg'])
    inc = Fraction(str(x['round_mg']))
    dose = round(dose / inc) * inc
    return {'doses_per_day': per_day, 'dose_mg': float(dose), 'daily_mg': float(dose * per_day)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('every 8 hours normal order',
   {'weight_kg': 21,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 220.0, 'daily_mg': 660.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 11,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 110.0, 'daily_mg': 440.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 61,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 41,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 14,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 10.0, 'daily_mg': 10.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 22,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 165.0, 'daily_mg': 330.0})],
 [('every 8 hours normal order',
   {'weight_kg': 22,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 230.0, 'daily_mg': 690.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 12,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 120.0, 'daily_mg': 480.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 62,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 42,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 19,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 15.0, 'daily_mg': 15.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 24,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 180.0, 'daily_mg': 360.0})],
 [('every 8 hours normal order',
   {'weight_kg': 23,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 245.0, 'daily_mg': 735.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 13,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 130.0, 'daily_mg': 520.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 63,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 43,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 24,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 20.0, 'daily_mg': 20.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 26,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 195.0, 'daily_mg': 390.0})],
 [('every 8 hours normal order',
   {'weight_kg': 24,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 255.0, 'daily_mg': 765.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 14,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 140.0, 'daily_mg': 560.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 64,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 44,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 29,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 25.0, 'daily_mg': 25.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 28,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 210.0, 'daily_mg': 420.0})],
 [('every 8 hours normal order',
   {'weight_kg': 25,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 265.0, 'daily_mg': 795.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 15,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 150.0, 'daily_mg': 600.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 65,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 45,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 34,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 30.0, 'daily_mg': 30.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 30,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 225.0, 'daily_mg': 450.0})]]
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):
    w = Fraction(str(x['weight_kg']))
    per_day = 24 // x['interval_h']
    daily = min(Fraction(str(x['mg_per_kg_day'])) * w, x['max_daily_mg'])
    dose = min(daily / per_day, x['max_single_mg'])
    inc = Fraction(str(x['round_mg']))
    dose = math.ceil(dose / inc) * inc
    return {'doses_per_day': per_day, 'dose_mg': float(dose), 'daily_mg': float(dose * per_day)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('every 8 hours normal order',
   {'weight_kg': 21,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 220.0, 'daily_mg': 660.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 11,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 110.0, 'daily_mg': 440.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 61,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 41,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 14,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 10.0, 'daily_mg': 10.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 22,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 165.0, 'daily_mg': 330.0})],
 [('every 8 hours normal order',
   {'weight_kg': 22,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 230.0, 'daily_mg': 690.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 12,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 120.0, 'daily_mg': 480.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 62,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 42,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 19,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 15.0, 'daily_mg': 15.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 24,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 180.0, 'daily_mg': 360.0})],
 [('every 8 hours normal order',
   {'weight_kg': 23,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 245.0, 'daily_mg': 735.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 13,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 130.0, 'daily_mg': 520.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 63,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 43,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 24,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 20.0, 'daily_mg': 20.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 26,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 195.0, 'daily_mg': 390.0})],
 [('every 8 hours normal order',
   {'weight_kg': 24,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 255.0, 'daily_mg': 765.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 14,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 140.0, 'daily_mg': 560.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 64,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 44,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 29,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 25.0, 'daily_mg': 25.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 28,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 210.0, 'daily_mg': 420.0})],
 [('every 8 hours normal order',
   {'weight_kg': 25,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 265.0, 'daily_mg': 795.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 15,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 150.0, 'daily_mg': 600.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 65,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 45,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 34,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 30.0, 'daily_mg': 30.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 30,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 225.0, 'daily_mg': 450.0})]]
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 144 mg calculated dose is dispensed as 145 mg.

Input {weight_kg, mg_per_kg_day, interval_h (divides 24), max_single_mg, max_daily_mg, round_mg}. Toy rule: doses/day = 24 / interval_h; daily = min(mg_per_kg_day * weight, max_daily_mg); per-dose = min(daily / doses, max_single_mg), then rounded DOWN to a multiple of round_mg. Return {doses_per_day, dose_mg, daily_mg = dose_mg * doses_per_day}.

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):
    w = Fraction(str(x['weight_kg']))
    per_day = 24 // x['interval_h']
    daily = min(Fraction(str(x['mg_per_kg_day'])) * w, x['max_daily_mg'])
    dose = min(daily / per_day, x['max_single_mg'])
    inc = Fraction(str(x['round_mg']))
    dose = math.floor(dose / inc) * inc
    return {'doses_per_day': per_day, 'dose_mg': float(dose), 'daily_mg': float(daily)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('every 8 hours normal order',
   {'weight_kg': 21,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 220.0, 'daily_mg': 660.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 11,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 110.0, 'daily_mg': 440.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 61,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 41,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 14,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 10.0, 'daily_mg': 10.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 22,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 165.0, 'daily_mg': 330.0})],
 [('every 8 hours normal order',
   {'weight_kg': 22,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 230.0, 'daily_mg': 690.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 12,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 120.0, 'daily_mg': 480.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 62,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 42,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 19,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 15.0, 'daily_mg': 15.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 24,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 180.0, 'daily_mg': 360.0})],
 [('every 8 hours normal order',
   {'weight_kg': 23,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 245.0, 'daily_mg': 735.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 13,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 130.0, 'daily_mg': 520.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 63,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 43,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 24,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 20.0, 'daily_mg': 20.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 26,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 195.0, 'daily_mg': 390.0})],
 [('every 8 hours normal order',
   {'weight_kg': 24,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 255.0, 'daily_mg': 765.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 14,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 140.0, 'daily_mg': 560.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 64,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 44,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 29,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 25.0, 'daily_mg': 25.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 28,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 210.0, 'daily_mg': 420.0})],
 [('every 8 hours normal order',
   {'weight_kg': 25,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 265.0, 'daily_mg': 795.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 15,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 150.0, 'daily_mg': 600.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 65,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 45,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 34,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 30.0, 'daily_mg': 30.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 30,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 225.0, 'daily_mg': 450.0})]]
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):
    w = Fraction(str(x['weight_kg']))
    per_day = 24 // x['interval_h']
    daily = min(Fraction(str(x['mg_per_kg_day'])) * w, x['max_daily_mg'])
    dose = min(daily / per_day, x['max_single_mg'])
    inc = Fraction(str(x['round_mg']))
    dose = math.floor(dose / inc) * inc
    return {'doses_per_day': per_day, 'dose_mg': float(dose), 'daily_mg': float(math.floor(daily / inc) * inc)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('every 8 hours normal order',
   {'weight_kg': 21,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 220.0, 'daily_mg': 660.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 11,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 110.0, 'daily_mg': 440.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 61,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 41,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 14,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 10.0, 'daily_mg': 10.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 22,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 165.0, 'daily_mg': 330.0})],
 [('every 8 hours normal order',
   {'weight_kg': 22,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 230.0, 'daily_mg': 690.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 12,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 120.0, 'daily_mg': 480.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 62,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 42,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 19,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 15.0, 'daily_mg': 15.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 24,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 180.0, 'daily_mg': 360.0})],
 [('every 8 hours normal order',
   {'weight_kg': 23,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 245.0, 'daily_mg': 735.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 13,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 130.0, 'daily_mg': 520.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 63,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 43,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 24,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 20.0, 'daily_mg': 20.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 26,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 195.0, 'daily_mg': 390.0})],
 [('every 8 hours normal order',
   {'weight_kg': 24,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 255.0, 'daily_mg': 765.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 14,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 140.0, 'daily_mg': 560.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 64,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 44,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 29,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 25.0, 'daily_mg': 25.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 28,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 210.0, 'daily_mg': 420.0})],
 [('every 8 hours normal order',
   {'weight_kg': 25,
    'mg_per_kg_day': 32,
    'interval_h': 8,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 5},
   {'doses_per_day': 3, 'dose_mg': 265.0, 'daily_mg': 795.0}),
  ('every 6 hours with 2.5 mg steps',
   {'weight_kg': 15,
    'mg_per_kg_day': 40,
    'interval_h': 6,
    'max_single_mg': 500,
    'max_daily_mg': 2000,
    'round_mg': '2.5'},
   {'doses_per_day': 4, 'dose_mg': 150.0, 'daily_mg': 600.0}),
  ('daily ceiling limits large child',
   {'weight_kg': 65,
    'mg_per_kg_day': 50,
    'interval_h': 12,
    'max_single_mg': 1500,
    'max_daily_mg': 2000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('single-dose ceiling',
   {'weight_kg': 45,
    'mg_per_kg_day': 100,
    'interval_h': 12,
    'max_single_mg': 1000,
    'max_daily_mg': 5000,
    'round_mg': 5},
   {'doses_per_day': 2, 'dose_mg': 1000.0, 'daily_mg': 2000.0}),
  ('rounding never exceeds calculated dose',
   {'weight_kg': 34,
    'mg_per_kg_day': 1,
    'interval_h': 24,
    'max_single_mg': 500,
    'max_daily_mg': 500,
    'round_mg': 5},
   {'doses_per_day': 1, 'dose_mg': 30.0, 'daily_mg': 30.0}),
  ('twice daily control',
   {'weight_kg': 15,
    'mg_per_kg_day': 30,
    'interval_h': 12,
    'max_single_mg': 500,
    'max_daily_mg': 1500,
    'round_mg': 1},
   {'doses_per_day': 2, 'dose_mg': 225.0, 'daily_mg': 450.0})]]
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:
The daily total shown to the prescriber disagrees with the sum of the rounded doses.

Input {weight_kg, mg_per_kg_day, interval_h (divides 24), max_single_mg, max_daily_mg, round_mg}. Toy rule: doses/day = 24 / interval_h; daily = min(mg_per_kg_day * weight, max_daily_mg); per-dose = min(daily / doses, max_single_mg), then rounded DOWN to a multiple of round_mg. Return {doses_per_day, dose_mg, daily_mg = dose_mg * doses_per_day}.

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):
    conc = Fraction(x['drug_mg']) / Fraction(str(x['bag_ml']))
    rate = Fraction(str(x['dose'])) * Fraction(str(x['weight_kg'])) * 60 / conc
    tenths = math.floor(rate * 10 + Fraction(1, 2))
    if tenths > 9999:
        return {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': float(conc)}
    if tenths == 0:
        return {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': float(conc)}
    return {'status': 'OK', 'conc_mcg_ml': float(conc), 'rate_ml_h': tenths / 10}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('standard adult infusion',
   {'dose': '5', 'weight_kg': 71, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.3}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 5, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.3}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 101, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 101},
   {'status': 'OK', 'conc_mcg_ml': 594.059405940594, 'rate_ml_h': 151.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 67, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 8, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 72, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.5}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.5}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 102, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 102},
   {'status': 'OK', 'conc_mcg_ml': 588.2352941176471, 'rate_ml_h': 153.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 68, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 73, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.7}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 13, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.7}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 103, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 103},
   {'status': 'OK', 'conc_mcg_ml': 582.5242718446602, 'rate_ml_h': 154.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 69, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 10, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 74, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.9}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 17, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.9}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 104, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 104},
   {'status': 'OK', 'conc_mcg_ml': 576.9230769230769, 'rate_ml_h': 156.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 70, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 11, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 75, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 14.1}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 21, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 1.1}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 105, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 105},
   {'status': 'OK', 'conc_mcg_ml': 571.4285714285714, 'rate_ml_h': 157.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 71, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 12, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})]]
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):
    conc = Fraction(str(x['bag_ml'])) * 1000 / Fraction(x['drug_mg'])
    rate = Fraction(str(x['dose'])) * Fraction(str(x['weight_kg'])) * 60 / conc
    tenths = math.floor(rate * 10 + Fraction(1, 2))
    if tenths > 9999:
        return {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': float(conc)}
    if tenths == 0:
        return {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': float(conc)}
    return {'status': 'OK', 'conc_mcg_ml': float(conc), 'rate_ml_h': tenths / 10}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('standard adult infusion',
   {'dose': '5', 'weight_kg': 71, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.3}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 5, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.3}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 101, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 101},
   {'status': 'OK', 'conc_mcg_ml': 594.059405940594, 'rate_ml_h': 151.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 67, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 8, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 72, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.5}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.5}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 102, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 102},
   {'status': 'OK', 'conc_mcg_ml': 588.2352941176471, 'rate_ml_h': 153.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 68, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 73, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.7}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 13, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.7}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 103, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 103},
   {'status': 'OK', 'conc_mcg_ml': 582.5242718446602, 'rate_ml_h': 154.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 69, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 10, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 74, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.9}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 17, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.9}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 104, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 104},
   {'status': 'OK', 'conc_mcg_ml': 576.9230769230769, 'rate_ml_h': 156.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 70, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 11, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 75, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 14.1}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 21, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 1.1}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 105, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 105},
   {'status': 'OK', 'conc_mcg_ml': 571.4285714285714, 'rate_ml_h': 157.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 71, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 12, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})]]
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:
Pump rates come out a thousand times too high and most orders are rejected as exceeding the pump.

Input {dose (mcg/kg/min), weight_kg, drug_mg, bag_ml}. Concentration = drug_mg*1000/bag_ml mcg/mL. Rate mL/h = dose*weight*60/concentration, rounded half-up to 0.1 mL/h. Pump accepts 0.1-999.9 mL/h: a rounded rate above 999.9 returns status EXCEEDS_PUMP, a rounded rate of 0.0 returns BELOW_RESOLUTION; otherwise status OK with rate_ml_h. conc_mcg_ml is always reported.

split: open-access