broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    k, v = x['kind'], x['value']
    if k == 'pct':
        r = Fraction(str(v)) * 100
    elif k == 'ratio':
        a, b = [Fraction(p.strip()) for p in v.split(':')]
        r = a * 1000 / b
    elif k == 'meq_to_mg':
        r = Fraction(str(v)) * Fraction(str(x['mw'])) / abs(x['valence'])
    elif k == 'mmol_to_meq':
        r = Fraction(str(v)) * abs(x['valence'])
    else:
        return {'error': 'UNKNOWN_KIND'}
    return {'result': round(float(r), 4)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent solution', {'kind': 'pct', 'value': '0.9'}, {'result': 9.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:10000'}, {'result': 0.1}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '2 : 1000'}, {'result': 2.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 10, 'mw': '40.08', 'valence': 2},
   {'result': 200.4}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -1}, {'result': 709.0}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 5, 'valence': -2}, {'result': 10.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 8, 'valence': 1}, {'result': 8.0}),
  ('unknown conversion kind', {'kind': 'mcg', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '5'}, {'result': 50.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:20000'}, {'result': 0.05}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '3 : 1000'}, {'result': 3.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 20, 'mw': '40.08', 'valence': 2},
   {'result': 400.8}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -2}, {'result': 354.5}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 10, 'valence': -2}, {'result': 20.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 9, 'valence': 1}, {'result': 9.0}),
  ('unknown conversion kind', {'kind': 'iu', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '2'}, {'result': 20.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:30000'}, {'result': 0.0333}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '4 : 1000'}, {'result': 4.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 30, 'mw': '40.08', 'valence': 2},
   {'result': 601.2}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -3}, {'result': 236.3333}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 15, 'valence': -2}, {'result': 30.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 10, 'valence': 1}, {'result': 10.0}),
  ('unknown conversion kind', {'kind': 'pct ', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '0.45'}, {'result': 4.5}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:40000'}, {'result': 0.025}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '5 : 1000'}, {'result': 5.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 40, 'mw': '40.08', 'valence': 2},
   {'result': 801.6}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -4}, {'result': 177.25}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 20, 'valence': -2}, {'result': 40.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 11, 'valence': 1}, {'result': 11.0}),
  ('unknown conversion kind', {'kind': 'Ratio', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '10'}, {'result': 100.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:50000'}, {'result': 0.02}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '6 : 1000'}, {'result': 6.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 50, 'mw': '40.08', 'valence': 2},
   {'result': 1002.0}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -5}, {'result': 141.8}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 25, 'valence': -2}, {'result': 50.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 12, 'valence': 1}, {'result': 12.0}),
  ('unknown conversion kind', {'kind': '', 'value': 1}, {'error': 'UNKNOWN_KIND'})]]
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):
    k, v = x['kind'], x['value']
    if k == 'pct':
        r = Fraction(str(v)) / 100
    elif k == 'ratio':
        a, b = [Fraction(p.strip()) for p in v.split(':')]
        r = a * 1000 / b
    elif k == 'meq_to_mg':
        r = Fraction(str(v)) * Fraction(str(x['mw'])) / abs(x['valence'])
    elif k == 'mmol_to_meq':
        r = Fraction(str(v)) * abs(x['valence'])
    else:
        return {'error': 'UNKNOWN_KIND'}
    return {'result': round(float(r), 4)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent solution', {'kind': 'pct', 'value': '0.9'}, {'result': 9.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:10000'}, {'result': 0.1}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '2 : 1000'}, {'result': 2.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 10, 'mw': '40.08', 'valence': 2},
   {'result': 200.4}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -1}, {'result': 709.0}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 5, 'valence': -2}, {'result': 10.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 8, 'valence': 1}, {'result': 8.0}),
  ('unknown conversion kind', {'kind': 'mcg', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '5'}, {'result': 50.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:20000'}, {'result': 0.05}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '3 : 1000'}, {'result': 3.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 20, 'mw': '40.08', 'valence': 2},
   {'result': 400.8}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -2}, {'result': 354.5}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 10, 'valence': -2}, {'result': 20.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 9, 'valence': 1}, {'result': 9.0}),
  ('unknown conversion kind', {'kind': 'iu', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '2'}, {'result': 20.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:30000'}, {'result': 0.0333}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '4 : 1000'}, {'result': 4.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 30, 'mw': '40.08', 'valence': 2},
   {'result': 601.2}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -3}, {'result': 236.3333}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 15, 'valence': -2}, {'result': 30.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 10, 'valence': 1}, {'result': 10.0}),
  ('unknown conversion kind', {'kind': 'pct ', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '0.45'}, {'result': 4.5}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:40000'}, {'result': 0.025}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '5 : 1000'}, {'result': 5.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 40, 'mw': '40.08', 'valence': 2},
   {'result': 801.6}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -4}, {'result': 177.25}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 20, 'valence': -2}, {'result': 40.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 11, 'valence': 1}, {'result': 11.0}),
  ('unknown conversion kind', {'kind': 'Ratio', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '10'}, {'result': 100.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:50000'}, {'result': 0.02}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '6 : 1000'}, {'result': 6.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 50, 'mw': '40.08', 'valence': 2},
   {'result': 1002.0}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -5}, {'result': 141.8}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 25, 'valence': -2}, {'result': 50.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 12, 'valence': 1}, {'result': 12.0}),
  ('unknown conversion kind', {'kind': '', 'value': 1}, {'error': 'UNKNOWN_KIND'})]]
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:
0.9% saline is reported as 90 mg/mL.

