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

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

prompt:
When two bands are equally close, the higher band is dispensed.

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

split: open-access


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

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

prompt:
A calculated 91.5 mg dose without a matching band is reported as 91 mg.

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

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    conc = Fraction(x['vial_mg']) / Fraction(str(x['diluent_ml']))
    vol = Fraction(str(x['dose_mg'])) / conc
    q = 100 if vol <= 1 else 10
    draw = Fraction(math.floor(vol * q + Fraction(1, 2)), q)
    vials = -(-Fraction(str(x['dose_mg'])) // x['vial_mg'])
    waste = vials * x['vial_mg'] - Fraction(str(x['dose_mg'])) if x['single_use'] else 0
    return {'conc_mg_ml': round(float(conc), 4), 'draw_ml': float(draw), 'vials': int(vials), 'waste_mg': float(waste)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('powder displacement dilutes vial',
   {'dose_mg': 450, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 9.0, 'vials': 1, 'waste_mg': 50.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 37, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.74, 'vials': 1, 'waste_mg': 63.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 45, 'vial_mg': 1000, 'diluent_ml': 49, 'displacement_ml': 1, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.3, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 62, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.2, 'vials': 1, 'waste_mg': 38.0}),
  ('dose exactly one vial',
   {'dose_mg': 250, 'vial_mg': 250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 601, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 399.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 31, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 10.0, 'vials': 1, 'waste_mg': 0.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 41, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.82, 'vials': 1, 'waste_mg': 59.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 49, 'vial_mg': 1000, 'diluent_ml': 48, 'displacement_ml': 2, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.5, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 71, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.4, 'vials': 1, 'waste_mg': 29.0}),
  ('dose exactly one vial',
   {'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 100.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 602, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 398.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 32, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.2, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 550, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 11.0, 'vials': 2, 'waste_mg': 450.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 29, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.58, 'vials': 1, 'waste_mg': 71.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 53, 'vial_mg': 1000, 'diluent_ml': 47, 'displacement_ml': 3, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.7, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 81, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.6, 'vials': 1, 'waste_mg': 19.0}),
  ('dose exactly one vial',
   {'dose_mg': 750, 'vial_mg': 750, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 150.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 603, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 397.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.3, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 600, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 400.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.66, 'vials': 1, 'waste_mg': 67.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 57, 'vial_mg': 1000, 'diluent_ml': 46, 'displacement_ml': 4, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.9, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 92, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.8, 'vials': 1, 'waste_mg': 8.0}),
  ('dose exactly one vial',
   {'dose_mg': 1000, 'vial_mg': 1000, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 200.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 604, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 396.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 34, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.4, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 650, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 13.0, 'vials': 2, 'waste_mg': 350.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 47, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.94, 'vials': 1, 'waste_mg': 53.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 61, 'vial_mg': 1000, 'diluent_ml': 45, 'displacement_ml': 5, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 102, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 2.0, 'vials': 2, 'waste_mg': 98.0}),
  ('dose exactly one vial',
   {'dose_mg': 1250, 'vial_mg': 1250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 250.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 605, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 395.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 35, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.5, 'vials': 1, 'waste_mg': 0.0})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    conc = Fraction(x['vial_mg']) / (Fraction(str(x['diluent_ml'])) - Fraction(str(x['displacement_ml'])))
    vol = Fraction(str(x['dose_mg'])) / conc
    q = 100 if vol <= 1 else 10
    draw = Fraction(math.floor(vol * q + Fraction(1, 2)), q)
    vials = -(-Fraction(str(x['dose_mg'])) // x['vial_mg'])
    waste = vials * x['vial_mg'] - Fraction(str(x['dose_mg'])) if x['single_use'] else 0
    return {'conc_mg_ml': round(float(conc), 4), 'draw_ml': float(draw), 'vials': int(vials), 'waste_mg': float(waste)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('powder displacement dilutes vial',
   {'dose_mg': 450, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 9.0, 'vials': 1, 'waste_mg': 50.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 37, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.74, 'vials': 1, 'waste_mg': 63.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 45, 'vial_mg': 1000, 'diluent_ml': 49, 'displacement_ml': 1, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.3, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 62, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.2, 'vials': 1, 'waste_mg': 38.0}),
  ('dose exactly one vial',
   {'dose_mg': 250, 'vial_mg': 250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 601, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 399.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 31, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 10.0, 'vials': 1, 'waste_mg': 0.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 41, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.82, 'vials': 1, 'waste_mg': 59.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 49, 'vial_mg': 1000, 'diluent_ml': 48, 'displacement_ml': 2, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.5, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 71, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.4, 'vials': 1, 'waste_mg': 29.0}),
  ('dose exactly one vial',
   {'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 100.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 602, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 398.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 32, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.2, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 550, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 11.0, 'vials': 2, 'waste_mg': 450.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 29, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.58, 'vials': 1, 'waste_mg': 71.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 53, 'vial_mg': 1000, 'diluent_ml': 47, 'displacement_ml': 3, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.7, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 81, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.6, 'vials': 1, 'waste_mg': 19.0}),
  ('dose exactly one vial',
   {'dose_mg': 750, 'vial_mg': 750, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 150.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 603, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 397.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.3, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 600, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 400.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.66, 'vials': 1, 'waste_mg': 67.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 57, 'vial_mg': 1000, 'diluent_ml': 46, 'displacement_ml': 4, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.9, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 92, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.8, 'vials': 1, 'waste_mg': 8.0}),
  ('dose exactly one vial',
   {'dose_mg': 1000, 'vial_mg': 1000, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 200.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 604, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 396.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 34, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.4, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 650, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 13.0, 'vials': 2, 'waste_mg': 350.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 47, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.94, 'vials': 1, 'waste_mg': 53.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 61, 'vial_mg': 1000, 'diluent_ml': 45, 'displacement_ml': 5, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 102, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 2.0, 'vials': 2, 'waste_mg': 98.0}),
  ('dose exactly one vial',
   {'dose_mg': 1250, 'vial_mg': 1250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 250.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 605, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 395.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 35, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.5, 'vials': 1, 'waste_mg': 0.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:
Draw volumes are slightly short because the concentration is overstated.

Input {dose_mg, vial_mg, diluent_ml, displacement_ml, single_use}. Concentration = vial_mg/(diluent_ml + displacement_ml). Draw volume = dose/concentration, rounded half-up to 0.01 mL when the volume is <= 1 mL, else to 0.1 mL. Vials = ceil(dose/vial_mg). Waste = vials*vial_mg - dose for single-use vials, else 0. Return {conc_mg_ml (4 dp), draw_ml, vials, waste_mg}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    conc = Fraction(x['vial_mg']) / (Fraction(str(x['diluent_ml'])) + Fraction(str(x['displacement_ml'])))
    vol = Fraction(str(x['dose_mg'])) / conc
    q = 10
    draw = Fraction(math.floor(vol * q + Fraction(1, 2)), q)
    vials = -(-Fraction(str(x['dose_mg'])) // x['vial_mg'])
    waste = vials * x['vial_mg'] - Fraction(str(x['dose_mg'])) if x['single_use'] else 0
    return {'conc_mg_ml': round(float(conc), 4), 'draw_ml': float(draw), 'vials': int(vials), 'waste_mg': float(waste)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('powder displacement dilutes vial',
   {'dose_mg': 450, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 9.0, 'vials': 1, 'waste_mg': 50.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 37, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.74, 'vials': 1, 'waste_mg': 63.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 45, 'vial_mg': 1000, 'diluent_ml': 49, 'displacement_ml': 1, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.3, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 62, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.2, 'vials': 1, 'waste_mg': 38.0}),
  ('dose exactly one vial',
   {'dose_mg': 250, 'vial_mg': 250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 601, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 399.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 31, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 10.0, 'vials': 1, 'waste_mg': 0.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 41, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.82, 'vials': 1, 'waste_mg': 59.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 49, 'vial_mg': 1000, 'diluent_ml': 48, 'displacement_ml': 2, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.5, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 71, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.4, 'vials': 1, 'waste_mg': 29.0}),
  ('dose exactly one vial',
   {'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 100.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 602, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 398.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 32, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.2, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 550, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 11.0, 'vials': 2, 'waste_mg': 450.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 29, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.58, 'vials': 1, 'waste_mg': 71.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 53, 'vial_mg': 1000, 'diluent_ml': 47, 'displacement_ml': 3, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.7, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 81, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.6, 'vials': 1, 'waste_mg': 19.0}),
  ('dose exactly one vial',
   {'dose_mg': 750, 'vial_mg': 750, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 150.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 603, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 397.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.3, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 600, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 400.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.66, 'vials': 1, 'waste_mg': 67.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 57, 'vial_mg': 1000, 'diluent_ml': 46, 'displacement_ml': 4, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.9, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 92, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.8, 'vials': 1, 'waste_mg': 8.0}),
  ('dose exactly one vial',
   {'dose_mg': 1000, 'vial_mg': 1000, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 200.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 604, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 396.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 34, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.4, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 650, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 13.0, 'vials': 2, 'waste_mg': 350.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 47, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.94, 'vials': 1, 'waste_mg': 53.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 61, 'vial_mg': 1000, 'diluent_ml': 45, 'displacement_ml': 5, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 102, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 2.0, 'vials': 2, 'waste_mg': 98.0}),
  ('dose exactly one vial',
   {'dose_mg': 1250, 'vial_mg': 1250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 250.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 605, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 395.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 35, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.5, 'vials': 1, 'waste_mg': 0.0})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    conc = Fraction(x['vial_mg']) / (Fraction(str(x['diluent_ml'])) + Fraction(str(x['displacement_ml'])))
    vol = Fraction(str(x['dose_mg'])) / conc
    q = 100 if vol < Fraction(1, 2) else 10
    draw = Fraction(math.floor(vol * q + Fraction(1, 2)), q)
    vials = -(-Fraction(str(x['dose_mg'])) // x['vial_mg'])
    waste = vials * x['vial_mg'] - Fraction(str(x['dose_mg'])) if x['single_use'] else 0
    return {'conc_mg_ml': round(float(conc), 4), 'draw_ml': float(draw), 'vials': int(vials), 'waste_mg': float(waste)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('powder displacement dilutes vial',
   {'dose_mg': 450, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 9.0, 'vials': 1, 'waste_mg': 50.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 37, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.74, 'vials': 1, 'waste_mg': 63.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 45, 'vial_mg': 1000, 'diluent_ml': 49, 'displacement_ml': 1, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.3, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 62, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.2, 'vials': 1, 'waste_mg': 38.0}),
  ('dose exactly one vial',
   {'dose_mg': 250, 'vial_mg': 250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 601, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 399.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 31, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 10.0, 'vials': 1, 'waste_mg': 0.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 41, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.82, 'vials': 1, 'waste_mg': 59.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 49, 'vial_mg': 1000, 'diluent_ml': 48, 'displacement_ml': 2, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.5, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 71, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.4, 'vials': 1, 'waste_mg': 29.0}),
  ('dose exactly one vial',
   {'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 100.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 602, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 398.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 32, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.2, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 550, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 11.0, 'vials': 2, 'waste_mg': 450.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 29, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.58, 'vials': 1, 'waste_mg': 71.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 53, 'vial_mg': 1000, 'diluent_ml': 47, 'displacement_ml': 3, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.7, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 81, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.6, 'vials': 1, 'waste_mg': 19.0}),
  ('dose exactly one vial',
   {'dose_mg': 750, 'vial_mg': 750, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 150.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 603, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 397.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.3, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 600, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 400.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.66, 'vials': 1, 'waste_mg': 67.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 57, 'vial_mg': 1000, 'diluent_ml': 46, 'displacement_ml': 4, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.9, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 92, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.8, 'vials': 1, 'waste_mg': 8.0}),
  ('dose exactly one vial',
   {'dose_mg': 1000, 'vial_mg': 1000, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 200.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 604, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 396.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 34, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.4, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 650, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 13.0, 'vials': 2, 'waste_mg': 350.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 47, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.94, 'vials': 1, 'waste_mg': 53.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 61, 'vial_mg': 1000, 'diluent_ml': 45, 'displacement_ml': 5, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 102, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 2.0, 'vials': 2, 'waste_mg': 98.0}),
  ('dose exactly one vial',
   {'dose_mg': 1250, 'vial_mg': 1250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 250.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 605, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 395.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 35, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.5, 'vials': 1, 'waste_mg': 0.0})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A 0.74 mL draw is rounded to 0.7 mL.

Input {dose_mg, vial_mg, diluent_ml, displacement_ml, single_use}. Concentration = vial_mg/(diluent_ml + displacement_ml). Draw volume = dose/concentration, rounded half-up to 0.01 mL when the volume is <= 1 mL, else to 0.1 mL. Vials = ceil(dose/vial_mg). Waste = vials*vial_mg - dose for single-use vials, else 0. Return {conc_mg_ml (4 dp), draw_ml, vials, waste_mg}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    conc = Fraction(x['vial_mg']) / (Fraction(str(x['diluent_ml'])) + Fraction(str(x['displacement_ml'])))
    vol = Fraction(str(x['dose_mg'])) / conc
    q = 100 if vol <= 1 else 10
    draw = Fraction(math.floor(vol * q), q)
    vials = -(-Fraction(str(x['dose_mg'])) // x['vial_mg'])
    waste = vials * x['vial_mg'] - Fraction(str(x['dose_mg'])) if x['single_use'] else 0
    return {'conc_mg_ml': round(float(conc), 4), 'draw_ml': float(draw), 'vials': int(vials), 'waste_mg': float(waste)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('powder displacement dilutes vial',
   {'dose_mg': 450, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 9.0, 'vials': 1, 'waste_mg': 50.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 37, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.74, 'vials': 1, 'waste_mg': 63.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 45, 'vial_mg': 1000, 'diluent_ml': 49, 'displacement_ml': 1, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.3, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 62, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.2, 'vials': 1, 'waste_mg': 38.0}),
  ('dose exactly one vial',
   {'dose_mg': 250, 'vial_mg': 250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 601, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 399.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 31, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 10.0, 'vials': 1, 'waste_mg': 0.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 41, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.82, 'vials': 1, 'waste_mg': 59.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 49, 'vial_mg': 1000, 'diluent_ml': 48, 'displacement_ml': 2, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.5, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 71, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.4, 'vials': 1, 'waste_mg': 29.0}),
  ('dose exactly one vial',
   {'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 100.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 602, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 398.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 32, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.2, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 550, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 11.0, 'vials': 2, 'waste_mg': 450.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 29, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.58, 'vials': 1, 'waste_mg': 71.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 53, 'vial_mg': 1000, 'diluent_ml': 47, 'displacement_ml': 3, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.7, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 81, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.6, 'vials': 1, 'waste_mg': 19.0}),
  ('dose exactly one vial',
   {'dose_mg': 750, 'vial_mg': 750, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 150.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 603, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 397.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.3, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 600, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 400.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.66, 'vials': 1, 'waste_mg': 67.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 57, 'vial_mg': 1000, 'diluent_ml': 46, 'displacement_ml': 4, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.9, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 92, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.8, 'vials': 1, 'waste_mg': 8.0}),
  ('dose exactly one vial',
   {'dose_mg': 1000, 'vial_mg': 1000, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 200.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 604, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 396.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 34, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.4, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 650, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 13.0, 'vials': 2, 'waste_mg': 350.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 47, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.94, 'vials': 1, 'waste_mg': 53.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 61, 'vial_mg': 1000, 'diluent_ml': 45, 'displacement_ml': 5, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 102, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 2.0, 'vials': 2, 'waste_mg': 98.0}),
  ('dose exactly one vial',
   {'dose_mg': 1250, 'vial_mg': 1250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 250.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 605, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 395.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 35, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.5, 'vials': 1, 'waste_mg': 0.0})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    conc = Fraction(x['vial_mg']) / (Fraction(str(x['diluent_ml'])) + Fraction(str(x['displacement_ml'])))
    vol = Fraction(str(x['dose_mg'])) / conc
    q = 100 if vol <= 1 else 10
    draw = Fraction(math.ceil(vol * q), q)
    vials = -(-Fraction(str(x['dose_mg'])) // x['vial_mg'])
    waste = vials * x['vial_mg'] - Fraction(str(x['dose_mg'])) if x['single_use'] else 0
    return {'conc_mg_ml': round(float(conc), 4), 'draw_ml': float(draw), 'vials': int(vials), 'waste_mg': float(waste)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('powder displacement dilutes vial',
   {'dose_mg': 450, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 9.0, 'vials': 1, 'waste_mg': 50.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 37, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.74, 'vials': 1, 'waste_mg': 63.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 45, 'vial_mg': 1000, 'diluent_ml': 49, 'displacement_ml': 1, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.3, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 62, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.2, 'vials': 1, 'waste_mg': 38.0}),
  ('dose exactly one vial',
   {'dose_mg': 250, 'vial_mg': 250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 601, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 399.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 31, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 10.0, 'vials': 1, 'waste_mg': 0.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 41, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.82, 'vials': 1, 'waste_mg': 59.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 49, 'vial_mg': 1000, 'diluent_ml': 48, 'displacement_ml': 2, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.5, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 71, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.4, 'vials': 1, 'waste_mg': 29.0}),
  ('dose exactly one vial',
   {'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 100.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 602, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 398.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 32, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.2, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 550, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 11.0, 'vials': 2, 'waste_mg': 450.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 29, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.58, 'vials': 1, 'waste_mg': 71.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 53, 'vial_mg': 1000, 'diluent_ml': 47, 'displacement_ml': 3, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.7, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 81, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.6, 'vials': 1, 'waste_mg': 19.0}),
  ('dose exactly one vial',
   {'dose_mg': 750, 'vial_mg': 750, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 150.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 603, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 397.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.3, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 600, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 400.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.66, 'vials': 1, 'waste_mg': 67.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 57, 'vial_mg': 1000, 'diluent_ml': 46, 'displacement_ml': 4, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.9, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 92, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.8, 'vials': 1, 'waste_mg': 8.0}),
  ('dose exactly one vial',
   {'dose_mg': 1000, 'vial_mg': 1000, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 200.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 604, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 396.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 34, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.4, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 650, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 13.0, 'vials': 2, 'waste_mg': 350.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 47, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.94, 'vials': 1, 'waste_mg': 53.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 61, 'vial_mg': 1000, 'diluent_ml': 45, 'displacement_ml': 5, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 102, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 2.0, 'vials': 2, 'waste_mg': 98.0}),
  ('dose exactly one vial',
   {'dose_mg': 1250, 'vial_mg': 1250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 250.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 605, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 395.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 35, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.5, 'vials': 1, 'waste_mg': 0.0})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A 2.25 mL requirement is drawn as 2.2 mL.

Input {dose_mg, vial_mg, diluent_ml, displacement_ml, single_use}. Concentration = vial_mg/(diluent_ml + displacement_ml). Draw volume = dose/concentration, rounded half-up to 0.01 mL when the volume is <= 1 mL, else to 0.1 mL. Vials = ceil(dose/vial_mg). Waste = vials*vial_mg - dose for single-use vials, else 0. Return {conc_mg_ml (4 dp), draw_ml, vials, waste_mg}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    conc = Fraction(x['vial_mg']) / (Fraction(str(x['diluent_ml'])) + Fraction(str(x['displacement_ml'])))
    vol = Fraction(str(x['dose_mg'])) / conc
    q = 100 if vol <= 1 else 10
    draw = Fraction(math.floor(vol * q + Fraction(1, 2)), q)
    vials = Fraction(str(x['dose_mg'])) // x['vial_mg']
    waste = vials * x['vial_mg'] - Fraction(str(x['dose_mg'])) if x['single_use'] else 0
    return {'conc_mg_ml': round(float(conc), 4), 'draw_ml': float(draw), 'vials': int(vials), 'waste_mg': float(waste)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('powder displacement dilutes vial',
   {'dose_mg': 450, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 9.0, 'vials': 1, 'waste_mg': 50.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 37, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.74, 'vials': 1, 'waste_mg': 63.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 45, 'vial_mg': 1000, 'diluent_ml': 49, 'displacement_ml': 1, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.3, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 62, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.2, 'vials': 1, 'waste_mg': 38.0}),
  ('dose exactly one vial',
   {'dose_mg': 250, 'vial_mg': 250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 601, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 399.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 31, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 10.0, 'vials': 1, 'waste_mg': 0.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 41, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.82, 'vials': 1, 'waste_mg': 59.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 49, 'vial_mg': 1000, 'diluent_ml': 48, 'displacement_ml': 2, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.5, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 71, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.4, 'vials': 1, 'waste_mg': 29.0}),
  ('dose exactly one vial',
   {'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 100.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 602, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 398.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 32, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.2, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 550, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 11.0, 'vials': 2, 'waste_mg': 450.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 29, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.58, 'vials': 1, 'waste_mg': 71.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 53, 'vial_mg': 1000, 'diluent_ml': 47, 'displacement_ml': 3, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.7, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 81, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.6, 'vials': 1, 'waste_mg': 19.0}),
  ('dose exactly one vial',
   {'dose_mg': 750, 'vial_mg': 750, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 150.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 603, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 397.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.3, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 600, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 400.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.66, 'vials': 1, 'waste_mg': 67.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 57, 'vial_mg': 1000, 'diluent_ml': 46, 'displacement_ml': 4, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.9, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 92, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.8, 'vials': 1, 'waste_mg': 8.0}),
  ('dose exactly one vial',
   {'dose_mg': 1000, 'vial_mg': 1000, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 200.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 604, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 396.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 34, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.4, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 650, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 13.0, 'vials': 2, 'waste_mg': 350.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 47, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.94, 'vials': 1, 'waste_mg': 53.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 61, 'vial_mg': 1000, 'diluent_ml': 45, 'displacement_ml': 5, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 102, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 2.0, 'vials': 2, 'waste_mg': 98.0}),
  ('dose exactly one vial',
   {'dose_mg': 1250, 'vial_mg': 1250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 250.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 605, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 395.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 35, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.5, 'vials': 1, 'waste_mg': 0.0})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    conc = Fraction(x['vial_mg']) / (Fraction(str(x['diluent_ml'])) + Fraction(str(x['displacement_ml'])))
    vol = Fraction(str(x['dose_mg'])) / conc
    q = 100 if vol <= 1 else 10
    draw = Fraction(math.floor(vol * q + Fraction(1, 2)), q)
    vials = Fraction(str(x['dose_mg'])) // x['vial_mg'] + 1
    waste = vials * x['vial_mg'] - Fraction(str(x['dose_mg'])) if x['single_use'] else 0
    return {'conc_mg_ml': round(float(conc), 4), 'draw_ml': float(draw), 'vials': int(vials), 'waste_mg': float(waste)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('powder displacement dilutes vial',
   {'dose_mg': 450, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 9.0, 'vials': 1, 'waste_mg': 50.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 37, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.74, 'vials': 1, 'waste_mg': 63.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 45, 'vial_mg': 1000, 'diluent_ml': 49, 'displacement_ml': 1, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.3, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 62, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.2, 'vials': 1, 'waste_mg': 38.0}),
  ('dose exactly one vial',
   {'dose_mg': 250, 'vial_mg': 250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 601, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 399.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 31, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 10.0, 'vials': 1, 'waste_mg': 0.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 41, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.82, 'vials': 1, 'waste_mg': 59.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 49, 'vial_mg': 1000, 'diluent_ml': 48, 'displacement_ml': 2, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.5, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 71, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.4, 'vials': 1, 'waste_mg': 29.0}),
  ('dose exactly one vial',
   {'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 100.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 602, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 398.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 32, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.2, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 550, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 11.0, 'vials': 2, 'waste_mg': 450.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 29, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.58, 'vials': 1, 'waste_mg': 71.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 53, 'vial_mg': 1000, 'diluent_ml': 47, 'displacement_ml': 3, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.7, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 81, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.6, 'vials': 1, 'waste_mg': 19.0}),
  ('dose exactly one vial',
   {'dose_mg': 750, 'vial_mg': 750, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 150.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 603, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 397.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.3, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 600, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 400.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.66, 'vials': 1, 'waste_mg': 67.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 57, 'vial_mg': 1000, 'diluent_ml': 46, 'displacement_ml': 4, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 2.9, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 92, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 1.8, 'vials': 1, 'waste_mg': 8.0}),
  ('dose exactly one vial',
   {'dose_mg': 1000, 'vial_mg': 1000, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 200.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 604, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 396.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 34, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.4, 'vials': 1, 'waste_mg': 0.0})],
 [('powder displacement dilutes vial',
   {'dose_mg': 650, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 13.0, 'vials': 2, 'waste_mg': 350.0}),
  ('sub-millilitre draw in hundredths',
   {'dose_mg': 47, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 0.94, 'vials': 1, 'waste_mg': 53.0}),
  ('draw volume half step rounds up',
   {'dose_mg': 61, 'vial_mg': 1000, 'diluent_ml': 45, 'displacement_ml': 5, 'single_use': False},
   {'conc_mg_ml': 20.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0}),
  ('draw volume below half step rounds down',
   {'dose_mg': 102, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 2.0, 'vials': 2, 'waste_mg': 98.0}),
  ('dose exactly one vial',
   {'dose_mg': 1250, 'vial_mg': 1250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 250.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
  ('dose spanning two vials',
   {'dose_mg': 605, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
   {'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 395.0}),
  ('multi-use vial has no waste',
   {'dose_mg': 35, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
   {'conc_mg_ml': 10.0, 'draw_ml': 3.5, 'vials': 1, 'waste_mg': 0.0})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A 601 mg dose from 500 mg vials is prepared from one vial.

Input {dose_mg, vial_mg, diluent_ml, displacement_ml, single_use}. Concentration = vial_mg/(diluent_ml + displacement_ml). Draw volume = dose/concentration, rounded half-up to 0.01 mL when the volume is <= 1 mL, else to 0.1 mL. Vials = ceil(dose/vial_mg). Waste = vials*vial_mg - dose for single-use vials, else 0. Return {conc_mg_ml (4 dp), draw_ml, vials, waste_mg}.

split: open-access