broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    scr = Fraction(str(x['scr']))
    if x['age'] >= 65:
        scr = max(scr, Fraction(4, 5))
    crcl = Fraction(140 - x['age']) * Fraction(str(x['weight_kg'])) / (72 * scr)
    if x['sex'] == 'F':
        crcl = crcl * Fraction(17, 20)
    c = round(crcl)
    dose, tau = x['dose_mg'], x['interval_h']
    if c >= 60:
        pass
    elif c >= 30:
        tau = tau * 2
    elif c >= 15:
        dose, tau = dose // 2 // 5 * 5, tau * 2
    else:
        return {'crcl': c, 'action': 'AVOID'}
    return {'crcl': c, 'action': 'GIVE', 'dose_mg': dose, 'interval_h': tau}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('young adult normal function',
   {'age': 31, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 79, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 141, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 71, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 260, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 260, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 6},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 12}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 175, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 85, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 32, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 80, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 143, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 72, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 270, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 270, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 195, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 95, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 33, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 104, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 82, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 145, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 73, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 39, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 280, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 280, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 18},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 36}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 395, 'interval_h': 24},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 195, 'interval_h': 48}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 34, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 103, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 83, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 148, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 74, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 290, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 290, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 24},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 48}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 155, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 75, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 35, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 102, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 84, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 150, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 75, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 30},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 60}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 135, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 65, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})]]
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):
    scr = Fraction(str(x['scr']))
    if x['age'] >= 65:
        scr = max(scr, Fraction(4, 5))
    crcl = Fraction(140 - x['age']) * Fraction(str(x['weight_kg'])) / (72 * scr)
    if x['sex'] == 'F':
        crcl = crcl * Fraction(17, 20)
    c = math.ceil(crcl)
    dose, tau = x['dose_mg'], x['interval_h']
    if c >= 60:
        pass
    elif c >= 30:
        tau = tau * 2
    elif c >= 15:
        dose, tau = dose // 2 // 5 * 5, tau * 2
    else:
        return {'crcl': c, 'action': 'AVOID'}
    return {'crcl': c, 'action': 'GIVE', 'dose_mg': dose, 'interval_h': tau}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('young adult normal function',
   {'age': 31, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 79, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 141, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 71, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 260, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 260, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 6},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 12}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 175, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 85, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 32, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 80, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 143, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 72, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 270, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 270, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 195, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 95, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 33, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 104, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 82, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 145, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 73, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 39, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 280, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 280, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 18},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 36}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 395, 'interval_h': 24},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 195, 'interval_h': 48}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 34, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 103, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 83, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 148, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 74, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 290, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 290, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 24},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 48}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 155, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 75, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 35, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 102, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 84, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 150, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 75, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 30},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 60}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 135, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 65, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})]]
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 clearance of 59.7 mL/min is treated as 60 and the interval is not extended.

Input {age, weight_kg, scr, sex, dose_mg, interval_h}. Toy rule: if age >= 65, serum creatinine is raised to at least 0.8 mg/dL. CrCl = (140-age)*weight/(72*scr), times 0.85 for sex "F", then truncated to an integer. Bands: CrCl >= 60 unchanged; 30-59 same dose, interval doubled; 15-29 dose halved and rounded down to a 5 mg multiple, interval doubled; < 15 action AVOID. Return {crcl, action, dose_mg, interval_h} (AVOID omits dose and interval).

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):
    scr = Fraction(str(x['scr']))
    if x['age'] >= 65:
        scr = max(scr, Fraction(4, 5))
    crcl = Fraction(140 - x['age']) * Fraction(str(x['weight_kg'])) / (72 * scr)
    if x['sex'] == 'F':
        crcl = crcl * Fraction(17, 20)
    c = math.floor(crcl)
    dose, tau = x['dose_mg'], x['interval_h']
    if c >= 60:
        pass
    elif c > 30:
        tau = tau * 2
    elif c >= 15:
        dose, tau = dose // 2 // 5 * 5, tau * 2
    else:
        return {'crcl': c, 'action': 'AVOID'}
    return {'crcl': c, 'action': 'GIVE', 'dose_mg': dose, 'interval_h': tau}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('young adult normal function',
   {'age': 31, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 79, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 141, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 71, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 260, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 260, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 6},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 12}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 175, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 85, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 32, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 80, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 143, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 72, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 270, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 270, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 195, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 95, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 33, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 104, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 82, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 145, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 73, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 39, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 280, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 280, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 18},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 36}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 395, 'interval_h': 24},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 195, 'interval_h': 48}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 34, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 103, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 83, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 148, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 74, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 290, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 290, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 24},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 48}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 155, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 75, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 35, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 102, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 84, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 150, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 75, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 30},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 60}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 135, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 65, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})]]
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):
    scr = Fraction(str(x['scr']))
    if x['age'] >= 65:
        scr = max(scr, Fraction(4, 5))
    crcl = Fraction(140 - x['age']) * Fraction(str(x['weight_kg'])) / (72 * scr)
    if x['sex'] == 'F':
        crcl = crcl * Fraction(17, 20)
    c = math.floor(crcl)
    dose, tau = x['dose_mg'], x['interval_h']
    if c >= 60:
        pass
    elif c >= 30 and c < 59:
        tau = tau * 2
    elif c >= 15:
        dose, tau = dose // 2 // 5 * 5, tau * 2
    else:
        return {'crcl': c, 'action': 'AVOID'}
    return {'crcl': c, 'action': 'GIVE', 'dose_mg': dose, 'interval_h': tau}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('young adult normal function',
   {'age': 31, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 79, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 141, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 71, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 260, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 260, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 6},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 12}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 175, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 85, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 32, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 80, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 143, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 72, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 270, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 270, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 195, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 95, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 33, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 104, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 82, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 145, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 73, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 39, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 280, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 280, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 18},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 36}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 395, 'interval_h': 24},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 195, 'interval_h': 48}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 34, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 103, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 83, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 148, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 74, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 290, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 290, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 24},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 48}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 155, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 75, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 35, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 102, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 84, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 150, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 75, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 30},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 60}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 135, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 65, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})]]
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 clearance of exactly 30 mL/min receives the severe-band half dose.