Input {kind, value, mw?, valence?}. kind "pct": w/v percent to mg/mL (x10). kind "ratio": "a:b" ratio strength (a g in b mL) to mg/mL = a*1000/b, whitespace around parts allowed. kind "meq_to_mg": mg = mEq*mw/|valence|. kind "mmol_to_meq": mEq = mmol*|valence|. Any other kind returns {error: UNKNOWN_KIND}. Otherwise {result} rounded to 4 decimals.

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):
    k, v = x['kind'], x['value']
    if k == 'pct':
        r = Fraction(str(v)) * 10
    elif k == 'ratio':
        a, b = [Fraction(p.strip()) for p in v.split(':')]
        r = a / b
    elif k == 'meq_to_mg':
        r = Fraction(str(v)) * Fraction(str(x['mw'])) / abs(x['valence'])
    elif k == 'mmol_to_meq':
        r = Fraction(str(v)) * abs(x['valence'])
    else:
        return {'error': 'UNKNOWN_KIND'}
    return {'result': round(float(r), 4)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent solution', {'kind': 'pct', 'value': '0.9'}, {'result': 9.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:10000'}, {'result': 0.1}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '2 : 1000'}, {'result': 2.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 10, 'mw': '40.08', 'valence': 2},
   {'result': 200.4}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -1}, {'result': 709.0}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 5, 'valence': -2}, {'result': 10.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 8, 'valence': 1}, {'result': 8.0}),
  ('unknown conversion kind', {'kind': 'mcg', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '5'}, {'result': 50.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:20000'}, {'result': 0.05}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '3 : 1000'}, {'result': 3.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 20, 'mw': '40.08', 'valence': 2},
   {'result': 400.8}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -2}, {'result': 354.5}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 10, 'valence': -2}, {'result': 20.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 9, 'valence': 1}, {'result': 9.0}),
  ('unknown conversion kind', {'kind': 'iu', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '2'}, {'result': 20.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:30000'}, {'result': 0.0333}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '4 : 1000'}, {'result': 4.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 30, 'mw': '40.08', 'valence': 2},
   {'result': 601.2}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -3}, {'result': 236.3333}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 15, 'valence': -2}, {'result': 30.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 10, 'valence': 1}, {'result': 10.0}),
  ('unknown conversion kind', {'kind': 'pct ', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '0.45'}, {'result': 4.5}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:40000'}, {'result': 0.025}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '5 : 1000'}, {'result': 5.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 40, 'mw': '40.08', 'valence': 2},
   {'result': 801.6}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -4}, {'result': 177.25}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 20, 'valence': -2}, {'result': 40.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 11, 'valence': 1}, {'result': 11.0}),
  ('unknown conversion kind', {'kind': 'Ratio', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '10'}, {'result': 100.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:50000'}, {'result': 0.02}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '6 : 1000'}, {'result': 6.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 50, 'mw': '40.08', 'valence': 2},
   {'result': 1002.0}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -5}, {'result': 141.8}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 25, 'valence': -2}, {'result': 50.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 12, 'valence': 1}, {'result': 12.0}),
  ('unknown conversion kind', {'kind': '', 'value': 1}, {'error': 'UNKNOWN_KIND'})]]
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):
    k, v = x['kind'], x['value']
    if k == 'pct':
        r = Fraction(str(v)) * 10
    elif k == 'ratio':
        a, b = [Fraction(p.strip()) for p in v.split(':')]
        r = 1000 / b
    elif k == 'meq_to_mg':
        r = Fraction(str(v)) * Fraction(str(x['mw'])) / abs(x['valence'])
    elif k == 'mmol_to_meq':
        r = Fraction(str(v)) * abs(x['valence'])
    else:
        return {'error': 'UNKNOWN_KIND'}
    return {'result': round(float(r), 4)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent solution', {'kind': 'pct', 'value': '0.9'}, {'result': 9.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:10000'}, {'result': 0.1}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '2 : 1000'}, {'result': 2.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 10, 'mw': '40.08', 'valence': 2},
   {'result': 200.4}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -1}, {'result': 709.0}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 5, 'valence': -2}, {'result': 10.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 8, 'valence': 1}, {'result': 8.0}),
  ('unknown conversion kind', {'kind': 'mcg', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '5'}, {'result': 50.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:20000'}, {'result': 0.05}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '3 : 1000'}, {'result': 3.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 20, 'mw': '40.08', 'valence': 2},
   {'result': 400.8}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -2}, {'result': 354.5}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 10, 'valence': -2}, {'result': 20.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 9, 'valence': 1}, {'result': 9.0}),
  ('unknown conversion kind', {'kind': 'iu', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '2'}, {'result': 20.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:30000'}, {'result': 0.0333}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '4 : 1000'}, {'result': 4.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 30, 'mw': '40.08', 'valence': 2},
   {'result': 601.2}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -3}, {'result': 236.3333}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 15, 'valence': -2}, {'result': 30.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 10, 'valence': 1}, {'result': 10.0}),
  ('unknown conversion kind', {'kind': 'pct ', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '0.45'}, {'result': 4.5}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:40000'}, {'result': 0.025}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '5 : 1000'}, {'result': 5.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 40, 'mw': '40.08', 'valence': 2},
   {'result': 801.6}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -4}, {'result': 177.25}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 20, 'valence': -2}, {'result': 40.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 11, 'valence': 1}, {'result': 11.0}),
  ('unknown conversion kind', {'kind': 'Ratio', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '10'}, {'result': 100.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:50000'}, {'result': 0.02}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '6 : 1000'}, {'result': 6.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 50, 'mw': '40.08', 'valence': 2},
   {'result': 1002.0}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -5}, {'result': 141.8}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 25, 'valence': -2}, {'result': 50.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 12, 'valence': 1}, {'result': 12.0}),
  ('unknown conversion kind', {'kind': '', 'value': 1}, {'error': 'UNKNOWN_KIND'})]]
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 1:1000 solution is reported as 0.001 mg/mL.

