broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    if x['weight_kg'] is None:
        return {'flag': 'NO_WEIGHT'}
    dose = Fraction(str(x['dose_mg']))
    if dose > x['abs_max_mg']:
        return {'flag': 'OVER_ABSOLUTE'}
    lo, hi = x['range']
    if x['age_days'] < 28 and x.get('neonatal_range'):
        lo, hi = x['neonatal_range']
    per_kg = dose / Fraction(str(x['weight_kg']))
    if per_kg * 10 < Fraction(str(lo)) * 9:
        flag = 'UNDER'
    elif per_kg > Fraction(str(hi)):
        flag = 'OVER'
    else:
        flag = 'OK'
    return {'flag': flag, 'mg_per_kg': round(float(per_kg), 2)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('within range control',
   {'dose_mg': 310, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 15.5}),
  ('neonate on day 27',
   {'dose_mg': 13,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 4.33}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 13,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 4.33}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 91,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 91, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.1}),
  ('clear underdose',
   {'dose_mg': 79, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.9}),
  ('overdose tolerance edge',
   {'dose_mg': 242, 'weight_kg': 11, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 65, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 15.38}),
  ('absolute maximum',
   {'dose_mg': 1060, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 100, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})],
 [('within range control',
   {'dose_mg': 320, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 16.0}),
  ('neonate on day 27',
   {'dose_mg': 14,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 4.67}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 14,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 4.67}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 92,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 92, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.2}),
  ('clear underdose',
   {'dose_mg': 78, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.8}),
  ('overdose tolerance edge',
   {'dose_mg': 264, 'weight_kg': 12, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 70, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 14.29}),
  ('absolute maximum',
   {'dose_mg': 1070, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 200, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})],
 [('within range control',
   {'dose_mg': 330, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 16.5}),
  ('neonate on day 27',
   {'dose_mg': 15,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 5.0}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 15,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 5.0}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 93,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 93, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.3}),
  ('clear underdose',
   {'dose_mg': 77, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.7}),
  ('overdose tolerance edge',
   {'dose_mg': 286, 'weight_kg': 13, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 75, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 13.33}),
  ('absolute maximum',
   {'dose_mg': 1080, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 300, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})],
 [('within range control',
   {'dose_mg': 340, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 17.0}),
  ('neonate on day 27',
   {'dose_mg': 16,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 5.33}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 16,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 5.33}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 94,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 94, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.4}),
  ('clear underdose',
   {'dose_mg': 76, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.6}),
  ('overdose tolerance edge',
   {'dose_mg': 308, 'weight_kg': 14, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 80, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 12.5}),
  ('absolute maximum',
   {'dose_mg': 1090, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 400, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})],
 [('within range control',
   {'dose_mg': 350, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 17.5}),
  ('neonate on day 27',
   {'dose_mg': 17,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OVER', 'mg_per_kg': 5.67}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 17,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 5.67}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 95,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 95, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.5}),
  ('clear underdose',
   {'dose_mg': 75, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.5}),
  ('overdose tolerance edge',
   {'dose_mg': 330, 'weight_kg': 15, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 85, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 11.76}),
  ('absolute maximum',
   {'dose_mg': 1100, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 500, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})]]
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):
    if x['weight_kg'] is None:
        return {'flag': 'NO_WEIGHT'}
    dose = Fraction(str(x['dose_mg']))
    if dose > x['abs_max_mg']:
        return {'flag': 'OVER_ABSOLUTE'}
    lo, hi = x['range']
    if x['age_days'] < 28 and x.get('neonatal_range'):
        lo, hi = x['neonatal_range']
    per_kg = dose / Fraction(str(x['weight_kg']))
    if per_kg * 10 < Fraction(str(lo)) * 9:
        flag = 'UNDER'
    elif per_kg * 10 >= Fraction(str(hi)) * 11:
        flag = 'OVER'
    else:
        flag = 'OK'
    return {'flag': flag, 'mg_per_kg': round(float(per_kg), 2)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('within range control',
   {'dose_mg': 310, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 15.5}),
  ('neonate on day 27',
   {'dose_mg': 13,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 4.33}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 13,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 4.33}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 91,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 91, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.1}),
  ('clear underdose',
   {'dose_mg': 79, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.9}),
  ('overdose tolerance edge',
   {'dose_mg': 242, 'weight_kg': 11, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 65, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 15.38}),
  ('absolute maximum',
   {'dose_mg': 1060, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 100, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})],
 [('within range control',
   {'dose_mg': 320, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 16.0}),
  ('neonate on day 27',
   {'dose_mg': 14,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 4.67}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 14,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 4.67}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 92,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 92, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.2}),
  ('clear underdose',
   {'dose_mg': 78, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.8}),
  ('overdose tolerance edge',
   {'dose_mg': 264, 'weight_kg': 12, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 70, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 14.29}),
  ('absolute maximum',
   {'dose_mg': 1070, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 200, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})],
 [('within range control',
   {'dose_mg': 330, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 16.5}),
  ('neonate on day 27',
   {'dose_mg': 15,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 5.0}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 15,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 5.0}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 93,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 93, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.3}),
  ('clear underdose',
   {'dose_mg': 77, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.7}),
  ('overdose tolerance edge',
   {'dose_mg': 286, 'weight_kg': 13, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 75, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 13.33}),
  ('absolute maximum',
   {'dose_mg': 1080, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 300, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})],
 [('within range control',
   {'dose_mg': 340, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 17.0}),
  ('neonate on day 27',
   {'dose_mg': 16,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 5.33}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 16,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 5.33}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 94,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 94, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.4}),
  ('clear underdose',
   {'dose_mg': 76, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.6}),
  ('overdose tolerance edge',
   {'dose_mg': 308, 'weight_kg': 14, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 80, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 12.5}),
  ('absolute maximum',
   {'dose_mg': 1090, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 400, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})],
 [('within range control',
   {'dose_mg': 350, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 17.5}),
  ('neonate on day 27',
   {'dose_mg': 17,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OVER', 'mg_per_kg': 5.67}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 17,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 5.67}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 95,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 95, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.5}),
  ('clear underdose',
   {'dose_mg': 75, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.5}),
  ('overdose tolerance edge',
   {'dose_mg': 330, 'weight_kg': 15, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 85, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 11.76}),
  ('absolute maximum',
   {'dose_mg': 1100, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 500, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})]]
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 dose at 105% of the upper bound is flagged as an overdose.

Input {dose_mg, weight_kg (or null), age_days, range [lo, hi] mg/kg, optional neonatal_range, abs_max_mg}. Missing weight returns NO_WEIGHT. A dose above abs_max_mg returns OVER_ABSOLUTE. Neonates (age_days < 28) use neonatal_range when present. Toy 10% tolerance: UNDER when mg/kg < 0.9*lo, OVER when mg/kg > 1.1*hi, else OK. Return {flag, mg_per_kg (2 dp)}.

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):
    if x['weight_kg'] is None:
        return {'flag': 'NO_WEIGHT'}
    dose = Fraction(str(x['dose_mg']))
    if dose >= x['abs_max_mg']:
        return {'flag': 'OVER_ABSOLUTE'}
    lo, hi = x['range']
    if x['age_days'] < 28 and x.get('neonatal_range'):
        lo, hi = x['neonatal_range']
    per_kg = dose / Fraction(str(x['weight_kg']))
    if per_kg * 10 < Fraction(str(lo)) * 9:
        flag = 'UNDER'
    elif per_kg * 10 > Fraction(str(hi)) * 11:
        flag = 'OVER'
    else:
        flag = 'OK'
    return {'flag': flag, 'mg_per_kg': round(float(per_kg), 2)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('within range control',
   {'dose_mg': 310, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 15.5}),
  ('neonate on day 27',
   {'dose_mg': 13,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 4.33}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 13,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 4.33}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 91,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 91, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.1}),
  ('clear underdose',
   {'dose_mg': 79, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.9}),
  ('overdose tolerance edge',
   {'dose_mg': 242, 'weight_kg': 11, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 65, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 15.38}),
  ('absolute maximum',
   {'dose_mg': 1060, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 100, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})],
 [('within range control',
   {'dose_mg': 320, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 16.0}),
  ('neonate on day 27',
   {'dose_mg': 14,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 4.67}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 14,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 4.67}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 92,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 92, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.2}),
  ('clear underdose',
   {'dose_mg': 78, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.8}),
  ('overdose tolerance edge',
   {'dose_mg': 264, 'weight_kg': 12, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 70, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 14.29}),
  ('absolute maximum',
   {'dose_mg': 1070, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 200, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})],
 [('within range control',
   {'dose_mg': 330, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 16.5}),
  ('neonate on day 27',
   {'dose_mg': 15,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 5.0}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 15,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 5.0}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 93,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 93, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.3}),
  ('clear underdose',
   {'dose_mg': 77, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.7}),
  ('overdose tolerance edge',
   {'dose_mg': 286, 'weight_kg': 13, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 75, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 13.33}),
  ('absolute maximum',
   {'dose_mg': 1080, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 300, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})],
 [('within range control',
   {'dose_mg': 340, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 17.0}),
  ('neonate on day 27',
   {'dose_mg': 16,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 5.33}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 16,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 5.33}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 94,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 94, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.4}),
  ('clear underdose',
   {'dose_mg': 76, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.6}),
  ('overdose tolerance edge',
   {'dose_mg': 308, 'weight_kg': 14, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 80, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 12.5}),
  ('absolute maximum',
   {'dose_mg': 1090, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 400, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})],
 [('within range control',
   {'dose_mg': 350, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 17.5}),
  ('neonate on day 27',
   {'dose_mg': 17,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OVER', 'mg_per_kg': 5.67}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 17,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 5.67}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 95,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 95, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.5}),
  ('clear underdose',
   {'dose_mg': 75, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.5}),
  ('overdose tolerance edge',
   {'dose_mg': 330, 'weight_kg': 15, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 85, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 11.76}),
  ('absolute maximum',
   {'dose_mg': 1100, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 500, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})]]
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):
    if x['weight_kg'] is None:
        return {'flag': 'NO_WEIGHT'}
    dose = Fraction(str(x['dose_mg']))
    if dose > x['abs_max_mg'] * 11 / 10:
        return {'flag': 'OVER_ABSOLUTE'}
    lo, hi = x['range']
    if x['age_days'] < 28 and x.get('neonatal_range'):
        lo, hi = x['neonatal_range']
    per_kg = dose / Fraction(str(x['weight_kg']))
    if per_kg * 10 < Fraction(str(lo)) * 9:
        flag = 'UNDER'
    elif per_kg * 10 > Fraction(str(hi)) * 11:
        flag = 'OVER'
    else:
        flag = 'OK'
    return {'flag': flag, 'mg_per_kg': round(float(per_kg), 2)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('within range control',
   {'dose_mg': 310, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 15.5}),
  ('neonate on day 27',
   {'dose_mg': 13,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 4.33}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 13,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 4.33}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 91,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 91, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.1}),
  ('clear underdose',
   {'dose_mg': 79, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.9}),
  ('overdose tolerance edge',
   {'dose_mg': 242, 'weight_kg': 11, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 65, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 15.38}),
  ('absolute maximum',
   {'dose_mg': 1060, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 100, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})],
 [('within range control',
   {'dose_mg': 320, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 16.0}),
  ('neonate on day 27',
   {'dose_mg': 14,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 4.67}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 14,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 4.67}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 92,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 92, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.2}),
  ('clear underdose',
   {'dose_mg': 78, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.8}),
  ('overdose tolerance edge',
   {'dose_mg': 264, 'weight_kg': 12, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 70, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 14.29}),
  ('absolute maximum',
   {'dose_mg': 1070, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 200, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})],
 [('within range control',
   {'dose_mg': 330, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 16.5}),
  ('neonate on day 27',
   {'dose_mg': 15,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 5.0}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 15,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 5.0}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 93,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 93, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.3}),
  ('clear underdose',
   {'dose_mg': 77, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.7}),
  ('overdose tolerance edge',
   {'dose_mg': 286, 'weight_kg': 13, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 75, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 13.33}),
  ('absolute maximum',
   {'dose_mg': 1080, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 300, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})],
 [('within range control',
   {'dose_mg': 340, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 17.0}),
  ('neonate on day 27',
   {'dose_mg': 16,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 5.33}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 16,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 5.33}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 94,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 94, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.4}),
  ('clear underdose',
   {'dose_mg': 76, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.6}),
  ('overdose tolerance edge',
   {'dose_mg': 308, 'weight_kg': 14, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 80, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 12.5}),
  ('absolute maximum',
   {'dose_mg': 1090, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 400, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})],
 [('within range control',
   {'dose_mg': 350, 'weight_kg': 20, 'age_days': 2000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 17.5}),
  ('neonate on day 27',
   {'dose_mg': 17,
    'weight_kg': 3,
    'age_days': 27,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'OVER', 'mg_per_kg': 5.67}),
  ('infant on day 28 uses standard range',
   {'dose_mg': 17,
    'weight_kg': 3,
    'age_days': 28,
    'range': [10, 20],
    'neonatal_range': [3, 5],
    'abs_max_mg': 100},
   {'flag': 'UNDER', 'mg_per_kg': 5.67}),
  ('older infant ignores neonatal range',
   {'dose_mg': 40,
    'weight_kg': 4,
    'age_days': 95,
    'range': [8, 12],
    'neonatal_range': [2, 4],
    'abs_max_mg': 100},
   {'flag': 'OK', 'mg_per_kg': 10.0}),
  ('underdose within tolerance',
   {'dose_mg': 95, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 9.5}),
  ('clear underdose',
   {'dose_mg': 75, 'weight_kg': 10, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'UNDER', 'mg_per_kg': 7.5}),
  ('overdose tolerance edge',
   {'dose_mg': 330, 'weight_kg': 15, 'age_days': 1000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 22.0}),
  ('dose exactly at absolute maximum',
   {'dose_mg': 1000, 'weight_kg': 85, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OK', 'mg_per_kg': 11.76}),
  ('absolute maximum',
   {'dose_mg': 1100, 'weight_kg': 60, 'age_days': 9000, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'OVER_ABSOLUTE'}),
  ('missing weight',
   {'dose_mg': 100, 'weight_kg': None, 'age_days': 500, 'range': [10, 20], 'abs_max_mg': 1000},
   {'flag': 'NO_WEIGHT'})]]
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 dose exactly at the absolute maximum is rejected.

Input {dose_mg, weight_kg (or null), age_days, range [lo, hi] mg/kg, optional neonatal_range, abs_max_mg}. Missing weight returns NO_WEIGHT. A dose above abs_max_mg returns OVER_ABSOLUTE. Neonates (age_days < 28) use neonatal_range when present. Toy 10% tolerance: UNDER when mg/kg < 0.9*lo, OVER when mg/kg > 1.1*hi, else OK. Return {flag, mg_per_kg (2 dp)}.

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):
    inr = Fraction(str(x['inr']))
    lo, hi = Fraction(str(x['low'])), Fraction(str(x['high']))
    w = Fraction(str(x['weekly_mg']))
    action = 'ADJUST'
    if inr > 5:
        action, w = 'HOLD', w * Fraction(85, 100)
    elif inr > hi:
        w = w * Fraction(90, 100)
    elif inr >= lo:
        action = 'CONTINUE'
    elif inr >= lo - Fraction(1, 2):
        w = w * Fraction(105, 100)
    else:
        w = w * Fraction(110, 100)
    units = math.floor(w * 2 + Fraction(1, 2))
    base, extra = divmod(units, 7)
    plan = [(base + 1) / 2] * extra + [base / 2] * (7 - extra)
    return {'action': action, 'weekly_mg': units / 2, 'plan': plan}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 31, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 26.5, 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 29, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 29.0, 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 31, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 22, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 23.0, 'plan': [3.5, 3.5, 3.5, 3.5, 3.0, 3.0, 3.0]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 26, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 28.5, 'plan': [4.5, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 25, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 26.5, 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '32.5', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 32.5, 'plan': [5.0, 5.0, 4.5, 4.5, 4.5, 4.5, 4.5]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 32, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 27.0, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 3.5, 3.5]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 30, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 32, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 24, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 25.0, 'plan': [4.0, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 27, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 29.5, 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 45, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 47.5, 'plan': [7.0, 7.0, 7.0, 7.0, 6.5, 6.5, 6.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '27.5', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 27.5, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.5]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 33, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 28.0, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 31, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 33, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 26, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 27.5, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.5]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 28, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 65, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 68.5, 'plan': [10.0, 10.0, 10.0, 10.0, 9.5, 9.5, 9.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '31', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 34, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 29.0, 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 32, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 34, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 34.0, 'plan': [5.0, 5.0, 5.0, 5.0, 5.0, 4.5, 4.5]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 28, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 29.5, 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 29, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 85, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 89.5, 'plan': [13.0, 13.0, 13.0, 13.0, 12.5, 12.5, 12.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '22.5', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 22.5, 'plan': [3.5, 3.5, 3.5, 3.0, 3.0, 3.0, 3.0]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 35, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 33, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 35, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 35.0, 'plan': [5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 30, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 31.5, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 30, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 105, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 110.5, 'plan': [16.0, 16.0, 16.0, 16.0, 15.5, 15.5, 15.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '38', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 38.0, 'plan': [5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.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):
    inr = Fraction(str(x['inr']))
    lo, hi = Fraction(str(x['low'])), Fraction(str(x['high']))
    w = Fraction(str(x['weekly_mg']))
    action = 'ADJUST'
    if inr >= hi + 2:
        action, w = 'HOLD', w * Fraction(85, 100)
    elif inr > hi:
        w = w * Fraction(90, 100)
    elif inr >= lo:
        action = 'CONTINUE'
    elif inr >= lo - Fraction(1, 2):
        w = w * Fraction(105, 100)
    else:
        w = w * Fraction(110, 100)
    units = math.floor(w * 2 + Fraction(1, 2))
    base, extra = divmod(units, 7)
    plan = [(base + 1) / 2] * extra + [base / 2] * (7 - extra)
    return {'action': action, 'weekly_mg': units / 2, 'plan': plan}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 31, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 26.5, 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 29, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 29.0, 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 31, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 22, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 23.0, 'plan': [3.5, 3.5, 3.5, 3.5, 3.0, 3.0, 3.0]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 26, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 28.5, 'plan': [4.5, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 25, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 26.5, 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '32.5', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 32.5, 'plan': [5.0, 5.0, 4.5, 4.5, 4.5, 4.5, 4.5]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 32, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 27.0, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 3.5, 3.5]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 30, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 32, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 24, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 25.0, 'plan': [4.0, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 27, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 29.5, 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 45, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 47.5, 'plan': [7.0, 7.0, 7.0, 7.0, 6.5, 6.5, 6.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '27.5', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 27.5, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.5]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 33, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 28.0, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 31, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 33, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 26, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 27.5, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.5]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 28, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 65, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 68.5, 'plan': [10.0, 10.0, 10.0, 10.0, 9.5, 9.5, 9.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '31', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 34, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 29.0, 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 32, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 34, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 34.0, 'plan': [5.0, 5.0, 5.0, 5.0, 5.0, 4.5, 4.5]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 28, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 29.5, 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 29, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 85, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 89.5, 'plan': [13.0, 13.0, 13.0, 13.0, 12.5, 12.5, 12.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '22.5', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 22.5, 'plan': [3.5, 3.5, 3.5, 3.0, 3.0, 3.0, 3.0]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 35, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 33, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 35, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 35.0, 'plan': [5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 30, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 31.5, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 30, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 105, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 110.5, 'plan': [16.0, 16.0, 16.0, 16.0, 15.5, 15.5, 15.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '38', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 38.0, 'plan': [5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.0]})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
An INR of exactly 5.0 is only reduced instead of held.

Input {inr, weekly_mg, low, high}. Toy table: inr >= 5 HOLD and weekly x0.85; high < inr < 5 x0.90; low <= inr <= high CONTINUE unchanged; low-0.5 <= inr < low x1.05; lower x1.10 (ADJUST otherwise). New weekly total rounds half-up to 0.5 mg; the plan spreads it over 7 days in 0.5 mg units as evenly as possible with the larger doses on the first days. Return {action, weekly_mg, plan}.

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):
    inr = Fraction(str(x['inr']))
    lo, hi = Fraction(str(x['low'])), Fraction(str(x['high']))
    w = Fraction(str(x['weekly_mg']))
    action = 'ADJUST'
    if inr >= 5:
        action, w = 'HOLD', w * Fraction(85, 100)
    elif inr > hi:
        w = w * Fraction(90, 100)
    elif inr > lo:
        action = 'CONTINUE'
    elif inr >= lo - Fraction(1, 2):
        w = w * Fraction(105, 100)
    else:
        w = w * Fraction(110, 100)
    units = math.floor(w * 2 + Fraction(1, 2))
    base, extra = divmod(units, 7)
    plan = [(base + 1) / 2] * extra + [base / 2] * (7 - extra)
    return {'action': action, 'weekly_mg': units / 2, 'plan': plan}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 31, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 26.5, 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 29, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 29.0, 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 31, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 22, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 23.0, 'plan': [3.5, 3.5, 3.5, 3.5, 3.0, 3.0, 3.0]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 26, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 28.5, 'plan': [4.5, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 25, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 26.5, 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '32.5', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 32.5, 'plan': [5.0, 5.0, 4.5, 4.5, 4.5, 4.5, 4.5]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 32, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 27.0, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 3.5, 3.5]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 30, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 32, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 24, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 25.0, 'plan': [4.0, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 27, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 29.5, 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 45, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 47.5, 'plan': [7.0, 7.0, 7.0, 7.0, 6.5, 6.5, 6.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '27.5', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 27.5, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.5]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 33, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 28.0, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 31, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 33, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 26, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 27.5, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.5]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 28, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 65, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 68.5, 'plan': [10.0, 10.0, 10.0, 10.0, 9.5, 9.5, 9.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '31', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 34, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 29.0, 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 32, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 34, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 34.0, 'plan': [5.0, 5.0, 5.0, 5.0, 5.0, 4.5, 4.5]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 28, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 29.5, 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 29, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 85, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 89.5, 'plan': [13.0, 13.0, 13.0, 13.0, 12.5, 12.5, 12.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '22.5', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 22.5, 'plan': [3.5, 3.5, 3.5, 3.0, 3.0, 3.0, 3.0]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 35, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 33, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 35, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 35.0, 'plan': [5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 30, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 31.5, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 30, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 105, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 110.5, 'plan': [16.0, 16.0, 16.0, 16.0, 15.5, 15.5, 15.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '38', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 38.0, 'plan': [5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.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):
    inr = Fraction(str(x['inr']))
    lo, hi = Fraction(str(x['low'])), Fraction(str(x['high']))
    w = Fraction(str(x['weekly_mg']))
    action = 'ADJUST'
    if inr >= 5:
        action, w = 'HOLD', w * Fraction(85, 100)
    elif inr > hi:
        w = w * Fraction(90, 100)
    elif inr >= lo and inr < hi:
        action = 'CONTINUE'
    elif inr >= lo - Fraction(1, 2):
        w = w * Fraction(105, 100)
    else:
        w = w * Fraction(110, 100)
    units = math.floor(w * 2 + Fraction(1, 2))
    base, extra = divmod(units, 7)
    plan = [(base + 1) / 2] * extra + [base / 2] * (7 - extra)
    return {'action': action, 'weekly_mg': units / 2, 'plan': plan}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 31, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 26.5, 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 29, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 29.0, 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 31, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 22, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 23.0, 'plan': [3.5, 3.5, 3.5, 3.5, 3.0, 3.0, 3.0]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 26, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 28.5, 'plan': [4.5, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 25, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 26.5, 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '32.5', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 32.5, 'plan': [5.0, 5.0, 4.5, 4.5, 4.5, 4.5, 4.5]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 32, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 27.0, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 3.5, 3.5]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 30, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 32, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 24, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 25.0, 'plan': [4.0, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 27, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 29.5, 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 45, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 47.5, 'plan': [7.0, 7.0, 7.0, 7.0, 6.5, 6.5, 6.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '27.5', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 27.5, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.5]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 33, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 28.0, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 31, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 33, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 26, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 27.5, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.5]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 28, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 65, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 68.5, 'plan': [10.0, 10.0, 10.0, 10.0, 9.5, 9.5, 9.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '31', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 34, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 29.0, 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 32, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 34, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 34.0, 'plan': [5.0, 5.0, 5.0, 5.0, 5.0, 4.5, 4.5]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 28, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 29.5, 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 29, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 85, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 89.5, 'plan': [13.0, 13.0, 13.0, 13.0, 12.5, 12.5, 12.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '22.5', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 22.5, 'plan': [3.5, 3.5, 3.5, 3.0, 3.0, 3.0, 3.0]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 35, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 33, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 35, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 35.0, 'plan': [5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 30, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 31.5, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 30, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 105, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 110.5, 'plan': [16.0, 16.0, 16.0, 16.0, 15.5, 15.5, 15.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '38', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 38.0, 'plan': [5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.0]})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
An INR exactly at the lower target triggers a dose increase.

Input {inr, weekly_mg, low, high}. Toy table: inr >= 5 HOLD and weekly x0.85; high < inr < 5 x0.90; low <= inr <= high CONTINUE unchanged; low-0.5 <= inr < low x1.05; lower x1.10 (ADJUST otherwise). New weekly total rounds half-up to 0.5 mg; the plan spreads it over 7 days in 0.5 mg units as evenly as possible with the larger doses on the first days. Return {action, weekly_mg, plan}.

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):
    inr = Fraction(str(x['inr']))
    lo, hi = Fraction(str(x['low'])), Fraction(str(x['high']))
    w = Fraction(str(x['weekly_mg']))
    action = 'ADJUST'
    if inr >= 5:
        action, w = 'HOLD', w * Fraction(85, 100)
    elif inr > hi:
        w = w * Fraction(90, 100)
    elif inr >= lo:
        action = 'CONTINUE'
    elif inr > lo - Fraction(1, 2):
        w = w * Fraction(105, 100)
    else:
        w = w * Fraction(110, 100)
    units = math.floor(w * 2 + Fraction(1, 2))
    base, extra = divmod(units, 7)
    plan = [(base + 1) / 2] * extra + [base / 2] * (7 - extra)
    return {'action': action, 'weekly_mg': units / 2, 'plan': plan}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 31, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 26.5, 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 29, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 29.0, 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 31, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 22, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 23.0, 'plan': [3.5, 3.5, 3.5, 3.5, 3.0, 3.0, 3.0]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 26, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 28.5, 'plan': [4.5, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 25, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 26.5, 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '32.5', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 32.5, 'plan': [5.0, 5.0, 4.5, 4.5, 4.5, 4.5, 4.5]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 32, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 27.0, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 3.5, 3.5]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 30, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 32, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 24, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 25.0, 'plan': [4.0, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 27, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 29.5, 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 45, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 47.5, 'plan': [7.0, 7.0, 7.0, 7.0, 6.5, 6.5, 6.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '27.5', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 27.5, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.5]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 33, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 28.0, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 31, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 33, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 26, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 27.5, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.5]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 28, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 65, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 68.5, 'plan': [10.0, 10.0, 10.0, 10.0, 9.5, 9.5, 9.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '31', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 34, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 29.0, 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 32, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 34, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 34.0, 'plan': [5.0, 5.0, 5.0, 5.0, 5.0, 4.5, 4.5]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 28, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 29.5, 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 29, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 85, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 89.5, 'plan': [13.0, 13.0, 13.0, 13.0, 12.5, 12.5, 12.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '22.5', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 22.5, 'plan': [3.5, 3.5, 3.5, 3.0, 3.0, 3.0, 3.0]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 35, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 33, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 35, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 35.0, 'plan': [5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 30, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 31.5, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 30, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 105, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 110.5, 'plan': [16.0, 16.0, 16.0, 16.0, 15.5, 15.5, 15.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '38', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 38.0, 'plan': [5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.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):
    inr = Fraction(str(x['inr']))
    lo, hi = Fraction(str(x['low'])), Fraction(str(x['high']))
    w = Fraction(str(x['weekly_mg']))
    action = 'ADJUST'
    if inr >= 5:
        action, w = 'HOLD', w * Fraction(85, 100)
    elif inr > hi:
        w = w * Fraction(90, 100)
    elif inr >= lo:
        action = 'CONTINUE'
    elif inr >= lo * Fraction(1, 2):
        w = w * Fraction(105, 100)
    else:
        w = w * Fraction(110, 100)
    units = math.floor(w * 2 + Fraction(1, 2))
    base, extra = divmod(units, 7)
    plan = [(base + 1) / 2] * extra + [base / 2] * (7 - extra)
    return {'action': action, 'weekly_mg': units / 2, 'plan': plan}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 31, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 26.5, 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 29, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 29.0, 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 31, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 22, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 23.0, 'plan': [3.5, 3.5, 3.5, 3.5, 3.0, 3.0, 3.0]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 26, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 28.5, 'plan': [4.5, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 25, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 26.5, 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '32.5', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 32.5, 'plan': [5.0, 5.0, 4.5, 4.5, 4.5, 4.5, 4.5]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 32, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 27.0, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 3.5, 3.5]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 30, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 32, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 24, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 25.0, 'plan': [4.0, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 27, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 29.5, 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 45, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 47.5, 'plan': [7.0, 7.0, 7.0, 7.0, 6.5, 6.5, 6.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '27.5', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 27.5, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.5]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 33, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 28.0, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 31, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 33, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 26, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 27.5, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.5]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 28, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 65, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 68.5, 'plan': [10.0, 10.0, 10.0, 10.0, 9.5, 9.5, 9.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '31', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 34, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 29.0, 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 32, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 34, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 34.0, 'plan': [5.0, 5.0, 5.0, 5.0, 5.0, 4.5, 4.5]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 28, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 29.5, 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 29, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 85, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 89.5, 'plan': [13.0, 13.0, 13.0, 13.0, 12.5, 12.5, 12.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '22.5', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 22.5, 'plan': [3.5, 3.5, 3.5, 3.0, 3.0, 3.0, 3.0]})],
 [('INR exactly 5 holds',
   {'inr': '5.0', 'weekly_mg': 35, 'low': 2, 'high': 3},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('high target range above 3',
   {'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
   {'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
  ('INR at upper target continues',
   {'inr': '3.5', 'weekly_mg': 33, 'low': '2.5', 'high': '3.5'},
   {'action': 'CONTINUE', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
  ('INR at lower target continues',
   {'inr': '2.0', 'weekly_mg': 35, 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 35.0, 'plan': [5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0]}),
  ('INR exactly half below target',
   {'inr': '1.5', 'weekly_mg': 30, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 31.5, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
  ('INR well below target',
   {'inr': '1.2', 'weekly_mg': 30, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
  ('weekly rounding half-up',
   {'inr': '1.8', 'weekly_mg': 105, 'low': 2, 'high': 3},
   {'action': 'ADJUST', 'weekly_mg': 110.5, 'plan': [16.0, 16.0, 16.0, 16.0, 15.5, 15.5, 15.5]}),
  ('uneven weekly split',
   {'inr': '2.5', 'weekly_mg': '38', 'low': 2, 'high': 3},
   {'action': 'CONTINUE', 'weekly_mg': 38.0, 'plan': [5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.0]})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
An INR exactly 0.5 below target gets the larger 10% increase.

Input {inr, weekly_mg, low, high}. Toy table: inr >= 5 HOLD and weekly x0.85; high < inr < 5 x0.90; low <= inr <= high CONTINUE unchanged; low-0.5 <= inr < low x1.05; lower x1.10 (ADJUST otherwise). New weekly total rounds half-up to 0.5 mg; the plan spreads it over 7 days in 0.5 mg units as evenly as possible with the larger doses on the first days. Return {action, weekly_mg, plan}.

split: open-access