Input {age, weight_kg, scr, sex, dose_mg, interval_h}. Toy rule: if age >= 65, serum creatinine is raised to at least 0.8 mg/dL. CrCl = (140-age)*weight/(72*scr), times 0.85 for sex "F", then truncated to an integer. Bands: CrCl >= 60 unchanged; 30-59 same dose, interval doubled; 15-29 dose halved and rounded down to a 5 mg multiple, interval doubled; < 15 action AVOID. Return {crcl, action, dose_mg, interval_h} (AVOID omits dose and interval).

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):
    scr = Fraction(str(x['scr']))
    if x['age'] >= 65:
        scr = max(scr, Fraction(4, 5))
    crcl = Fraction(140 - x['age']) * Fraction(str(x['weight_kg'])) / (72 * scr)
    if x['sex'] == 'F':
        crcl = crcl * Fraction(17, 20)
    c = math.floor(crcl)
    dose, tau = x['dose_mg'], x['interval_h']
    if c >= 60:
        pass
    elif c >= 30:
        tau = tau * 2
    elif c >= 15:
        dose, tau = dose // 2, tau * 2
    else:
        return {'crcl': c, 'action': 'AVOID'}
    return {'crcl': c, 'action': 'GIVE', 'dose_mg': dose, 'interval_h': tau}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('young adult normal function',
   {'age': 31, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 79, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 141, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 71, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 260, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 260, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 6},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 12}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 175, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 85, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 32, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 80, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 143, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 72, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 270, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 270, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 195, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 95, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 33, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 104, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 82, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 145, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 73, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 39, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 280, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 280, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 18},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 36}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 395, 'interval_h': 24},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 195, 'interval_h': 48}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 34, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 103, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 83, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 148, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 74, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 290, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 290, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 24},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 48}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 155, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 75, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 35, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 102, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 84, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 150, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 75, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 30},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 60}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 135, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 65, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})]]
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):
    scr = Fraction(str(x['scr']))
    if x['age'] >= 65:
        scr = max(scr, Fraction(4, 5))
    crcl = Fraction(140 - x['age']) * Fraction(str(x['weight_kg'])) / (72 * scr)
    if x['sex'] == 'F':
        crcl = crcl * Fraction(17, 20)
    c = math.floor(crcl)
    dose, tau = x['dose_mg'], x['interval_h']
    if c >= 60:
        pass
    elif c >= 30:
        tau = tau * 2
    elif c >= 15:
        dose, tau = round(dose / 2 / 5) * 5, tau * 2
    else:
        return {'crcl': c, 'action': 'AVOID'}
    return {'crcl': c, 'action': 'GIVE', 'dose_mg': dose, 'interval_h': tau}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('young adult normal function',
   {'age': 31, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 79, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 141, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 71, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 260, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 260, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 6},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 12}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 175, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 85, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 32, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 80, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 143, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 72, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 270, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 270, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 195, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 95, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 33, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 104, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 82, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 145, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 73, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 39, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 280, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 280, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 18},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 36}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 395, 'interval_h': 24},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 195, 'interval_h': 48}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 34, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 103, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 83, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 148, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 74, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 290, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 290, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 24},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 48}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 155, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 75, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 35, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 102, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 84, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 150, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 75, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 30},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 60}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 135, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 65, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})]]
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 175 mg dose is halved to 87 mg, which is not a 5 mg multiple.