Input {kind, value, mw?, valence?}. kind "pct": w/v percent to mg/mL (x10). kind "ratio": "a:b" ratio strength (a g in b mL) to mg/mL = a*1000/b, whitespace around parts allowed. kind "meq_to_mg": mg = mEq*mw/|valence|. kind "mmol_to_meq": mEq = mmol*|valence|. Any other kind returns {error: UNKNOWN_KIND}. Otherwise {result} rounded to 4 decimals.

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):
    k, v = x['kind'], x['value']
    if k == 'pct':
        r = Fraction(str(v)) * 10
    elif k == 'ratio':
        a, b = [Fraction(p.strip()) for p in v.split(':')]
        r = a * 1000 / b
    elif k == 'meq_to_mg':
        r = Fraction(str(v)) * Fraction(str(x['mw'])) * abs(x['valence'])
    elif k == 'mmol_to_meq':
        r = Fraction(str(v)) * abs(x['valence'])
    else:
        return {'error': 'UNKNOWN_KIND'}
    return {'result': round(float(r), 4)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent solution', {'kind': 'pct', 'value': '0.9'}, {'result': 9.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:10000'}, {'result': 0.1}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '2 : 1000'}, {'result': 2.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 10, 'mw': '40.08', 'valence': 2},
   {'result': 200.4}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -1}, {'result': 709.0}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 5, 'valence': -2}, {'result': 10.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 8, 'valence': 1}, {'result': 8.0}),
  ('unknown conversion kind', {'kind': 'mcg', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '5'}, {'result': 50.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:20000'}, {'result': 0.05}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '3 : 1000'}, {'result': 3.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 20, 'mw': '40.08', 'valence': 2},
   {'result': 400.8}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -2}, {'result': 354.5}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 10, 'valence': -2}, {'result': 20.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 9, 'valence': 1}, {'result': 9.0}),
  ('unknown conversion kind', {'kind': 'iu', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '2'}, {'result': 20.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:30000'}, {'result': 0.0333}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '4 : 1000'}, {'result': 4.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 30, 'mw': '40.08', 'valence': 2},
   {'result': 601.2}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -3}, {'result': 236.3333}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 15, 'valence': -2}, {'result': 30.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 10, 'valence': 1}, {'result': 10.0}),
  ('unknown conversion kind', {'kind': 'pct ', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '0.45'}, {'result': 4.5}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:40000'}, {'result': 0.025}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '5 : 1000'}, {'result': 5.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 40, 'mw': '40.08', 'valence': 2},
   {'result': 801.6}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -4}, {'result': 177.25}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 20, 'valence': -2}, {'result': 40.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 11, 'valence': 1}, {'result': 11.0}),
  ('unknown conversion kind', {'kind': 'Ratio', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '10'}, {'result': 100.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:50000'}, {'result': 0.02}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '6 : 1000'}, {'result': 6.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 50, 'mw': '40.08', 'valence': 2},
   {'result': 1002.0}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -5}, {'result': 141.8}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 25, 'valence': -2}, {'result': 50.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 12, 'valence': 1}, {'result': 12.0}),
  ('unknown conversion kind', {'kind': '', 'value': 1}, {'error': 'UNKNOWN_KIND'})]]
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):
    k, v = x['kind'], x['value']
    if k == 'pct':
        r = Fraction(str(v)) * 10
    elif k == 'ratio':
        a, b = [Fraction(p.strip()) for p in v.split(':')]
        r = a * 1000 / b
    elif k == 'meq_to_mg':
        r = Fraction(str(v)) * Fraction(str(x['mw'])) / x['valence']
    elif k == 'mmol_to_meq':
        r = Fraction(str(v)) * abs(x['valence'])
    else:
        return {'error': 'UNKNOWN_KIND'}
    return {'result': round(float(r), 4)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent solution', {'kind': 'pct', 'value': '0.9'}, {'result': 9.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:10000'}, {'result': 0.1}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '2 : 1000'}, {'result': 2.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 10, 'mw': '40.08', 'valence': 2},
   {'result': 200.4}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -1}, {'result': 709.0}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 5, 'valence': -2}, {'result': 10.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 8, 'valence': 1}, {'result': 8.0}),
  ('unknown conversion kind', {'kind': 'mcg', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '5'}, {'result': 50.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:20000'}, {'result': 0.05}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '3 : 1000'}, {'result': 3.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 20, 'mw': '40.08', 'valence': 2},
   {'result': 400.8}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -2}, {'result': 354.5}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 10, 'valence': -2}, {'result': 20.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 9, 'valence': 1}, {'result': 9.0}),
  ('unknown conversion kind', {'kind': 'iu', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '2'}, {'result': 20.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:30000'}, {'result': 0.0333}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '4 : 1000'}, {'result': 4.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 30, 'mw': '40.08', 'valence': 2},
   {'result': 601.2}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -3}, {'result': 236.3333}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 15, 'valence': -2}, {'result': 30.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 10, 'valence': 1}, {'result': 10.0}),
  ('unknown conversion kind', {'kind': 'pct ', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '0.45'}, {'result': 4.5}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:40000'}, {'result': 0.025}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '5 : 1000'}, {'result': 5.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 40, 'mw': '40.08', 'valence': 2},
   {'result': 801.6}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -4}, {'result': 177.25}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 20, 'valence': -2}, {'result': 40.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 11, 'valence': 1}, {'result': 11.0}),
  ('unknown conversion kind', {'kind': 'Ratio', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '10'}, {'result': 100.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:50000'}, {'result': 0.02}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '6 : 1000'}, {'result': 6.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 50, 'mw': '40.08', 'valence': 2},
   {'result': 1002.0}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -5}, {'result': 141.8}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 25, 'valence': -2}, {'result': 50.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 12, 'valence': 1}, {'result': 12.0}),
  ('unknown conversion kind', {'kind': '', 'value': 1}, {'error': 'UNKNOWN_KIND'})]]
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:
Calcium mEq convert to four times the correct milligram amount.

