FA-63871 / Medication dosing calculations / Open access
Pediatric mg/kg/day dose divided by interval: administrations per day · case 01
An every-8-hour order is split into four doses, so each dose is a quarter of the daily amount.
ROOT CAUSE
Doses per day are counted as fence posts (0, 8, 16, 24 h) instead of intervals in 24 hours.
VERIFIED REPAIR
Use 24 / interval_h as the number of administrations per day.
Unsuccessful approach: Special-casing only intervals of 12 h and longer leaves the fence-post error for q6h and q8h orders.
Case contract
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}.
Why this case matters
Divided-dose calculators must count administrations per day correctly and apply both ceilings before rounding down to a measurable increment.
1 / The failure
Exit 1"""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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| every 8 hours normal order | {'daily_mg': 660.0, 'dose_mg': 165.0, 'doses_per_day': 4} | {'daily_mg': 660.0, 'dose_mg': 220.0, 'doses_per_day': 3} | Failed |
| every 6 hours with 2.5 mg steps | {'daily_mg': 437.5, 'dose_mg': 87.5, 'doses_per_day': 5} | {'daily_mg': 440.0, 'dose_mg': 110.0, 'doses_per_day': 4} | Failed |
| daily ceiling limits large child | {'daily_mg': 1995.0, 'dose_mg': 665.0, 'doses_per_day': 3} | {'daily_mg': 2000.0, 'dose_mg': 1000.0, 'doses_per_day': 2} | Failed |
| single-dose ceiling | {'daily_mg': 3000.0, 'dose_mg': 1000.0, 'doses_per_day': 3} | {'daily_mg': 2000.0, 'dose_mg': 1000.0, 'doses_per_day': 2} | Failed |
| rounding never exceeds calculated dose | {'daily_mg': 10.0, 'dose_mg': 5.0, 'doses_per_day': 2} | {'daily_mg': 10.0, 'dose_mg': 10.0, 'doses_per_day': 1} | Failed |
| twice daily control | {'daily_mg': 330.0, 'dose_mg': 110.0, 'doses_per_day': 3} | {'daily_mg': 330.0, 'dose_mg': 165.0, 'doses_per_day': 2} | Failed |
SHA-256 / 2430b9d14422489650defef630a21a2ae688f1f403e6545cbbdb4ffc41611be5
2 / The unsuccessful fix
Exit 1"""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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| every 8 hours normal order | {'daily_mg': 660.0, 'dose_mg': 165.0, 'doses_per_day': 4} | {'daily_mg': 660.0, 'dose_mg': 220.0, 'doses_per_day': 3} | Failed |
| every 6 hours with 2.5 mg steps | {'daily_mg': 437.5, 'dose_mg': 87.5, 'doses_per_day': 5} | {'daily_mg': 440.0, 'dose_mg': 110.0, 'doses_per_day': 4} | Failed |
| daily ceiling limits large child | {'daily_mg': 2000.0, 'dose_mg': 1000.0, 'doses_per_day': 2} | {'daily_mg': 2000.0, 'dose_mg': 1000.0, 'doses_per_day': 2} | Passed |
| single-dose ceiling | {'daily_mg': 2000.0, 'dose_mg': 1000.0, 'doses_per_day': 2} | {'daily_mg': 2000.0, 'dose_mg': 1000.0, 'doses_per_day': 2} | Passed |
| rounding never exceeds calculated dose | {'daily_mg': 10.0, 'dose_mg': 10.0, 'doses_per_day': 1} | {'daily_mg': 10.0, 'dose_mg': 10.0, 'doses_per_day': 1} | Passed |
| twice daily control | {'daily_mg': 330.0, 'dose_mg': 165.0, 'doses_per_day': 2} | {'daily_mg': 330.0, 'dose_mg': 165.0, 'doses_per_day': 2} | Passed |
SHA-256 / 445c9123a91044ccc1beb78afed23e6af83406a16d238a7ba90071a4dded7102
3 / The verified repair
Exit 0"""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(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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| every 8 hours normal order | {'daily_mg': 660.0, 'dose_mg': 220.0, 'doses_per_day': 3} | {'daily_mg': 660.0, 'dose_mg': 220.0, 'doses_per_day': 3} | Passed |
| every 6 hours with 2.5 mg steps | {'daily_mg': 440.0, 'dose_mg': 110.0, 'doses_per_day': 4} | {'daily_mg': 440.0, 'dose_mg': 110.0, 'doses_per_day': 4} | Passed |
| daily ceiling limits large child | {'daily_mg': 2000.0, 'dose_mg': 1000.0, 'doses_per_day': 2} | {'daily_mg': 2000.0, 'dose_mg': 1000.0, 'doses_per_day': 2} | Passed |
| single-dose ceiling | {'daily_mg': 2000.0, 'dose_mg': 1000.0, 'doses_per_day': 2} | {'daily_mg': 2000.0, 'dose_mg': 1000.0, 'doses_per_day': 2} | Passed |
| rounding never exceeds calculated dose | {'daily_mg': 10.0, 'dose_mg': 10.0, 'doses_per_day': 1} | {'daily_mg': 10.0, 'dose_mg': 10.0, 'doses_per_day': 1} | Passed |
| twice daily control | {'daily_mg': 330.0, 'dose_mg': 165.0, 'doses_per_day': 2} | {'daily_mg': 330.0, 'dose_mg': 165.0, 'doses_per_day': 2} | Passed |
SHA-256 / 554b1c8d4d7287825c88725f774ac420ca44def84a74abf15542c063553f9798
Verification & scope
A deterministic toy software model with explicitly stipulated thresholds and formulas; it is not clinical guidance, not a validated medical calculator, and makes no claim of conformance to any published protocol. Numbered variants vary patient and order inputs. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:47:18.969278+00:00.
Case digest / 79170e96ec54d5670a4c8f2c9c060223d50d067c0c417a437585012dc305c674