Input {age, weight_kg, scr, sex, dose_mg, interval_h}. Toy rule: if age >= 65, serum creatinine is raised to at least 0.8 mg/dL. CrCl = (140-age)*weight/(72*scr), times 0.85 for sex "F", then truncated to an integer. Bands: CrCl >= 60 unchanged; 30-59 same dose, interval doubled; 15-29 dose halved and rounded down to a 5 mg multiple, interval doubled; < 15 action AVOID. Return {crcl, action, dose_mg, interval_h} (AVOID omits dose and interval).

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):
    scr = Fraction(str(x['scr']))
    if x['age'] >= 65:
        scr = max(scr, Fraction(4, 5))
    crcl = Fraction(140 - x['age']) * Fraction(str(x['weight_kg'])) / (72 * scr)
    if x['sex'] == 'F':
        crcl = crcl * Fraction(17, 20)
    c = math.floor(crcl)
    dose, tau = x['dose_mg'], x['interval_h']
    if c >= 60:
        pass
    elif c >= 30:
        tau = tau * 2
    elif c >= 15:
        dose, tau = dose // 2 // 5 * 5, tau
    else:
        return {'crcl': c, 'action': 'AVOID'}
    return {'crcl': c, 'action': 'GIVE', 'dose_mg': dose, 'interval_h': tau}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('young adult normal function',
   {'age': 31, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 79, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 141, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 71, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 260, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 260, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 6},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 12}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 175, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 85, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 32, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 80, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 143, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 72, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 270, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 270, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 195, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 95, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 33, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 104, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 82, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 145, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 73, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 39, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 280, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 280, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 18},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 36}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 395, 'interval_h': 24},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 195, 'interval_h': 48}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 34, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 103, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 83, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 148, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 74, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 290, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 290, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 24},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 48}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 155, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 75, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 35, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 102, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 84, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 150, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 75, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 30},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 60}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 135, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 65, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})]]
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):
    scr = Fraction(str(x['scr']))
    if x['age'] >= 65:
        scr = max(scr, Fraction(4, 5))
    crcl = Fraction(140 - x['age']) * Fraction(str(x['weight_kg'])) / (72 * scr)
    if x['sex'] == 'F':
        crcl = crcl * Fraction(17, 20)
    c = math.floor(crcl)
    dose, tau = x['dose_mg'], x['interval_h']
    if c >= 60:
        pass
    elif c >= 30:
        tau = tau * 2
    elif c >= 15:
        dose, tau = dose // 2 // 5 * 5, tau + 12
    else:
        return {'crcl': c, 'action': 'AVOID'}
    return {'crcl': c, 'action': 'GIVE', 'dose_mg': dose, 'interval_h': tau}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('young adult normal function',
   {'age': 31, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 79, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 141, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 71, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 260, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 260, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 6},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 12}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 175, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 85, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 32, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 80, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 143, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 72, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 270, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 270, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 195, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 95, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 33, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 104, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 82, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 145, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 73, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 39, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 280, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 280, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 18},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 36}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 395, 'interval_h': 24},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 195, 'interval_h': 48}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 34, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 103, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 83, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 148, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 74, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 290, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 290, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 24},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 48}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 155, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 75, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 35, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 102, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 84, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 150, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 75, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 30},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 60}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 135, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 65, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})]]
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:
Severe impairment halves the dose but keeps the original interval.