Input {kind, value, mw?, valence?}. kind "pct": w/v percent to mg/mL (x10). kind "ratio": "a:b" ratio strength (a g in b mL) to mg/mL = a*1000/b, whitespace around parts allowed. kind "meq_to_mg": mg = mEq*mw/|valence|. kind "mmol_to_meq": mEq = mmol*|valence|. Any other kind returns {error: UNKNOWN_KIND}. Otherwise {result} rounded to 4 decimals.

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):
    k, v = x['kind'], x['value']
    if k == 'pct':
        r = Fraction(str(v)) * 10
    elif k == 'ratio':
        a, b = [Fraction(p.strip()) for p in v.split(':')]
        r = a * 1000 / b
    elif k == 'meq_to_mg':
        r = Fraction(str(v)) * Fraction(str(x['mw'])) / abs(x['valence'])
    elif k == 'mmol_to_meq':
        r = Fraction(str(v)) * x['valence']
    else:
        return {'error': 'UNKNOWN_KIND'}
    return {'result': round(float(r), 4)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent solution', {'kind': 'pct', 'value': '0.9'}, {'result': 9.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:10000'}, {'result': 0.1}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '2 : 1000'}, {'result': 2.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 10, 'mw': '40.08', 'valence': 2},
   {'result': 200.4}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -1}, {'result': 709.0}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 5, 'valence': -2}, {'result': 10.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 8, 'valence': 1}, {'result': 8.0}),
  ('unknown conversion kind', {'kind': 'mcg', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '5'}, {'result': 50.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:20000'}, {'result': 0.05}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '3 : 1000'}, {'result': 3.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 20, 'mw': '40.08', 'valence': 2},
   {'result': 400.8}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -2}, {'result': 354.5}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 10, 'valence': -2}, {'result': 20.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 9, 'valence': 1}, {'result': 9.0}),
  ('unknown conversion kind', {'kind': 'iu', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '2'}, {'result': 20.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:30000'}, {'result': 0.0333}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '4 : 1000'}, {'result': 4.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 30, 'mw': '40.08', 'valence': 2},
   {'result': 601.2}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -3}, {'result': 236.3333}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 15, 'valence': -2}, {'result': 30.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 10, 'valence': 1}, {'result': 10.0}),
  ('unknown conversion kind', {'kind': 'pct ', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '0.45'}, {'result': 4.5}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:40000'}, {'result': 0.025}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '5 : 1000'}, {'result': 5.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 40, 'mw': '40.08', 'valence': 2},
   {'result': 801.6}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -4}, {'result': 177.25}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 20, 'valence': -2}, {'result': 40.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 11, 'valence': 1}, {'result': 11.0}),
  ('unknown conversion kind', {'kind': 'Ratio', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '10'}, {'result': 100.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:50000'}, {'result': 0.02}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '6 : 1000'}, {'result': 6.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 50, 'mw': '40.08', 'valence': 2},
   {'result': 1002.0}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -5}, {'result': 141.8}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 25, 'valence': -2}, {'result': 50.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 12, 'valence': 1}, {'result': 12.0}),
  ('unknown conversion kind', {'kind': '', 'value': 1}, {'error': 'UNKNOWN_KIND'})]]
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):
    k, v = x['kind'], x['value']
    if k == 'pct':
        r = Fraction(str(v)) * 10
    elif k == 'ratio':
        a, b = [Fraction(p.strip()) for p in v.split(':')]
        r = a * 1000 / b
    elif k == 'meq_to_mg':
        r = Fraction(str(v)) * Fraction(str(x['mw'])) / abs(x['valence'])
    elif k == 'mmol_to_meq':
        r = Fraction(str(v)) / abs(x['valence'])
    else:
        return {'error': 'UNKNOWN_KIND'}
    return {'result': round(float(r), 4)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent solution', {'kind': 'pct', 'value': '0.9'}, {'result': 9.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:10000'}, {'result': 0.1}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '2 : 1000'}, {'result': 2.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 10, 'mw': '40.08', 'valence': 2},
   {'result': 200.4}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -1}, {'result': 709.0}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 5, 'valence': -2}, {'result': 10.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 8, 'valence': 1}, {'result': 8.0}),
  ('unknown conversion kind', {'kind': 'mcg', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '5'}, {'result': 50.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:20000'}, {'result': 0.05}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '3 : 1000'}, {'result': 3.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 20, 'mw': '40.08', 'valence': 2},
   {'result': 400.8}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -2}, {'result': 354.5}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 10, 'valence': -2}, {'result': 20.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 9, 'valence': 1}, {'result': 9.0}),
  ('unknown conversion kind', {'kind': 'iu', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '2'}, {'result': 20.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:30000'}, {'result': 0.0333}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '4 : 1000'}, {'result': 4.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 30, 'mw': '40.08', 'valence': 2},
   {'result': 601.2}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -3}, {'result': 236.3333}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 15, 'valence': -2}, {'result': 30.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 10, 'valence': 1}, {'result': 10.0}),
  ('unknown conversion kind', {'kind': 'pct ', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '0.45'}, {'result': 4.5}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:40000'}, {'result': 0.025}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '5 : 1000'}, {'result': 5.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 40, 'mw': '40.08', 'valence': 2},
   {'result': 801.6}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -4}, {'result': 177.25}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 20, 'valence': -2}, {'result': 40.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 11, 'valence': 1}, {'result': 11.0}),
  ('unknown conversion kind', {'kind': 'Ratio', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '10'}, {'result': 100.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:50000'}, {'result': 0.02}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '6 : 1000'}, {'result': 6.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 50, 'mw': '40.08', 'valence': 2},
   {'result': 1002.0}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -5}, {'result': 141.8}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 25, 'valence': -2}, {'result': 50.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 12, 'valence': 1}, {'result': 12.0}),
  ('unknown conversion kind', {'kind': '', 'value': 1}, {'error': 'UNKNOWN_KIND'})]]
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:
Phosphate-style divalent anions produce negative mEq amounts.