Input {age, weight_kg, scr, sex, dose_mg, interval_h}. Toy rule: if age >= 65, serum creatinine is raised to at least 0.8 mg/dL. CrCl = (140-age)*weight/(72*scr), times 0.85 for sex "F", then truncated to an integer. Bands: CrCl >= 60 unchanged; 30-59 same dose, interval doubled; 15-29 dose halved and rounded down to a 5 mg multiple, interval doubled; < 15 action AVOID. Return {crcl, action, dose_mg, interval_h} (AVOID omits dose and interval).

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):
    target = Fraction(str(x['target_mg']))
    best = None
    for s in sorted(x['strengths']):
        step = Fraction(s, 2)
        units = math.floor(target / step + Fraction(1, 2))
        if units == 0:
            continue
        dose = units * step
        tabs = dose / s
        if tabs > 4:
            continue
        if abs(dose - target) * 100 > x['tol_pct'] * target:
            continue
        key = (abs(dose - target), math.ceil(tabs), -s)
        if best is None or key < best[0]:
            best = (key, s, tabs, dose)
    if best is None:
        return {'status': 'NO_MATCH'}
    return {'status': 'OK', 'strength': best[1], 'tablets': float(best[2]), 'dose_mg': float(best[3])}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('unscored tablet may not be halved',
   {'target_mg': 5, 'strengths': [10, 25], 'scored': [25], 'tol_pct': 10},
   {'status': 'NO_MATCH'}),
  ('scored tablet half used',
   {'target_mg': '7.5', 'strengths': [5, 10], 'scored': [5], 'tol_pct': 6},
   {'status': 'OK', 'strength': 5, 'tablets': 1.5, 'dose_mg': 7.5}),
  ('near dose rounds up to whole tablet',
   {'target_mg': 14, 'strengths': [5], 'scored': [], 'tol_pct': 11},
   {'status': 'OK', 'strength': 5, 'tablets': 3.0, 'dose_mg': 15.0}),
  ('near dose rounds down to whole tablet',
   {'target_mg': 11, 'strengths': [5], 'scored': [], 'tol_pct': 11},
   {'status': 'OK', 'strength': 5, 'tablets': 2.0, 'dose_mg': 10.0}),
  ('three and a half tablets allowed',
   {'target_mg': 35, 'strengths': [10], 'scored': [10], 'tol_pct': 1},
   {'status': 'OK', 'strength': 10, 'tablets': 3.5, 'dose_mg': 35.0}),
  ('exactly four tablets allowed',
   {'target_mg': 40, 'strengths': [10], 'scored': [], 'tol_pct': 1},
   {'status': 'OK', 'strength': 10, 'tablets': 4.0, 'dose_mg': 40.0}),
  ('tolerance measured against target',
   {'target_mg': 200, 'strengths': [150], 'scored': [], 'tol_pct': 27},
   {'status': 'OK', 'strength': 150, 'tablets': 1.0, 'dose_mg': 150.0}),
  ('equal error prefers larger strength',
   {'target_mg': 30, 'strengths': [15, 20], 'scored': [20], 'tol_pct': 1},
   {'status': 'OK', 'strength': 20, 'tablets': 1.5, 'dose_mg': 30.0}),
  ('accuracy outranks tablet count',
   {'target_mg': 21, 'strengths': [10, 7], 'scored': [], 'tol_pct': 6},
   {'status': 'OK', 'strength': 7, 'tablets': 3.0, 'dose_mg': 21.0})],
 [('unscored tablet may not be halved',
   {'target_mg': 15, 'strengths': [30, 75], 'scored': [75], 'tol_pct': 10},
   {'status': 'NO_MATCH'}),
  ('scored tablet half used',
   {'target_mg': '7.5', 'strengths': [5, 10], 'scored': [5], 'tol_pct': 7},
   {'status': 'OK', 'strength': 5, 'tablets': 1.5, 'dose_mg': 7.5}),
  ('near dose rounds up to whole tablet',
   {'target_mg': 14, 'strengths': [5], 'scored': [], 'tol_pct': 12},
   {'status': 'OK', 'strength': 5, 'tablets': 3.0, 'dose_mg': 15.0}),
  ('near dose rounds down to whole tablet',
   {'target_mg': 11, 'strengths': [5], 'scored': [], 'tol_pct': 12},
   {'status': 'OK', 'strength': 5, 'tablets': 2.0, 'dose_mg': 10.0}),
  ('three and a half tablets allowed',
   {'target_mg': 35, 'strengths': [10], 'scored': [10], 'tol_pct': 2},
   {'status': 'OK', 'strength': 10, 'tablets': 3.5, 'dose_mg': 35.0}),
  ('exactly four tablets allowed',
   {'target_mg': 40, 'strengths': [10], 'scored': [], 'tol_pct': 2},
   {'status': 'OK', 'strength': 10, 'tablets': 4.0, 'dose_mg': 40.0}),
  ('tolerance measured against target',
   {'target_mg': 200, 'strengths': [150], 'scored': [], 'tol_pct': 28},
   {'status': 'OK', 'strength': 150, 'tablets': 1.0, 'dose_mg': 150.0}),
  ('equal error prefers larger strength',
   {'target_mg': 30, 'strengths': [15, 20], 'scored': [20], 'tol_pct': 2},
   {'status': 'OK', 'strength': 20, 'tablets': 1.5, 'dose_mg': 30.0}),
  ('accuracy outranks tablet count',
   {'target_mg': 21, 'strengths': [10, 7], 'scored': [], 'tol_pct': 7},
   {'status': 'OK', 'strength': 7, 'tablets': 3.0, 'dose_mg': 21.0})],
 [('unscored tablet may not be halved',
   {'target_mg': 25, 'strengths': [50, 125], 'scored': [125], 'tol_pct': 10},
   {'status': 'NO_MATCH'}),
  ('scored tablet half used',
   {'target_mg': '7.5', 'strengths': [5, 10], 'scored': [5], 'tol_pct': 8},
   {'status': 'OK', 'strength': 5, 'tablets': 1.5, 'dose_mg': 7.5}),
  ('near dose rounds up to whole tablet',
   {'target_mg': 14, 'strengths': [5], 'scored': [], 'tol_pct': 13},
   {'status': 'OK', 'strength': 5, 'tablets': 3.0, 'dose_mg': 15.0}),
  ('near dose rounds down to whole tablet',
   {'target_mg': 11, 'strengths': [5], 'scored': [], 'tol_pct': 13},
   {'status': 'OK', 'strength': 5, 'tablets': 2.0, 'dose_mg': 10.0}),
  ('three and a half tablets allowed',
   {'target_mg': 35, 'strengths': [10], 'scored': [10], 'tol_pct': 3},
   {'status': 'OK', 'strength': 10, 'tablets': 3.5, 'dose_mg': 35.0}),
  ('exactly four tablets allowed',
   {'target_mg': 40, 'strengths': [10], 'scored': [], 'tol_pct': 3},
   {'status': 'OK', 'strength': 10, 'tablets': 4.0, 'dose_mg': 40.0}),
  ('tolerance measured against target',
   {'target_mg': 200, 'strengths': [150], 'scored': [], 'tol_pct': 29},
   {'status': 'OK', 'strength': 150, 'tablets': 1.0, 'dose_mg': 150.0}),
  ('equal error prefers larger strength',
   {'target_mg': 30, 'strengths': [15, 20], 'scored': [20], 'tol_pct': 3},
   {'status': 'OK', 'strength': 20, 'tablets': 1.5, 'dose_mg': 30.0}),
  ('accuracy outranks tablet count',
   {'target_mg': 21, 'strengths': [10, 7], 'scored': [], 'tol_pct': 8},
   {'status': 'OK', 'strength': 7, 'tablets': 3.0, 'dose_mg': 21.0})],
 [('unscored tablet may not be halved',
   {'target_mg': 35, 'strengths': [70, 175], 'scored': [175], 'tol_pct': 10},
   {'status': 'NO_MATCH'}),
  ('scored tablet half used',
   {'target_mg': '7.5', 'strengths': [5, 10], 'scored': [5], 'tol_pct': 9},
   {'status': 'OK', 'strength': 5, 'tablets': 1.5, 'dose_mg': 7.5}),
  ('near dose rounds up to whole tablet',
   {'target_mg': 14, 'strengths': [5], 'scored': [], 'tol_pct': 14},
   {'status': 'OK', 'strength': 5, 'tablets': 3.0, 'dose_mg': 15.0}),
  ('near dose rounds down to whole tablet',
   {'target_mg': 11, 'strengths': [5], 'scored': [], 'tol_pct': 14},
   {'status': 'OK', 'strength': 5, 'tablets': 2.0, 'dose_mg': 10.0}),
  ('three and a half tablets allowed',
   {'target_mg': 35, 'strengths': [10], 'scored': [10], 'tol_pct': 4},
   {'status': 'OK', 'strength': 10, 'tablets': 3.5, 'dose_mg': 35.0}),
  ('exactly four tablets allowed',
   {'target_mg': 40, 'strengths': [10], 'scored': [], 'tol_pct': 4},
   {'status': 'OK', 'strength': 10, 'tablets': 4.0, 'dose_mg': 40.0}),
  ('tolerance measured against target',
   {'target_mg': 200, 'strengths': [150], 'scored': [], 'tol_pct': 30},
   {'status': 'OK', 'strength': 150, 'tablets': 1.0, 'dose_mg': 150.0}),
  ('equal error prefers larger strength',
   {'target_mg': 30, 'strengths': [15, 20], 'scored': [20], 'tol_pct': 4},
   {'status': 'OK', 'strength': 20, 'tablets': 1.5, 'dose_mg': 30.0}),
  ('accuracy outranks tablet count',
   {'target_mg': 21, 'strengths': [10, 7], 'scored': [], 'tol_pct': 9},
   {'status': 'OK', 'strength': 7, 'tablets': 3.0, 'dose_mg': 21.0})],
 [('unscored tablet may not be halved',
   {'target_mg': 45, 'strengths': [90, 225], 'scored': [225], 'tol_pct': 10},
   {'status': 'NO_MATCH'}),
  ('scored tablet half used',
   {'target_mg': '7.5', 'strengths': [5, 10], 'scored': [5], 'tol_pct': 10},
   {'status': 'OK', 'strength': 5, 'tablets': 1.5, 'dose_mg': 7.5}),
  ('near dose rounds up to whole tablet',
   {'target_mg': 14, 'strengths': [5], 'scored': [], 'tol_pct': 15},
   {'status': 'OK', 'strength': 5, 'tablets': 3.0, 'dose_mg': 15.0}),
  ('near dose rounds down to whole tablet',
   {'target_mg': 11, 'strengths': [5], 'scored': [], 'tol_pct': 15},
   {'status': 'OK', 'strength': 5, 'tablets': 2.0, 'dose_mg': 10.0}),
  ('three and a half tablets allowed',
   {'target_mg': 35, 'strengths': [10], 'scored': [10], 'tol_pct': 5},
   {'status': 'OK', 'strength': 10, 'tablets': 3.5, 'dose_mg': 35.0}),
  ('exactly four tablets allowed',
   {'target_mg': 40, 'strengths': [10], 'scored': [], 'tol_pct': 5},
   {'status': 'OK', 'strength': 10, 'tablets': 4.0, 'dose_mg': 40.0}),
  ('tolerance measured against target',
   {'target_mg': 200, 'strengths': [150], 'scored': [], 'tol_pct': 31},
   {'status': 'OK', 'strength': 150, 'tablets': 1.0, 'dose_mg': 150.0}),
  ('equal error prefers larger strength',
   {'target_mg': 30, 'strengths': [15, 20], 'scored': [20], 'tol_pct': 5},
   {'status': 'OK', 'strength': 20, 'tablets': 1.5, 'dose_mg': 30.0}),
  ('accuracy outranks tablet count',
   {'target_mg': 21, 'strengths': [10, 7], 'scored': [], 'tol_pct': 10},
   {'status': 'OK', 'strength': 7, 'tablets': 3.0, 'dose_mg': 21.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):
    target = Fraction(str(x['target_mg']))
    best = None
    for s in sorted(x['strengths']):
        step = Fraction(s, 2) if x['scored'] else Fraction(s)
        units = math.floor(target / step + Fraction(1, 2))
        if units == 0:
            continue
        dose = units * step
        tabs = dose / s
        if tabs > 4:
            continue
        if abs(dose - target) * 100 > x['tol_pct'] * target:
            continue
        key = (abs(dose - target), math.ceil(tabs), -s)
        if best is None or key < best[0]:
            best = (key, s, tabs, dose)
    if best is None:
        return {'status': 'NO_MATCH'}
    return {'status': 'OK', 'strength': best[1], 'tablets': float(best[2]), 'dose_mg': float(best[3])}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('unscored tablet may not be halved',
   {'target_mg': 5, 'strengths': [10, 25], 'scored': [25], 'tol_pct': 10},
   {'status': 'NO_MATCH'}),
  ('scored tablet half used',
   {'target_mg': '7.5', 'strengths': [5, 10], 'scored': [5], 'tol_pct': 6},
   {'status': 'OK', 'strength': 5, 'tablets': 1.5, 'dose_mg': 7.5}),
  ('near dose rounds up to whole tablet',
   {'target_mg': 14, 'strengths': [5], 'scored': [], 'tol_pct': 11},
   {'status': 'OK', 'strength': 5, 'tablets': 3.0, 'dose_mg': 15.0}),
  ('near dose rounds down to whole tablet',
   {'target_mg': 11, 'strengths': [5], 'scored': [], 'tol_pct': 11},
   {'status': 'OK', 'strength': 5, 'tablets': 2.0, 'dose_mg': 10.0}),
  ('three and a half tablets allowed',
   {'target_mg': 35, 'strengths': [10], 'scored': [10], 'tol_pct': 1},
   {'status': 'OK', 'strength': 10, 'tablets': 3.5, 'dose_mg': 35.0}),
  ('exactly four tablets allowed',
   {'target_mg': 40, 'strengths': [10], 'scored': [], 'tol_pct': 1},
   {'status': 'OK', 'strength': 10, 'tablets': 4.0, 'dose_mg': 40.0}),
  ('tolerance measured against target',
   {'target_mg': 200, 'strengths': [150], 'scored': [], 'tol_pct': 27},
   {'status': 'OK', 'strength': 150, 'tablets': 1.0, 'dose_mg': 150.0}),
  ('equal error prefers larger strength',
   {'target_mg': 30, 'strengths': [15, 20], 'scored': [20], 'tol_pct': 1},
   {'status': 'OK', 'strength': 20, 'tablets': 1.5, 'dose_mg': 30.0}),
  ('accuracy outranks tablet count',
   {'target_mg': 21, 'strengths': [10, 7], 'scored': [], 'tol_pct': 6},
   {'status': 'OK', 'strength': 7, 'tablets': 3.0, 'dose_mg': 21.0})],
 [('unscored tablet may not be halved',
   {'target_mg': 15, 'strengths': [30, 75], 'scored': [75], 'tol_pct': 10},
   {'status': 'NO_MATCH'}),
  ('scored tablet half used',
   {'target_mg': '7.5', 'strengths': [5, 10], 'scored': [5], 'tol_pct': 7},
   {'status': 'OK', 'strength': 5, 'tablets': 1.5, 'dose_mg': 7.5}),
  ('near dose rounds up to whole tablet',
   {'target_mg': 14, 'strengths': [5], 'scored': [], 'tol_pct': 12},
   {'status': 'OK', 'strength': 5, 'tablets': 3.0, 'dose_mg': 15.0}),
  ('near dose rounds down to whole tablet',
   {'target_mg': 11, 'strengths': [5], 'scored': [], 'tol_pct': 12},
   {'status': 'OK', 'strength': 5, 'tablets': 2.0, 'dose_mg': 10.0}),
  ('three and a half tablets allowed',
   {'target_mg': 35, 'strengths': [10], 'scored': [10], 'tol_pct': 2},
   {'status': 'OK', 'strength': 10, 'tablets': 3.5, 'dose_mg': 35.0}),
  ('exactly four tablets allowed',
   {'target_mg': 40, 'strengths': [10], 'scored': [], 'tol_pct': 2},
   {'status': 'OK', 'strength': 10, 'tablets': 4.0, 'dose_mg': 40.0}),
  ('tolerance measured against target',
   {'target_mg': 200, 'strengths': [150], 'scored': [], 'tol_pct': 28},
   {'status': 'OK', 'strength': 150, 'tablets': 1.0, 'dose_mg': 150.0}),
  ('equal error prefers larger strength',
   {'target_mg': 30, 'strengths': [15, 20], 'scored': [20], 'tol_pct': 2},
   {'status': 'OK', 'strength': 20, 'tablets': 1.5, 'dose_mg': 30.0}),
  ('accuracy outranks tablet count',
   {'target_mg': 21, 'strengths': [10, 7], 'scored': [], 'tol_pct': 7},
   {'status': 'OK', 'strength': 7, 'tablets': 3.0, 'dose_mg': 21.0})],
 [('unscored tablet may not be halved',
   {'target_mg': 25, 'strengths': [50, 125], 'scored': [125], 'tol_pct': 10},
   {'status': 'NO_MATCH'}),
  ('scored tablet half used',
   {'target_mg': '7.5', 'strengths': [5, 10], 'scored': [5], 'tol_pct': 8},
   {'status': 'OK', 'strength': 5, 'tablets': 1.5, 'dose_mg': 7.5}),
  ('near dose rounds up to whole tablet',
   {'target_mg': 14, 'strengths': [5], 'scored': [], 'tol_pct': 13},
   {'status': 'OK', 'strength': 5, 'tablets': 3.0, 'dose_mg': 15.0}),
  ('near dose rounds down to whole tablet',
   {'target_mg': 11, 'strengths': [5], 'scored': [], 'tol_pct': 13},
   {'status': 'OK', 'strength': 5, 'tablets': 2.0, 'dose_mg': 10.0}),
  ('three and a half tablets allowed',
   {'target_mg': 35, 'strengths': [10], 'scored': [10], 'tol_pct': 3},
   {'status': 'OK', 'strength': 10, 'tablets': 3.5, 'dose_mg': 35.0}),
  ('exactly four tablets allowed',
   {'target_mg': 40, 'strengths': [10], 'scored': [], 'tol_pct': 3},
   {'status': 'OK', 'strength': 10, 'tablets': 4.0, 'dose_mg': 40.0}),
  ('tolerance measured against target',
   {'target_mg': 200, 'strengths': [150], 'scored': [], 'tol_pct': 29},
   {'status': 'OK', 'strength': 150, 'tablets': 1.0, 'dose_mg': 150.0}),
  ('equal error prefers larger strength',
   {'target_mg': 30, 'strengths': [15, 20], 'scored': [20], 'tol_pct': 3},
   {'status': 'OK', 'strength': 20, 'tablets': 1.5, 'dose_mg': 30.0}),
  ('accuracy outranks tablet count',
   {'target_mg': 21, 'strengths': [10, 7], 'scored': [], 'tol_pct': 8},
   {'status': 'OK', 'strength': 7, 'tablets': 3.0, 'dose_mg': 21.0})],
 [('unscored tablet may not be halved',
   {'target_mg': 35, 'strengths': [70, 175], 'scored': [175], 'tol_pct': 10},
   {'status': 'NO_MATCH'}),
  ('scored tablet half used',
   {'target_mg': '7.5', 'strengths': [5, 10], 'scored': [5], 'tol_pct': 9},
   {'status': 'OK', 'strength': 5, 'tablets': 1.5, 'dose_mg': 7.5}),
  ('near dose rounds up to whole tablet',
   {'target_mg': 14, 'strengths': [5], 'scored': [], 'tol_pct': 14},
   {'status': 'OK', 'strength': 5, 'tablets': 3.0, 'dose_mg': 15.0}),
  ('near dose rounds down to whole tablet',
   {'target_mg': 11, 'strengths': [5], 'scored': [], 'tol_pct': 14},
   {'status': 'OK', 'strength': 5, 'tablets': 2.0, 'dose_mg': 10.0}),
  ('three and a half tablets allowed',
   {'target_mg': 35, 'strengths': [10], 'scored': [10], 'tol_pct': 4},
   {'status': 'OK', 'strength': 10, 'tablets': 3.5, 'dose_mg': 35.0}),
  ('exactly four tablets allowed',
   {'target_mg': 40, 'strengths': [10], 'scored': [], 'tol_pct': 4},
   {'status': 'OK', 'strength': 10, 'tablets': 4.0, 'dose_mg': 40.0}),
  ('tolerance measured against target',
   {'target_mg': 200, 'strengths': [150], 'scored': [], 'tol_pct': 30},
   {'status': 'OK', 'strength': 150, 'tablets': 1.0, 'dose_mg': 150.0}),
  ('equal error prefers larger strength',
   {'target_mg': 30, 'strengths': [15, 20], 'scored': [20], 'tol_pct': 4},
   {'status': 'OK', 'strength': 20, 'tablets': 1.5, 'dose_mg': 30.0}),
  ('accuracy outranks tablet count',
   {'target_mg': 21, 'strengths': [10, 7], 'scored': [], 'tol_pct': 9},
   {'status': 'OK', 'strength': 7, 'tablets': 3.0, 'dose_mg': 21.0})],
 [('unscored tablet may not be halved',
   {'target_mg': 45, 'strengths': [90, 225], 'scored': [225], 'tol_pct': 10},
   {'status': 'NO_MATCH'}),
  ('scored tablet half used',
   {'target_mg': '7.5', 'strengths': [5, 10], 'scored': [5], 'tol_pct': 10},
   {'status': 'OK', 'strength': 5, 'tablets': 1.5, 'dose_mg': 7.5}),
  ('near dose rounds up to whole tablet',
   {'target_mg': 14, 'strengths': [5], 'scored': [], 'tol_pct': 15},
   {'status': 'OK', 'strength': 5, 'tablets': 3.0, 'dose_mg': 15.0}),
  ('near dose rounds down to whole tablet',
   {'target_mg': 11, 'strengths': [5], 'scored': [], 'tol_pct': 15},
   {'status': 'OK', 'strength': 5, 'tablets': 2.0, 'dose_mg': 10.0}),
  ('three and a half tablets allowed',
   {'target_mg': 35, 'strengths': [10], 'scored': [10], 'tol_pct': 5},
   {'status': 'OK', 'strength': 10, 'tablets': 3.5, 'dose_mg': 35.0}),
  ('exactly four tablets allowed',
   {'target_mg': 40, 'strengths': [10], 'scored': [], 'tol_pct': 5},
   {'status': 'OK', 'strength': 10, 'tablets': 4.0, 'dose_mg': 40.0}),
  ('tolerance measured against target',
   {'target_mg': 200, 'strengths': [150], 'scored': [], 'tol_pct': 31},
   {'status': 'OK', 'strength': 150, 'tablets': 1.0, 'dose_mg': 150.0}),
  ('equal error prefers larger strength',
   {'target_mg': 30, 'strengths': [15, 20], 'scored': [20], 'tol_pct': 5},
   {'status': 'OK', 'strength': 20, 'tablets': 1.5, 'dose_mg': 30.0}),
  ('accuracy outranks tablet count',
   {'target_mg': 21, 'strengths': [10, 7], 'scored': [], 'tol_pct': 10},
   {'status': 'OK', 'strength': 7, 'tablets': 3.0, 'dose_mg': 21.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:
Half of an unscored tablet is dispensed.

Input {target_mg, strengths, scored (strengths that may be halved), tol_pct}. For each strength s: step = s/2 if s is scored else s; units = target/step rounded half-up (skip if 0); dose = units*step; tablets = dose/s (skip if more than 4 tablets); keep only |dose-target|*100 <= tol_pct*target. Prefer smallest absolute error, then fewest physical tablets (ceil of tablets), then the largest strength. Return {status OK, strength, tablets, dose_mg} or {status NO_MATCH}.

split: open-access