Input {kind, value, mw?, valence?}. kind "pct": w/v percent to mg/mL (x10). kind "ratio": "a:b" ratio strength (a g in b mL) to mg/mL = a*1000/b, whitespace around parts allowed. kind "meq_to_mg": mg = mEq*mw/|valence|. kind "mmol_to_meq": mEq = mmol*|valence|. Any other kind returns {error: UNKNOWN_KIND}. Otherwise {result} rounded to 4 decimals.

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):
    k, v = x['kind'], x['value']
    if k == 'pct':
        r = Fraction(str(v)) * 10
    elif k == 'ratio':
        a, b = [Fraction(p.strip()) for p in v.split(':')]
        r = a * 1000 / b
    elif k == 'meq_to_mg':
        r = Fraction(str(v)) * Fraction(str(x['mw'])) / abs(x['valence'])
    elif k == 'mmol_to_meq':
        r = Fraction(str(v)) * abs(x['valence'])
    else:
        return {'result': 0.0}
    return {'result': round(float(r), 4)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent solution', {'kind': 'pct', 'value': '0.9'}, {'result': 9.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:10000'}, {'result': 0.1}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '2 : 1000'}, {'result': 2.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 10, 'mw': '40.08', 'valence': 2},
   {'result': 200.4}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -1}, {'result': 709.0}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 5, 'valence': -2}, {'result': 10.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 8, 'valence': 1}, {'result': 8.0}),
  ('unknown conversion kind', {'kind': 'mcg', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '5'}, {'result': 50.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:20000'}, {'result': 0.05}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '3 : 1000'}, {'result': 3.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 20, 'mw': '40.08', 'valence': 2},
   {'result': 400.8}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -2}, {'result': 354.5}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 10, 'valence': -2}, {'result': 20.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 9, 'valence': 1}, {'result': 9.0}),
  ('unknown conversion kind', {'kind': 'iu', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '2'}, {'result': 20.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:30000'}, {'result': 0.0333}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '4 : 1000'}, {'result': 4.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 30, 'mw': '40.08', 'valence': 2},
   {'result': 601.2}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -3}, {'result': 236.3333}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 15, 'valence': -2}, {'result': 30.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 10, 'valence': 1}, {'result': 10.0}),
  ('unknown conversion kind', {'kind': 'pct ', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '0.45'}, {'result': 4.5}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:40000'}, {'result': 0.025}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '5 : 1000'}, {'result': 5.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 40, 'mw': '40.08', 'valence': 2},
   {'result': 801.6}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -4}, {'result': 177.25}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 20, 'valence': -2}, {'result': 40.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 11, 'valence': 1}, {'result': 11.0}),
  ('unknown conversion kind', {'kind': 'Ratio', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '10'}, {'result': 100.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:50000'}, {'result': 0.02}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '6 : 1000'}, {'result': 6.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 50, 'mw': '40.08', 'valence': 2},
   {'result': 1002.0}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -5}, {'result': 141.8}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 25, 'valence': -2}, {'result': 50.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 12, 'valence': 1}, {'result': 12.0}),
  ('unknown conversion kind', {'kind': '', 'value': 1}, {'error': 'UNKNOWN_KIND'})]]
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):
    k, v = x['kind'], x['value']
    if k == 'pct':
        r = Fraction(str(v)) * 10
    elif k == 'ratio':
        a, b = [Fraction(p.strip()) for p in v.split(':')]
        r = a * 1000 / b
    elif k == 'meq_to_mg':
        r = Fraction(str(v)) * Fraction(str(x['mw'])) / abs(x['valence'])
    elif k == 'mmol_to_meq':
        r = Fraction(str(v)) * abs(x['valence'])
    else:
        return {'error': 'UNKNOWN_KIND', 'result': 0.0}
    return {'result': round(float(r), 4)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent solution', {'kind': 'pct', 'value': '0.9'}, {'result': 9.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:10000'}, {'result': 0.1}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '2 : 1000'}, {'result': 2.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 10, 'mw': '40.08', 'valence': 2},
   {'result': 200.4}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -1}, {'result': 709.0}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 5, 'valence': -2}, {'result': 10.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 8, 'valence': 1}, {'result': 8.0}),
  ('unknown conversion kind', {'kind': 'mcg', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '5'}, {'result': 50.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:20000'}, {'result': 0.05}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '3 : 1000'}, {'result': 3.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 20, 'mw': '40.08', 'valence': 2},
   {'result': 400.8}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -2}, {'result': 354.5}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 10, 'valence': -2}, {'result': 20.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 9, 'valence': 1}, {'result': 9.0}),
  ('unknown conversion kind', {'kind': 'iu', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '2'}, {'result': 20.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:30000'}, {'result': 0.0333}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '4 : 1000'}, {'result': 4.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 30, 'mw': '40.08', 'valence': 2},
   {'result': 601.2}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -3}, {'result': 236.3333}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 15, 'valence': -2}, {'result': 30.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 10, 'valence': 1}, {'result': 10.0}),
  ('unknown conversion kind', {'kind': 'pct ', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '0.45'}, {'result': 4.5}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:40000'}, {'result': 0.025}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '5 : 1000'}, {'result': 5.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 40, 'mw': '40.08', 'valence': 2},
   {'result': 801.6}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -4}, {'result': 177.25}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 20, 'valence': -2}, {'result': 40.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 11, 'valence': 1}, {'result': 11.0}),
  ('unknown conversion kind', {'kind': 'Ratio', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '10'}, {'result': 100.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:50000'}, {'result': 0.02}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '6 : 1000'}, {'result': 6.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 50, 'mw': '40.08', 'valence': 2},
   {'result': 1002.0}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -5}, {'result': 141.8}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 25, 'valence': -2}, {'result': 50.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 12, 'valence': 1}, {'result': 12.0}),
  ('unknown conversion kind', {'kind': '', 'value': 1}, {'error': 'UNKNOWN_KIND'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
An unsupported unit silently converts to 0.

Input {kind, value, mw?, valence?}. kind "pct": w/v percent to mg/mL (x10). kind "ratio": "a:b" ratio strength (a g in b mL) to mg/mL = a*1000/b, whitespace around parts allowed. kind "meq_to_mg": mg = mEq*mw/|valence|. kind "mmol_to_meq": mEq = mmol*|valence|. Any other kind returns {error: UNKNOWN_KIND}. Otherwise {result} rounded to 4 decimals.

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):
    dose = min(Fraction(str(x['mg_per_kg'])) * Fraction(str(x['weight_kg'])), x['max_mg'])
    per_ml = Fraction(x['conc_mg'])
    vol = dose / per_ml
    grad = {1: Fraction(1, 100), 5: Fraction(1, 5), 10: Fraction(1, 2)}[x['syringe_ml']]
    v = math.floor(vol / grad + Fraction(1, 2)) * grad
    if v * per_ml > x['max_mg']:
        v = math.floor(vol / grad) * grad
    if v > x['syringe_ml']:
        return {'status': 'SPLIT', 'syringes': math.ceil(v / x['syringe_ml'])}
    return {'status': 'OK', 'volume_ml': float(v), 'dose_mg': float(v * per_ml)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('suspension per 5 mL label',
   {'weight_kg': 13, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 4.0, 'dose_mg': 200.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 9, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 3.8, 'dose_mg': 91.2}),
  ('10 mL syringe graduations',
   {'weight_kg': 21, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 7.5, 'dose_mg': 150.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 195, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 4.5, 'dose_mg': 180.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 39, 'mg_per_kg': 5, 'max_mg': 200, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 200.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.1', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 5, 'max_mg': 1000, 'conc_mg': 10, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 31, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2})],
 [('suspension per 5 mL label',
   {'weight_kg': 14, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 4.0, 'dose_mg': 200.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 10, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 4.2, 'dose_mg': 100.8}),
  ('10 mL syringe graduations',
   {'weight_kg': 22, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 7.5, 'dose_mg': 150.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 215, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 200.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 43, 'mg_per_kg': 5, 'max_mg': 220, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.5, 'dose_mg': 220.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.2', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 10, 'max_mg': 1000, 'conc_mg': 20, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 32, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2})],
 [('suspension per 5 mL label',
   {'weight_kg': 15, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 4.5, 'dose_mg': 225.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 11, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 4.6, 'dose_mg': 110.4}),
  ('10 mL syringe graduations',
   {'weight_kg': 23, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 8.0, 'dose_mg': 160.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 235, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.5, 'dose_mg': 220.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 47, 'mg_per_kg': 5, 'max_mg': 240, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 6.0, 'dose_mg': 240.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.05', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 30, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 34, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 3})],
 [('suspension per 5 mL label',
   {'weight_kg': 16, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 250.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 12, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('10 mL syringe graduations',
   {'weight_kg': 24, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 8.5, 'dose_mg': 170.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 255, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 6.0, 'dose_mg': 240.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 51, 'mg_per_kg': 5, 'max_mg': 260, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 6.5, 'dose_mg': 260.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.15', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 20, 'max_mg': 1000, 'conc_mg': 40, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 36, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 3})],
 [('suspension per 5 mL label',
   {'weight_kg': 17, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 250.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 13, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('10 mL syringe graduations',
   {'weight_kg': 25, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 9.0, 'dose_mg': 180.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 275, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 6.5, 'dose_mg': 260.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 55, 'mg_per_kg': 5, 'max_mg': 280, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 7.0, 'dose_mg': 280.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.12', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 25, 'max_mg': 1000, 'conc_mg': 50, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 37, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 3})]]
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):
    dose = min(Fraction(str(x['mg_per_kg'])) * Fraction(str(x['weight_kg'])), x['max_mg'])
    per_ml = Fraction(x['conc_ml'], x['conc_mg'])
    vol = dose / per_ml
    grad = {1: Fraction(1, 100), 5: Fraction(1, 5), 10: Fraction(1, 2)}[x['syringe_ml']]
    v = math.floor(vol / grad + Fraction(1, 2)) * grad
    if v * per_ml > x['max_mg']:
        v = math.floor(vol / grad) * grad
    if v > x['syringe_ml']:
        return {'status': 'SPLIT', 'syringes': math.ceil(v / x['syringe_ml'])}
    return {'status': 'OK', 'volume_ml': float(v), 'dose_mg': float(v * per_ml)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('suspension per 5 mL label',
   {'weight_kg': 13, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 4.0, 'dose_mg': 200.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 9, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 3.8, 'dose_mg': 91.2}),
  ('10 mL syringe graduations',
   {'weight_kg': 21, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 7.5, 'dose_mg': 150.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 195, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 4.5, 'dose_mg': 180.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 39, 'mg_per_kg': 5, 'max_mg': 200, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 200.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.1', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 5, 'max_mg': 1000, 'conc_mg': 10, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 31, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2})],
 [('suspension per 5 mL label',
   {'weight_kg': 14, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 4.0, 'dose_mg': 200.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 10, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 4.2, 'dose_mg': 100.8}),
  ('10 mL syringe graduations',
   {'weight_kg': 22, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 7.5, 'dose_mg': 150.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 215, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 200.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 43, 'mg_per_kg': 5, 'max_mg': 220, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.5, 'dose_mg': 220.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.2', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 10, 'max_mg': 1000, 'conc_mg': 20, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 32, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2})],
 [('suspension per 5 mL label',
   {'weight_kg': 15, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 4.5, 'dose_mg': 225.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 11, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 4.6, 'dose_mg': 110.4}),
  ('10 mL syringe graduations',
   {'weight_kg': 23, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 8.0, 'dose_mg': 160.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 235, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.5, 'dose_mg': 220.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 47, 'mg_per_kg': 5, 'max_mg': 240, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 6.0, 'dose_mg': 240.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.05', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 30, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 34, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 3})],
 [('suspension per 5 mL label',
   {'weight_kg': 16, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 250.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 12, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('10 mL syringe graduations',
   {'weight_kg': 24, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 8.5, 'dose_mg': 170.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 255, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 6.0, 'dose_mg': 240.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 51, 'mg_per_kg': 5, 'max_mg': 260, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 6.5, 'dose_mg': 260.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.15', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 20, 'max_mg': 1000, 'conc_mg': 40, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 36, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 3})],
 [('suspension per 5 mL label',
   {'weight_kg': 17, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 250.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 13, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('10 mL syringe graduations',
   {'weight_kg': 25, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 9.0, 'dose_mg': 180.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 275, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 6.5, 'dose_mg': 260.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 55, 'mg_per_kg': 5, 'max_mg': 280, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 7.0, 'dose_mg': 280.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.12', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 25, 'max_mg': 1000, 'conc_mg': 50, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 37, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 3})]]
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 250 mg/5 mL suspension yields volumes five times too small.

Input {weight_kg, mg_per_kg, max_mg, conc_mg, conc_ml (label strength conc_mg per conc_ml), syringe_ml (1, 5 or 10)}. dose = min(mg_per_kg*weight, max_mg); volume = dose/(conc_mg/conc_ml). Graduations: 1 mL syringe 0.01 mL, 5 mL syringe 0.2 mL, 10 mL syringe 0.5 mL. Round half-up to the graduation, but if that delivers more than max_mg round down instead. A rounded volume above syringe capacity returns {status SPLIT, syringes = ceil(volume/capacity)}; otherwise {status OK, volume_ml, dose_mg delivered}.

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):
    dose = min(Fraction(str(x['mg_per_kg'])) * Fraction(str(x['weight_kg'])), x['max_mg'])
    per_ml = Fraction(x['conc_mg'], x['conc_ml'])
    vol = dose / per_ml
    grad = {1: Fraction(1, 100), 5: Fraction(1, 5), 10: Fraction(1, 2)}[x['syringe_ml']]
    v = math.floor(vol / grad + Fraction(1, 2)) * grad
    if v > x['max_mg']:
        v = math.floor(vol / grad) * grad
    if v > x['syringe_ml']:
        return {'status': 'SPLIT', 'syringes': math.ceil(v / x['syringe_ml'])}
    return {'status': 'OK', 'volume_ml': float(v), 'dose_mg': float(v * per_ml)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('suspension per 5 mL label',
   {'weight_kg': 13, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 4.0, 'dose_mg': 200.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 9, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 3.8, 'dose_mg': 91.2}),
  ('10 mL syringe graduations',
   {'weight_kg': 21, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 7.5, 'dose_mg': 150.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 195, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 4.5, 'dose_mg': 180.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 39, 'mg_per_kg': 5, 'max_mg': 200, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 200.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.1', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 5, 'max_mg': 1000, 'conc_mg': 10, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 31, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2})],
 [('suspension per 5 mL label',
   {'weight_kg': 14, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 4.0, 'dose_mg': 200.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 10, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 4.2, 'dose_mg': 100.8}),
  ('10 mL syringe graduations',
   {'weight_kg': 22, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 7.5, 'dose_mg': 150.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 215, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 200.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 43, 'mg_per_kg': 5, 'max_mg': 220, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.5, 'dose_mg': 220.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.2', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 10, 'max_mg': 1000, 'conc_mg': 20, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 32, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2})],
 [('suspension per 5 mL label',
   {'weight_kg': 15, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 4.5, 'dose_mg': 225.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 11, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 4.6, 'dose_mg': 110.4}),
  ('10 mL syringe graduations',
   {'weight_kg': 23, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 8.0, 'dose_mg': 160.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 235, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.5, 'dose_mg': 220.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 47, 'mg_per_kg': 5, 'max_mg': 240, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 6.0, 'dose_mg': 240.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.05', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 30, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 34, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 3})],
 [('suspension per 5 mL label',
   {'weight_kg': 16, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 250.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 12, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('10 mL syringe graduations',
   {'weight_kg': 24, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 8.5, 'dose_mg': 170.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 255, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 6.0, 'dose_mg': 240.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 51, 'mg_per_kg': 5, 'max_mg': 260, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 6.5, 'dose_mg': 260.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.15', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 20, 'max_mg': 1000, 'conc_mg': 40, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 36, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 3})],
 [('suspension per 5 mL label',
   {'weight_kg': 17, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 250.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 13, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('10 mL syringe graduations',
   {'weight_kg': 25, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 9.0, 'dose_mg': 180.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 275, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 6.5, 'dose_mg': 260.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 55, 'mg_per_kg': 5, 'max_mg': 280, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 7.0, 'dose_mg': 280.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.12', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 25, 'max_mg': 1000, 'conc_mg': 50, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 37, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 3})]]
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):
    dose = min(Fraction(str(x['mg_per_kg'])) * Fraction(str(x['weight_kg'])), x['max_mg'])
    per_ml = Fraction(x['conc_mg'], x['conc_ml'])
    vol = dose / per_ml
    grad = {1: Fraction(1, 100), 5: Fraction(1, 5), 10: Fraction(1, 2)}[x['syringe_ml']]
    v = math.floor(vol / grad + Fraction(1, 2)) * grad
    if v * per_ml >= x['max_mg']:
        v = math.floor(vol / grad) * grad
    if v > x['syringe_ml']:
        return {'status': 'SPLIT', 'syringes': math.ceil(v / x['syringe_ml'])}
    return {'status': 'OK', 'volume_ml': float(v), 'dose_mg': float(v * per_ml)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('suspension per 5 mL label',
   {'weight_kg': 13, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 4.0, 'dose_mg': 200.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 9, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 3.8, 'dose_mg': 91.2}),
  ('10 mL syringe graduations',
   {'weight_kg': 21, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 7.5, 'dose_mg': 150.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 195, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 4.5, 'dose_mg': 180.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 39, 'mg_per_kg': 5, 'max_mg': 200, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 200.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.1', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 5, 'max_mg': 1000, 'conc_mg': 10, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 31, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2})],
 [('suspension per 5 mL label',
   {'weight_kg': 14, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 4.0, 'dose_mg': 200.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 10, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 4.2, 'dose_mg': 100.8}),
  ('10 mL syringe graduations',
   {'weight_kg': 22, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 7.5, 'dose_mg': 150.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 215, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 200.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 43, 'mg_per_kg': 5, 'max_mg': 220, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.5, 'dose_mg': 220.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.2', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 10, 'max_mg': 1000, 'conc_mg': 20, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 32, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2})],
 [('suspension per 5 mL label',
   {'weight_kg': 15, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 4.5, 'dose_mg': 225.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 11, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 4.6, 'dose_mg': 110.4}),
  ('10 mL syringe graduations',
   {'weight_kg': 23, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 8.0, 'dose_mg': 160.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 235, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.5, 'dose_mg': 220.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 47, 'mg_per_kg': 5, 'max_mg': 240, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 6.0, 'dose_mg': 240.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.05', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 30, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 34, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 3})],
 [('suspension per 5 mL label',
   {'weight_kg': 16, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 250.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 12, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('10 mL syringe graduations',
   {'weight_kg': 24, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 8.5, 'dose_mg': 170.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 255, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 6.0, 'dose_mg': 240.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 51, 'mg_per_kg': 5, 'max_mg': 260, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 6.5, 'dose_mg': 260.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.15', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 20, 'max_mg': 1000, 'conc_mg': 40, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 36, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 3})],
 [('suspension per 5 mL label',
   {'weight_kg': 17, 'mg_per_kg': 15, 'max_mg': 500, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 250.0}),
  ('5 mL syringe graduations',
   {'weight_kg': 13, 'mg_per_kg': 10, 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('10 mL syringe graduations',
   {'weight_kg': 25, 'mg_per_kg': 7, 'max_mg': 500, 'conc_mg': 100, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 9.0, 'dose_mg': 180.0}),
  ('rounding up would exceed maximum',
   {'weight_kg': 40, 'mg_per_kg': 20, 'max_mg': 275, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 6.5, 'dose_mg': 260.0}),
  ('rounding up lands exactly on maximum',
   {'weight_kg': 55, 'mg_per_kg': 5, 'max_mg': 280, 'conc_mg': 200, 'conc_ml': 5, 'syringe_ml': 10},
   {'status': 'OK', 'volume_ml': 7.0, 'dose_mg': 280.0}),
  ('volume rounds down to capacity',
   {'weight_kg': 10, 'mg_per_kg': '12.12', 'max_mg': 500, 'conc_mg': 120, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'OK', 'volume_ml': 5.0, 'dose_mg': 120.0}),
  ('exact multiple of syringe capacity',
   {'weight_kg': 20, 'mg_per_kg': 25, 'max_mg': 1000, 'conc_mg': 50, 'conc_ml': 1, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 2}),
  ('split across syringes',
   {'weight_kg': 37, 'mg_per_kg': 15, 'max_mg': 1000, 'conc_mg': 250, 'conc_ml': 5, 'syringe_ml': 5},
   {'status': 'SPLIT', 'syringes': 3})]]
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:
Rounding the volume up delivers more than the maximum dose.

Input {weight_kg, mg_per_kg, max_mg, conc_mg, conc_ml (label strength conc_mg per conc_ml), syringe_ml (1, 5 or 10)}. dose = min(mg_per_kg*weight, max_mg); volume = dose/(conc_mg/conc_ml). Graduations: 1 mL syringe 0.01 mL, 5 mL syringe 0.2 mL, 10 mL syringe 0.5 mL. Round half-up to the graduation, but if that delivers more than max_mg round down instead. A rounded volume above syringe capacity returns {status SPLIT, syringes = ceil(volume/capacity)}; otherwise {status OK, volume_ml, dose_mg delivered}.

split: open-access