broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(a, b):
    BANDS = [(101, 200, 1), (200, 300, 2), (300, 400, 5), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]
    def index(v):
        n = 0
        for lo, hi, step in BANDS:
            if v >= hi:
                n += (hi - lo) // step
            else:
                if (v - lo) % step:
                    return None
                return n + (v - lo) // step
        return None
    out = []
    for p in (a, b):
        c = Fraction(p) * 100
        if c.denominator != 1 or c < 101 or c > 100000:
            return 'invalid'
        i = index(int(c))
        if i is None:
            return 'off ladder'
        out.append(i)
    return out[0] - out[1]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: distance sign', ('2.10', '3.30'), 51),
  ('regression: distance sign', ('20.00', '4.00'), -60),
  ('variant scenario 1', ('5.90', '2.36'), -71),
  ('variant scenario 2', ('70.00', '1.16'), -238)],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: distance sign', ('17.50', '2.10'), -120),
  ('variant scenario 1', ('4.70', '8.00'), 23),
  ('variant scenario 2', ('42.00', '8.21'), 'off ladder')],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: distance sign', ('4.20', '11.00'), 40),
  ('regression: distance sign', ('5.10', '1.91'), -90),
  ('variant scenario 1', ('19.01', '11.50'), 'off ladder'),
  ('variant scenario 2', ('9.20', '560.00'), 100)],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: distance sign', ('1.31', '2.88'), 113),
  ('regression: distance sign', ('8.40', '2.76'), -64),
  ('variant scenario 1', ('44.00', '95.00'), 12),
  ('variant scenario 2', ('5.91', '30.00'), 'off ladder')],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: distance sign', ('2.38', '4.00'), 51),
  ('regression: distance sign', ('18.00', '12.50'), -11),
  ('variant scenario 1', ('2.12', '2.34'), 11),
  ('variant scenario 2', ('3.90', '5.50'), 17)]]
for label, args, expected in cases[N - 1]:
    check(label, run(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
from fractions import Fraction
N = 1
observations = []
def solve(a, b):
    BANDS = [(101, 200, 1), (200, 300, 2), (300, 400, 5), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]
    def index(v):
        n = 0
        for lo, hi, step in BANDS:
            if v >= hi:
                n += (hi - lo) // step
            else:
                if (v - lo) % step:
                    return None
                return n + (v - lo) // step
        return None
    out = []
    for p in (a, b):
        c = Fraction(p) * 100
        if c.denominator != 1 or c < 101 or c > 100000:
            return 'invalid'
        i = index(int(c))
        if i is None:
            return 'off ladder'
        out.append(i)
    return abs(out[1] - out[0])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: distance sign', ('2.10', '3.30'), 51),
  ('regression: distance sign', ('20.00', '4.00'), -60),
  ('variant scenario 1', ('5.90', '2.36'), -71),
  ('variant scenario 2', ('70.00', '1.16'), -238)],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: distance sign', ('17.50', '2.10'), -120),
  ('variant scenario 1', ('4.70', '8.00'), 23),
  ('variant scenario 2', ('42.00', '8.21'), 'off ladder')],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: distance sign', ('4.20', '11.00'), 40),
  ('regression: distance sign', ('5.10', '1.91'), -90),
  ('variant scenario 1', ('19.01', '11.50'), 'off ladder'),
  ('variant scenario 2', ('9.20', '560.00'), 100)],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: distance sign', ('1.31', '2.88'), 113),
  ('regression: distance sign', ('8.40', '2.76'), -64),
  ('variant scenario 1', ('44.00', '95.00'), 12),
  ('variant scenario 2', ('5.91', '30.00'), 'off ladder')],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: distance sign', ('2.38', '4.00'), 51),
  ('regression: distance sign', ('18.00', '12.50'), -11),
  ('variant scenario 1', ('2.12', '2.34'), 11),
  ('variant scenario 2', ('3.90', '5.50'), 17)]]
for label, args, expected in cases[N - 1]:
    check(label, run(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:
Moving from 3.10 down to 2.90 reports +7 ticks.

Signed tick distance from price a to price b on the ladder [(101, 200, 1), (200, 300, 2), (300, 400, 5), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)] (hundredths). Prices must be within 1.01..1000 ("invalid") and exactly on a tick ("off ladder"). Tick index counts all ticks of lower bands ((hi - lo) / step each) plus (v - lo) / step within the band. Return index(b) - index(a).

split: open-access


meaning: Fixture-count band, not measured model difficulty

deps: stdlib

prompt:
A 3.40 price displays as 9/4 instead of 5/2.

Display a decimal price (> 1, else "invalid") as the nearest traditional fraction from the ascending ladder ['1/10', '1/8', '1/5', '2/9', '1/4', '2/7', '1/3', '4/11', '2/5', '4/9', '1/2', '8/15', '4/7', '8/13', '4/6', '8/11', '4/5', '5/6', '10/11', 'evens', '11/10', '6/5', '5/4', '11/8', '6/4', '13/8', '7/4', '15/8', '2/1', '9/4', '5/2', '11/4', '3/1', '10/3', '7/2', '4/1', '9/2', '5/1', '11/2', '6/1', '13/2', '7/1', '15/2', '8/1', '17/2', '9/1', '10/1', '11/1', '12/1', '14/1', '16/1', '18/1', '20/1', '25/1', '33/1', '40/1', '50/1', '66/1', '100/1']. Distance is |fraction value - (d - 1)| with "evens" = 1; ties go to the earlier (shorter) ladder entry. Return the ladder string.

split: open-access


prompt:
A 3.00 price is displayed as 3/1 instead of 2/1.

Display a decimal price (> 1, else "invalid") as the nearest traditional fraction from the ascending ladder ['1/10', '1/8', '1/5', '2/9', '1/4', '2/7', '1/3', '4/11', '2/5', '4/9', '1/2', '8/15', '4/7', '8/13', '4/6', '8/11', '4/5', '5/6', '10/11', 'evens', '11/10', '6/5', '5/4', '11/8', '6/4', '13/8', '7/4', '15/8', '2/1', '9/4', '5/2', '11/4', '3/1', '10/3', '7/2', '4/1', '9/2', '5/1', '11/2', '6/1', '13/2', '7/1', '15/2', '8/1', '17/2', '9/1', '10/1', '11/1', '12/1', '14/1', '16/1', '18/1', '20/1', '25/1', '33/1', '40/1', '50/1', '66/1', '100/1']. Distance is |fraction value - (d - 1)| with "evens" = 1; ties go to the earlier (shorter) ladder entry. Return the ladder string.

split: open-access


prompt:
A price exactly between 11/4 and 3/1 displays as 3/1.

Display a decimal price (> 1, else "invalid") as the nearest traditional fraction from the ascending ladder ['1/10', '1/8', '1/5', '2/9', '1/4', '2/7', '1/3', '4/11', '2/5', '4/9', '1/2', '8/15', '4/7', '8/13', '4/6', '8/11', '4/5', '5/6', '10/11', 'evens', '11/10', '6/5', '5/4', '11/8', '6/4', '13/8', '7/4', '15/8', '2/1', '9/4', '5/2', '11/4', '3/1', '10/3', '7/2', '4/1', '9/2', '5/1', '11/2', '6/1', '13/2', '7/1', '15/2', '8/1', '17/2', '9/1', '10/1', '11/1', '12/1', '14/1', '16/1', '18/1', '20/1', '25/1', '33/1', '40/1', '50/1', '66/1', '100/1']. Distance is |fraction value - (d - 1)| with "evens" = 1; ties go to the earlier (shorter) ladder entry. Return the ladder string.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import itertools
import math
N = 1
observations = []
def solve(selections, unit_cents, system):
    SYS = {'trixie': (3, [2, 3]), 'patent': (3, [1, 2, 3]), 'yankee': (4, [1, 2, 3, 4]), 'lucky15': (4, [1, 2, 3, 4])}
    n, sizes = SYS[system]
    if len(selections) != n:
        return 'invalid'
    lines = [c for k in sizes for c in itertools.combinations(range(n), k)]
    ret = Fraction(0)
    for combo in lines:
        m = Fraction(1)
        for i in combo:
            price, result = selections[i]
            if result == 'lose':
                m = Fraction(0)
                break
            if result == 'win':
                m *= Fraction(price)
        ret += unit_cents * m
    return [len(lines), unit_cents * len(lines), math.floor(ret)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: yankee composition',
   ([['5.29', 'win'], ['2.17', 'win'], ['4.78', 'void'], ['3.18', 'void']], 50, 'yankee'),
   [11, 550, 3464]),
  ('variant scenario 1',
   ([['1.95', 'win'], ['4.63', 'win'], ['5.31', 'win']], 25, 'trixie'),
   [4, 100, 2297]),
  ('variant scenario 2',
   ([['5.78', 'win'], ['1.85', 'lose'], ['1.47', 'void'], ['1.41', 'void']], 25, 'lucky15'),
   [15, 375, 653])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: yankee composition',
   ([['5.29', 'lose'], ['1.90', 'win'], ['2.16', 'lose'], ['1.45', 'win']], 50, 'yankee'),
   [11, 550, 137]),
  ('variant scenario 1',
   ([['2.42', 'lose'], ['2.58', 'win'], ['2.00', 'lose'], ['4.02', 'win']], 100, 'lucky15'),
   [15, 1500, 1697]),
  ('variant scenario 2',
   ([['2.34', 'win'], ['1.77', 'lose'], ['4.10', 'lose']], 100, 'patent'),
   [7, 700, 234])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: yankee composition',
   ([['3.11', 'win'], ['5.18', 'win'], ['2.02', 'win'], ['1.76', 'win']], 100, 'yankee'),
   [11, 1100, 19864]),
  ('variant scenario 1',
   ([['4.95', 'win'], ['5.49', 'void'], ['4.60', 'void']], 100, 'trixie'),
   [4, 400, 1585]),
  ('variant scenario 2',
   ([['3.01', 'lose'], ['4.92', 'lose'], ['1.83', 'lose'], ['2.53', 'lose'], ['3.61', 'void']],
    100,
    'lucky15'),
   'invalid')],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: yankee composition',
   ([['5.73', 'void'], ['3.73', 'void'], ['2.13', 'lose'], ['3.62', 'win']], 25, 'yankee'),
   [11, 275, 296]),
  ('variant scenario 1',
   ([['4.26', 'win'], ['1.31', 'void'], ['1.86', 'void']], 100, 'patent'),
   [7, 700, 2004]),
  ('variant scenario 2',
   ([['4.86', 'void'], ['3.74', 'void'], ['3.83', 'win']], 25, 'trixie'),
   [4, 100, 312])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: yankee composition',
   ([['1.39', 'win'], ['4.34', 'void'], ['2.29', 'void'], ['5.41', 'void']], 50, 'yankee'),
   [11, 550, 686]),
  ('variant scenario 1',
   ([['4.65', 'win'], ['1.35', 'void'], ['1.60', 'void']], 25, 'patent'),
   [7, 175, 540]),
  ('variant scenario 2',
   ([['3.24', 'win'], ['1.34', 'void'], ['3.79', 'win']], 100, 'trixie'),
   [4, 400, 3158])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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
from fractions import Fraction
import itertools
import math
N = 1
observations = []
def solve(selections, unit_cents, system):
    SYS = {'trixie': (3, [2, 3]), 'patent': (3, [1, 2, 3]), 'yankee': (4, [2, 3]), 'lucky15': (4, [1, 2, 3, 4])}
    n, sizes = SYS[system]
    if len(selections) != n:
        return 'invalid'
    lines = [c for k in sizes for c in itertools.combinations(range(n), k)]
    ret = Fraction(0)
    for combo in lines:
        m = Fraction(1)
        for i in combo:
            price, result = selections[i]
            if result == 'lose':
                m = Fraction(0)
                break
            if result == 'win':
                m *= Fraction(price)
        ret += unit_cents * m
    return [len(lines), unit_cents * len(lines), math.floor(ret)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: yankee composition',
   ([['5.29', 'win'], ['2.17', 'win'], ['4.78', 'void'], ['3.18', 'void']], 50, 'yankee'),
   [11, 550, 3464]),
  ('variant scenario 1',
   ([['1.95', 'win'], ['4.63', 'win'], ['5.31', 'win']], 25, 'trixie'),
   [4, 100, 2297]),
  ('variant scenario 2',
   ([['5.78', 'win'], ['1.85', 'lose'], ['1.47', 'void'], ['1.41', 'void']], 25, 'lucky15'),
   [15, 375, 653])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: yankee composition',
   ([['5.29', 'lose'], ['1.90', 'win'], ['2.16', 'lose'], ['1.45', 'win']], 50, 'yankee'),
   [11, 550, 137]),
  ('variant scenario 1',
   ([['2.42', 'lose'], ['2.58', 'win'], ['2.00', 'lose'], ['4.02', 'win']], 100, 'lucky15'),
   [15, 1500, 1697]),
  ('variant scenario 2',
   ([['2.34', 'win'], ['1.77', 'lose'], ['4.10', 'lose']], 100, 'patent'),
   [7, 700, 234])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: yankee composition',
   ([['3.11', 'win'], ['5.18', 'win'], ['2.02', 'win'], ['1.76', 'win']], 100, 'yankee'),
   [11, 1100, 19864]),
  ('variant scenario 1',
   ([['4.95', 'win'], ['5.49', 'void'], ['4.60', 'void']], 100, 'trixie'),
   [4, 400, 1585]),
  ('variant scenario 2',
   ([['3.01', 'lose'], ['4.92', 'lose'], ['1.83', 'lose'], ['2.53', 'lose'], ['3.61', 'void']],
    100,
    'lucky15'),
   'invalid')],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: yankee composition',
   ([['5.73', 'void'], ['3.73', 'void'], ['2.13', 'lose'], ['3.62', 'win']], 25, 'yankee'),
   [11, 275, 296]),
  ('variant scenario 1',
   ([['4.26', 'win'], ['1.31', 'void'], ['1.86', 'void']], 100, 'patent'),
   [7, 700, 2004]),
  ('variant scenario 2',
   ([['4.86', 'void'], ['3.74', 'void'], ['3.83', 'win']], 25, 'trixie'),
   [4, 100, 312])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: yankee composition',
   ([['1.39', 'win'], ['4.34', 'void'], ['2.29', 'void'], ['5.41', 'void']], 50, 'yankee'),
   [11, 550, 686]),
  ('variant scenario 1',
   ([['4.65', 'win'], ['1.35', 'void'], ['1.60', 'void']], 25, 'patent'),
   [7, 175, 540]),
  ('variant scenario 2',
   ([['3.24', 'win'], ['1.34', 'void'], ['3.79', 'win']], 100, 'trixie'),
   [4, 400, 3158])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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 yankee is settled as 15 lines, or as 10 lines without the fourfold.

Full-cover system bets. system: trixie (3 selections: doubles and treble), patent (3: singles, doubles, treble), yankee (4: doubles, trebles, fourfold), lucky15 (4: singles through fourfold). Wrong selection count returns "invalid". Every combination is a line staked unit_cents; a line with a losing selection returns 0; void selections count as price 1. Return [lines, total stake, total return rounded down].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import itertools
import math
N = 1
observations = []
def solve(selections, unit_cents, system):
    SYS = {'trixie': (3, [2, 3]), 'patent': (3, [1, 2, 3]), 'yankee': (4, [2, 3, 4]), 'lucky15': (4, [1, 2, 3, 4])}
    n, sizes = SYS[system]
    if len(selections) != n:
        return 'invalid'
    lines = [c for k in sizes for c in itertools.combinations(range(n), k)]
    ret = Fraction(0)
    for combo in lines:
        m = Fraction(1)
        for i in combo:
            price, result = selections[i]
            if result in ('lose', 'void'):
                m = Fraction(0)
                break
            if result == 'win':
                m *= Fraction(price)
        ret += unit_cents * m
    return [len(lines), unit_cents * len(lines), math.floor(ret)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: void selection',
   ([['5.92', 'lose'], ['4.13', 'lose'], ['5.96', 'void']], 100, 'patent'),
   [7, 700, 100]),
  ('variant scenario 1',
   ([['3.65', 'win'], ['3.16', 'win'], ['2.64', 'win'], ['4.07', 'win']], 100, 'lucky15'),
   [15, 1500, 35598]),
  ('variant scenario 2',
   ([['4.68', 'lose'], ['2.86', 'lose'], ['2.47', 'lose'], ['4.63', 'win']], 100, 'lucky15'),
   [15, 1500, 463])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: void selection',
   ([['2.01', 'void'], ['2.91', 'void'], ['2.01', 'lose']], 100, 'trixie'),
   [4, 400, 100]),
  ('variant scenario 1',
   ([['3.09', 'win'], ['4.05', 'void'], ['5.96', 'lose'], ['1.77', 'lose']], 50, 'yankee'),
   [11, 550, 154]),
  ('variant scenario 2',
   ([['2.18', 'lose'], ['4.86', 'win'], ['3.65', 'win']], 100, 'trixie'),
   [4, 400, 1773])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: void selection',
   ([['4.32', 'win'], ['5.81', 'lose'], ['1.95', 'void'], ['3.80', 'win']], 100, 'yankee'),
   [11, 1100, 4095]),
  ('variant scenario 1',
   ([['2.12', 'win'], ['3.26', 'win'], ['2.15', 'lose']], 50, 'patent'),
   [7, 350, 614]),
  ('variant scenario 2',
   ([['5.95', 'win'], ['2.71', 'lose'], ['3.63', 'lose']], 25, 'patent'),
   [7, 175, 148])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: void selection',
   ([['2.47', 'lose'], ['4.09', 'win'], ['4.37', 'win'], ['2.66', 'void']], 100, 'yankee'),
   [11, 1100, 4420]),
  ('variant scenario 1',
   ([['3.59', 'lose'], ['4.34', 'win'], ['3.89', 'win'], ['2.34', 'win']], 25, 'yankee'),
   [11, 275, 1891]),
  ('variant scenario 2',
   ([['2.72', 'win'], ['5.80', 'lose'], ['2.62', 'lose']], 25, 'trixie'),
   [4, 100, 0])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: void selection',
   ([['4.84', 'lose'], ['1.69', 'win'], ['5.48', 'win'], ['5.81', 'void']], 50, 'yankee'),
   [11, 550, 1284]),
  ('variant scenario 1',
   ([['3.45', 'win'], ['4.45', 'void'], ['3.65', 'win'], ['2.52', 'win']], 100, 'lucky15'),
   [15, 1500, 14467]),
  ('variant scenario 2',
   ([['5.21', 'lose'], ['5.61', 'win'], ['5.91', 'void'], ['1.84', 'lose']], 25, 'lucky15'),
   [15, 375, 305])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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
from fractions import Fraction
import itertools
import math
N = 1
observations = []
def solve(selections, unit_cents, system):
    SYS = {'trixie': (3, [2, 3]), 'patent': (3, [1, 2, 3]), 'yankee': (4, [2, 3, 4]), 'lucky15': (4, [1, 2, 3, 4])}
    n, sizes = SYS[system]
    if len(selections) != n:
        return 'invalid'
    lines = [c for k in sizes for c in itertools.combinations(range(n), k)]
    ret = Fraction(0)
    for combo in lines:
        m = Fraction(1)
        for i in combo:
            price, result = selections[i]
            if result == 'lose':
                m = Fraction(0)
                break
            if result in ('win', 'void'):
                m *= Fraction(price)
        ret += unit_cents * m
    return [len(lines), unit_cents * len(lines), math.floor(ret)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: void selection',
   ([['5.92', 'lose'], ['4.13', 'lose'], ['5.96', 'void']], 100, 'patent'),
   [7, 700, 100]),
  ('variant scenario 1',
   ([['3.65', 'win'], ['3.16', 'win'], ['2.64', 'win'], ['4.07', 'win']], 100, 'lucky15'),
   [15, 1500, 35598]),
  ('variant scenario 2',
   ([['4.68', 'lose'], ['2.86', 'lose'], ['2.47', 'lose'], ['4.63', 'win']], 100, 'lucky15'),
   [15, 1500, 463])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: void selection',
   ([['2.01', 'void'], ['2.91', 'void'], ['2.01', 'lose']], 100, 'trixie'),
   [4, 400, 100]),
  ('variant scenario 1',
   ([['3.09', 'win'], ['4.05', 'void'], ['5.96', 'lose'], ['1.77', 'lose']], 50, 'yankee'),
   [11, 550, 154]),
  ('variant scenario 2',
   ([['2.18', 'lose'], ['4.86', 'win'], ['3.65', 'win']], 100, 'trixie'),
   [4, 400, 1773])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: void selection',
   ([['4.32', 'win'], ['5.81', 'lose'], ['1.95', 'void'], ['3.80', 'win']], 100, 'yankee'),
   [11, 1100, 4095]),
  ('variant scenario 1',
   ([['2.12', 'win'], ['3.26', 'win'], ['2.15', 'lose']], 50, 'patent'),
   [7, 350, 614]),
  ('variant scenario 2',
   ([['5.95', 'win'], ['2.71', 'lose'], ['3.63', 'lose']], 25, 'patent'),
   [7, 175, 148])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: void selection',
   ([['2.47', 'lose'], ['4.09', 'win'], ['4.37', 'win'], ['2.66', 'void']], 100, 'yankee'),
   [11, 1100, 4420]),
  ('variant scenario 1',
   ([['3.59', 'lose'], ['4.34', 'win'], ['3.89', 'win'], ['2.34', 'win']], 25, 'yankee'),
   [11, 275, 1891]),
  ('variant scenario 2',
   ([['2.72', 'win'], ['5.80', 'lose'], ['2.62', 'lose']], 25, 'trixie'),
   [4, 100, 0])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: void selection',
   ([['4.84', 'lose'], ['1.69', 'win'], ['5.48', 'win'], ['5.81', 'void']], 50, 'yankee'),
   [11, 550, 1284]),
  ('variant scenario 1',
   ([['3.45', 'win'], ['4.45', 'void'], ['3.65', 'win'], ['2.52', 'win']], 100, 'lucky15'),
   [15, 1500, 14467]),
  ('variant scenario 2',
   ([['5.21', 'lose'], ['5.61', 'win'], ['5.91', 'void'], ['1.84', 'lose']], 25, 'lucky15'),
   [15, 375, 305])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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:
Lines containing a non-runner return nothing, or pay the non-runner price.

Full-cover system bets. system: trixie (3 selections: doubles and treble), patent (3: singles, doubles, treble), yankee (4: doubles, trebles, fourfold), lucky15 (4: singles through fourfold). Wrong selection count returns "invalid". Every combination is a line staked unit_cents; a line with a losing selection returns 0; void selections count as price 1. Return [lines, total stake, total return rounded down].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import itertools
import math
N = 1
observations = []
def solve(selections, unit_cents, system):
    SYS = {'trixie': (3, [2, 3]), 'patent': (3, [1, 2, 3]), 'yankee': (4, [2, 3, 4]), 'lucky15': (4, [1, 2, 3, 4])}
    n, sizes = SYS[system]
    if len(selections) != n:
        return 'invalid'
    lines = [c for k in sizes for c in itertools.combinations(range(n), k)]
    ret = Fraction(0)
    for combo in lines:
        m = Fraction(1)
        for i in combo:
            price, result = selections[i]
            if result == 'lose':
                m = Fraction(0)
                break
            if result == 'win':
                m *= Fraction(price)
        ret += unit_cents * m
    return [len(lines), unit_cents * n, math.floor(ret)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: total stake',
   ([['2.81', 'win'], ['4.60', 'lose'], ['2.95', 'lose'], ['1.62', 'lose']], 25, 'lucky15'),
   [15, 375, 70]),
  ('variant scenario 1',
   ([['5.79', 'lose'], ['3.41', 'void'], ['3.66', 'win']], 25, 'trixie'),
   [4, 100, 91]),
  ('variant scenario 2',
   ([['3.01', 'lose'], ['4.93', 'win'], ['2.10', 'lose']], 50, 'patent'),
   [7, 350, 246])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: total stake',
   ([['4.89', 'win'], ['3.10', 'win'], ['3.26', 'win'], ['3.49', 'lose']], 50, 'yankee'),
   [11, 550, 4531]),
  ('variant scenario 1',
   ([['2.52', 'win'], ['2.43', 'void'], ['1.54', 'win'], ['5.51', 'void']], 100, 'lucky15'),
   [15, 1500, 3476]),
  ('variant scenario 2',
   ([['2.97', 'lose'], ['3.94', 'void'], ['1.41', 'win'], ['5.60', 'lose']], 100, 'yankee'),
   [11, 1100, 141])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: total stake',
   ([['2.82', 'win'], ['3.33', 'lose'], ['1.68', 'lose'], ['2.92', 'lose']], 100, 'lucky15'),
   [15, 1500, 282]),
  ('variant scenario 1',
   ([['3.30', 'win'], ['2.92', 'lose'], ['4.87', 'void']], 100, 'patent'),
   [7, 700, 760]),
  ('variant scenario 2',
   ([['1.96', 'lose'], ['5.37', 'void'], ['3.43', 'void'], ['2.72', 'win']], 50, 'yankee'),
   [11, 550, 458])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: total stake',
   ([['3.79', 'lose'], ['4.05', 'win'], ['4.66', 'win'], ['5.16', 'void']], 100, 'yankee'),
   [11, 1100, 4645]),
  ('variant scenario 1',
   ([['3.13', 'void'], ['4.79', 'win'], ['4.77', 'win'], ['1.56', 'win']], 50, 'yankee'),
   [11, 550, 7896]),
  ('variant scenario 2',
   ([['5.53', 'lose'], ['4.16', 'win'], ['2.16', 'win'], ['2.29', 'void']], 100, 'lucky15'),
   [15, 1500, 3161])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: total stake',
   ([['3.05', 'win'], ['4.52', 'win'], ['3.40', 'win']], 50, 'patent'),
   [7, 350, 4868]),
  ('variant scenario 1',
   ([['2.02', 'win'], ['2.56', 'win'], ['2.79', 'void'], ['2.20', 'win']], 25, 'lucky15'),
   [15, 375, 1695]),
  ('variant scenario 2',
   ([['2.95', 'lose'], ['3.69', 'win'], ['3.92', 'win']], 50, 'patent'),
   [7, 350, 1103])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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
from fractions import Fraction
import itertools
import math
N = 1
observations = []
def solve(selections, unit_cents, system):
    SYS = {'trixie': (3, [2, 3]), 'patent': (3, [1, 2, 3]), 'yankee': (4, [2, 3, 4]), 'lucky15': (4, [1, 2, 3, 4])}
    n, sizes = SYS[system]
    if len(selections) != n:
        return 'invalid'
    lines = [c for k in sizes for c in itertools.combinations(range(n), k)]
    ret = Fraction(0)
    for combo in lines:
        m = Fraction(1)
        for i in combo:
            price, result = selections[i]
            if result == 'lose':
                m = Fraction(0)
                break
            if result == 'win':
                m *= Fraction(price)
        ret += unit_cents * m
    return [len(lines), unit_cents * len(sizes), math.floor(ret)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: total stake',
   ([['2.81', 'win'], ['4.60', 'lose'], ['2.95', 'lose'], ['1.62', 'lose']], 25, 'lucky15'),
   [15, 375, 70]),
  ('variant scenario 1',
   ([['5.79', 'lose'], ['3.41', 'void'], ['3.66', 'win']], 25, 'trixie'),
   [4, 100, 91]),
  ('variant scenario 2',
   ([['3.01', 'lose'], ['4.93', 'win'], ['2.10', 'lose']], 50, 'patent'),
   [7, 350, 246])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: total stake',
   ([['4.89', 'win'], ['3.10', 'win'], ['3.26', 'win'], ['3.49', 'lose']], 50, 'yankee'),
   [11, 550, 4531]),
  ('variant scenario 1',
   ([['2.52', 'win'], ['2.43', 'void'], ['1.54', 'win'], ['5.51', 'void']], 100, 'lucky15'),
   [15, 1500, 3476]),
  ('variant scenario 2',
   ([['2.97', 'lose'], ['3.94', 'void'], ['1.41', 'win'], ['5.60', 'lose']], 100, 'yankee'),
   [11, 1100, 141])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: total stake',
   ([['2.82', 'win'], ['3.33', 'lose'], ['1.68', 'lose'], ['2.92', 'lose']], 100, 'lucky15'),
   [15, 1500, 282]),
  ('variant scenario 1',
   ([['3.30', 'win'], ['2.92', 'lose'], ['4.87', 'void']], 100, 'patent'),
   [7, 700, 760]),
  ('variant scenario 2',
   ([['1.96', 'lose'], ['5.37', 'void'], ['3.43', 'void'], ['2.72', 'win']], 50, 'yankee'),
   [11, 550, 458])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: total stake',
   ([['3.79', 'lose'], ['4.05', 'win'], ['4.66', 'win'], ['5.16', 'void']], 100, 'yankee'),
   [11, 1100, 4645]),
  ('variant scenario 1',
   ([['3.13', 'void'], ['4.79', 'win'], ['4.77', 'win'], ['1.56', 'win']], 50, 'yankee'),
   [11, 550, 7896]),
  ('variant scenario 2',
   ([['5.53', 'lose'], ['4.16', 'win'], ['2.16', 'win'], ['2.29', 'void']], 100, 'lucky15'),
   [15, 1500, 3161])],
 [('control trixie all win',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 2000]),
  ('control yankee line count',
   ([['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'yankee'),
   [11, 1100, 0]),
  ('boundary void selection',
   ([['2.00', 'void'], ['3.00', 'win'], ['2.00', 'win']], 100, 'trixie'),
   [4, 400, 1700]),
  ('boundary patent single winner',
   ([['5.00', 'win'], ['2.00', 'lose'], ['2.00', 'lose']], 100, 'patent'),
   [7, 700, 500]),
  ('boundary wrong count',
   ([['2.00', 'win'], ['2.00', 'win'], ['2.00', 'win']], 100, 'yankee'),
   'invalid'),
  ('regression: total stake',
   ([['3.05', 'win'], ['4.52', 'win'], ['3.40', 'win']], 50, 'patent'),
   [7, 350, 4868]),
  ('variant scenario 1',
   ([['2.02', 'win'], ['2.56', 'win'], ['2.79', 'void'], ['2.20', 'win']], 25, 'lucky15'),
   [15, 375, 1695]),
  ('variant scenario 2',
   ([['2.95', 'lose'], ['3.69', 'win'], ['3.92', 'win']], 50, 'patent'),
   [7, 350, 1103])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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 yankee is charged 4 units instead of 11.

Full-cover system bets. system: trixie (3 selections: doubles and treble), patent (3: singles, doubles, treble), yankee (4: doubles, trebles, fourfold), lucky15 (4: singles through fourfold). Wrong selection count returns "invalid". Every combination is a line staked unit_cents; a line with a losing selection returns 0; void selections count as price 1. Return [lines, total stake, total return rounded down].

split: open-access


prompt:
A withdrawn 2.50 shot yields a 35p deduction instead of 40p.

Non-runner deduction for a winning bet. Each withdrawn runner's decimal price maps to pence-in-the-pound from the first band whose limit it does not exceed: [('1.30', 75), ('1.40', 70), ('1.53', 65), ('1.62', 60), ('1.80', 55), ('1.95', 50), ('2.20', 45), ('2.50', 40), ('2.75', 35), ('3.25', 30), ('4.00', 25), ('5.00', 20), ('6.50', 15), ('10.00', 10), ('15.00', 5)]; above 15.00 it is 0. Deductions from several withdrawals are summed and capped at 75. The deduction applies to winnings only: return = stake + floor(stake * (price - 1) * (100 - deduction) / 100). Return [deduction, return cents].

split: open-access


prompt:
Winning bets lose part of their stake to the deduction.

Non-runner deduction for a winning bet. Each withdrawn runner's decimal price maps to pence-in-the-pound from the first band whose limit it does not exceed: [('1.30', 75), ('1.40', 70), ('1.53', 65), ('1.62', 60), ('1.80', 55), ('1.95', 50), ('2.20', 45), ('2.50', 40), ('2.75', 35), ('3.25', 30), ('4.00', 25), ('5.00', 20), ('6.50', 15), ('10.00', 10), ('15.00', 5)]; above 15.00 it is 0. Deductions from several withdrawals are summed and capped at 75. The deduction applies to winnings only: return = stake + floor(stake * (price - 1) * (100 - deduction) / 100). Return [deduction, return cents].

split: open-access


prompt:
Two short-priced withdrawals remove more than 75p in the pound.

Non-runner deduction for a winning bet. Each withdrawn runner's decimal price maps to pence-in-the-pound from the first band whose limit it does not exceed: [('1.30', 75), ('1.40', 70), ('1.53', 65), ('1.62', 60), ('1.80', 55), ('1.95', 50), ('2.20', 45), ('2.50', 40), ('2.75', 35), ('3.25', 30), ('4.00', 25), ('5.00', 20), ('6.50', 15), ('10.00', 10), ('15.00', 5)]; above 15.00 it is 0. Deductions from several withdrawals are summed and capped at 75. The deduction applies to winnings only: return = stake + floor(stake * (price - 1) * (100 - deduction) / 100). Return [deduction, return cents].

split: open-access


prompt:
Two withdrawals of 4.00 and 6.00 deduct 25p instead of 40p.

Non-runner deduction for a winning bet. Each withdrawn runner's decimal price maps to pence-in-the-pound from the first band whose limit it does not exceed: [('1.30', 75), ('1.40', 70), ('1.53', 65), ('1.62', 60), ('1.80', 55), ('1.95', 50), ('2.20', 45), ('2.50', 40), ('2.75', 35), ('3.25', 30), ('4.00', 25), ('5.00', 20), ('6.50', 15), ('10.00', 10), ('15.00', 5)]; above 15.00 it is 0. Deductions from several withdrawals are summed and capped at 75. The deduction applies to winnings only: return = stake + floor(stake * (price - 1) * (100 - deduction) / 100). Return [deduction, return cents].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(text):
    t = text.strip()
    try:
        if '/' in t:
            a, b = t.split('/')
            dec = 1 + Fraction(int(a), int(b))
        elif t[:1] in ('+', '-'):
            n = int(t[1:])
            if n < 100:
                return 'invalid'
            dec = 1 + (Fraction(n, 100) if t[0] == '+' else Fraction(100, n))
        elif t.isdigit() and int(t) > 100:
            dec = 1 + Fraction(int(t), 100)
        else:
            dec = Fraction(t.replace(',', '.'))
    except (ValueError, ZeroDivisionError):
        return 'invalid'
    if dec <= 1:
        return 'invalid'
    c = math.floor(dec * 100 + Fraction(1, 2))
    return '%d.%02d' % (c // 100, c % 100)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: unsigned american threshold', ('100',), '2.00'),
  ('regression: unsigned american threshold', ('50',), '50.00'),
  ('variant scenario 1', ('5.92',), '5.92'),
  ('variant scenario 2', ('7.95',), '7.95')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: unsigned american threshold', ('100',), '2.00'),
  ('regression: unsigned american threshold', ('50',), '50.00'),
  ('variant scenario 1', ('1/5',), '1.20'),
  ('variant scenario 2', ('-421',), '1.24')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: unsigned american threshold', ('100',), '2.00'),
  ('regression: unsigned american threshold', ('50',), '50.00'),
  ('variant scenario 1', ('3.75',), '3.75'),
  ('variant scenario 2', ('4.75',), '4.75')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: unsigned american threshold', ('50',), '50.00'),
  ('regression: unsigned american threshold', ('100',), '2.00'),
  ('variant scenario 1', ('469',), '5.69'),
  ('variant scenario 2', ('+481',), '5.81')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: unsigned american threshold', ('50',), '50.00'),
  ('regression: unsigned american threshold', ('100',), '2.00'),
  ('variant scenario 1', ('20/4',), '6.00'),
  ('variant scenario 2', ('5/0',), 'invalid')]]
for label, args, expected in cases[N - 1]:
    check(label, run(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
from fractions import Fraction
import math
N = 1
observations = []
def solve(text):
    t = text.strip()
    try:
        if '/' in t:
            a, b = t.split('/')
            dec = 1 + Fraction(int(a), int(b))
        elif t[:1] in ('+', '-'):
            n = int(t[1:])
            if n < 100:
                return 'invalid'
            dec = 1 + (Fraction(n, 100) if t[0] == '+' else Fraction(100, n))
        elif t.isdigit() and int(t) >= 10:
            dec = 1 + Fraction(int(t), 100)
        else:
            dec = Fraction(t.replace(',', '.'))
    except (ValueError, ZeroDivisionError):
        return 'invalid'
    if dec <= 1:
        return 'invalid'
    c = math.floor(dec * 100 + Fraction(1, 2))
    return '%d.%02d' % (c // 100, c % 100)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: unsigned american threshold', ('100',), '2.00'),
  ('regression: unsigned american threshold', ('50',), '50.00'),
  ('variant scenario 1', ('5.92',), '5.92'),
  ('variant scenario 2', ('7.95',), '7.95')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: unsigned american threshold', ('100',), '2.00'),
  ('regression: unsigned american threshold', ('50',), '50.00'),
  ('variant scenario 1', ('1/5',), '1.20'),
  ('variant scenario 2', ('-421',), '1.24')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: unsigned american threshold', ('100',), '2.00'),
  ('regression: unsigned american threshold', ('50',), '50.00'),
  ('variant scenario 1', ('3.75',), '3.75'),
  ('variant scenario 2', ('4.75',), '4.75')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: unsigned american threshold', ('50',), '50.00'),
  ('regression: unsigned american threshold', ('100',), '2.00'),
  ('variant scenario 1', ('469',), '5.69'),
  ('variant scenario 2', ('+481',), '5.81')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: unsigned american threshold', ('50',), '50.00'),
  ('regression: unsigned american threshold', ('100',), '2.00'),
  ('variant scenario 1', ('20/4',), '6.00'),
  ('variant scenario 2', ('5/0',), 'invalid')]]
for label, args, expected in cases[N - 1]:
    check(label, run(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:
Typing "100" produces a 100.00 decimal price instead of even money.

Normalise user-typed odds to a decimal price string with two decimals (half up). Detection order: text containing "/" is fractional a/b; text starting with "+" or "-" is American (magnitude >= 100); an unsigned integer >= 100 is a positive American line; anything else is a decimal price, where a comma is the decimal separator ("2,50"). Unparseable input, zero denominators, magnitudes below 100 and results not above 1 return "invalid".

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(text):
    t = text.strip()
    try:
        if '/' in t:
            a, b = t.split('/')
            dec = 1 + Fraction(int(a), int(b))
        elif t[:1] in ('+', '-'):
            n = int(t[1:])
            if n < 100:
                return 'invalid'
            dec = 1 + (Fraction(n, 100) if t[0] == '+' else Fraction(100, n))
        elif t.isdigit() and int(t) >= 100:
            dec = 1 + Fraction(int(t), 100)
        else:
            dec = Fraction(t)
    except (ValueError, ZeroDivisionError):
        return 'invalid'
    if dec <= 1:
        return 'invalid'
    c = math.floor(dec * 100 + Fraction(1, 2))
    return '%d.%02d' % (c // 100, c % 100)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: decimal comma', ('7,89',), '7.89'),
  ('variant scenario 1', ('3.40',), '3.40'),
  ('variant scenario 2', ('-372',), '1.27')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: decimal comma', ('6,60',), '6.60'),
  ('variant scenario 1', ('3.47',), '3.47'),
  ('variant scenario 2', ('+536',), '6.36')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: decimal comma', ('6,37',), '6.37'),
  ('variant scenario 1', ('+584',), '6.84'),
  ('variant scenario 2', ('1,75',), '1.75')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: decimal comma', ('3,22',), '3.22'),
  ('variant scenario 1', ('10/2',), '6.00'),
  ('variant scenario 2', ('2/8',), '1.25')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: decimal comma', ('1,75',), '1.75'),
  ('variant scenario 1', ('6.74',), '6.74'),
  ('variant scenario 2', ('+195',), '2.95')]]
for label, args, expected in cases[N - 1]:
    check(label, run(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
from fractions import Fraction
import math
N = 1
observations = []
def solve(text):
    t = text.strip()
    try:
        if '/' in t:
            a, b = t.split('/')
            dec = 1 + Fraction(int(a), int(b))
        elif t[:1] in ('+', '-'):
            n = int(t[1:])
            if n < 100:
                return 'invalid'
            dec = 1 + (Fraction(n, 100) if t[0] == '+' else Fraction(100, n))
        elif t.isdigit() and int(t) >= 100:
            dec = 1 + Fraction(int(t), 100)
        else:
            dec = Fraction(t.replace(',', ''))
    except (ValueError, ZeroDivisionError):
        return 'invalid'
    if dec <= 1:
        return 'invalid'
    c = math.floor(dec * 100 + Fraction(1, 2))
    return '%d.%02d' % (c // 100, c % 100)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: decimal comma', ('7,89',), '7.89'),
  ('variant scenario 1', ('3.40',), '3.40'),
  ('variant scenario 2', ('-372',), '1.27')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: decimal comma', ('6,60',), '6.60'),
  ('variant scenario 1', ('3.47',), '3.47'),
  ('variant scenario 2', ('+536',), '6.36')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: decimal comma', ('6,37',), '6.37'),
  ('variant scenario 1', ('+584',), '6.84'),
  ('variant scenario 2', ('1,75',), '1.75')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: decimal comma', ('3,22',), '3.22'),
  ('variant scenario 1', ('10/2',), '6.00'),
  ('variant scenario 2', ('2/8',), '1.25')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: decimal comma', ('1,75',), '1.75'),
  ('variant scenario 1', ('6.74',), '6.74'),
  ('variant scenario 2', ('+195',), '2.95')]]
for label, args, expected in cases[N - 1]:
    check(label, run(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:
"2,50" is rejected or becomes a +250 American line.

Normalise user-typed odds to a decimal price string with two decimals (half up). Detection order: text containing "/" is fractional a/b; text starting with "+" or "-" is American (magnitude >= 100); an unsigned integer >= 100 is a positive American line; anything else is a decimal price, where a comma is the decimal separator ("2,50"). Unparseable input, zero denominators, magnitudes below 100 and results not above 1 return "invalid".

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(text):
    t = text.strip()
    try:
        if '/' in t:
            a, b = t.split('/')
            dec = 1 + Fraction(int(a), int(b))
        elif t[:1] == '-':
            n = int(t[1:])
            if n < 100:
                return 'invalid'
            dec = 1 + (Fraction(n, 100) if t[0] == '+' else Fraction(100, n))
        elif t.isdigit() and int(t) >= 100:
            dec = 1 + Fraction(int(t), 100)
        else:
            dec = Fraction(t.replace(',', '.'))
    except (ValueError, ZeroDivisionError):
        return 'invalid'
    if dec <= 1:
        return 'invalid'
    c = math.floor(dec * 100 + Fraction(1, 2))
    return '%d.%02d' % (c // 100, c % 100)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: plus sign detection', ('+487',), '5.87'),
  ('regression: plus sign detection', ('',), 'invalid'),
  ('variant scenario 1', ('3,36',), '3.36'),
  ('variant scenario 2', ('3/1',), '4.00')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: plus sign detection', ('+319',), '4.19'),
  ('regression: plus sign detection', ('',), 'invalid'),
  ('variant scenario 1', ('-595',), '1.17'),
  ('variant scenario 2', ('13/2',), '7.50')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: plus sign detection', ('',), 'invalid'),
  ('regression: plus sign detection', ('+100',), '2.00'),
  ('variant scenario 1', ('3,07',), '3.07'),
  ('variant scenario 2', ('256',), '3.56')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: plus sign detection', ('+150',), '2.50'),
  ('regression: plus sign detection', ('',), 'invalid'),
  ('variant scenario 1', ('1.84',), '1.84'),
  ('variant scenario 2', ('6,57',), '6.57')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: plus sign detection', ('+553',), '6.53'),
  ('regression: plus sign detection', ('',), 'invalid'),
  ('variant scenario 1', ('-513',), '1.19'),
  ('variant scenario 2', ('191',), '2.91')]]
for label, args, expected in cases[N - 1]:
    check(label, run(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
from fractions import Fraction
import math
N = 1
observations = []
def solve(text):
    t = text.strip()
    try:
        if '/' in t:
            a, b = t.split('/')
            dec = 1 + Fraction(int(a), int(b))
        elif t[0] in '+-':
            n = int(t[1:])
            if n < 100:
                return 'invalid'
            dec = 1 + (Fraction(n, 100) if t[0] == '+' else Fraction(100, n))
        elif t.isdigit() and int(t) >= 100:
            dec = 1 + Fraction(int(t), 100)
        else:
            dec = Fraction(t.replace(',', '.'))
    except (ValueError, ZeroDivisionError):
        return 'invalid'
    if dec <= 1:
        return 'invalid'
    c = math.floor(dec * 100 + Fraction(1, 2))
    return '%d.%02d' % (c // 100, c % 100)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: plus sign detection', ('+487',), '5.87'),
  ('regression: plus sign detection', ('',), 'invalid'),
  ('variant scenario 1', ('3,36',), '3.36'),
  ('variant scenario 2', ('3/1',), '4.00')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: plus sign detection', ('+319',), '4.19'),
  ('regression: plus sign detection', ('',), 'invalid'),
  ('variant scenario 1', ('-595',), '1.17'),
  ('variant scenario 2', ('13/2',), '7.50')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: plus sign detection', ('',), 'invalid'),
  ('regression: plus sign detection', ('+100',), '2.00'),
  ('variant scenario 1', ('3,07',), '3.07'),
  ('variant scenario 2', ('256',), '3.56')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: plus sign detection', ('+150',), '2.50'),
  ('regression: plus sign detection', ('',), 'invalid'),
  ('variant scenario 1', ('1.84',), '1.84'),
  ('variant scenario 2', ('6,57',), '6.57')],
 [('control fractional', ('5/2',), '3.50'),
  ('control negative american', ('-110',), '1.91'),
  ('boundary unsigned hundred', ('100',), '2.00'),
  ('boundary small integer is decimal', ('3',), '3.00'),
  ('boundary decimal comma', ('2,50',), '2.50'),
  ('control empty input', ('',), 'invalid'),
  ('regression: plus sign detection', ('+553',), '6.53'),
  ('regression: plus sign detection', ('',), 'invalid'),
  ('variant scenario 1', ('-513',), '1.19'),
  ('variant scenario 2', ('191',), '2.91')]]
for label, args, expected in cases[N - 1]:
    check(label, run(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:
"+150" is read as a 150.00 decimal price, or empty input crashes.

Normalise user-typed odds to a decimal price string with two decimals (half up). Detection order: text containing "/" is fractional a/b; text starting with "+" or "-" is American (magnitude >= 100); an unsigned integer >= 100 is a positive American line; anything else is a decimal price, where a comma is the decimal separator ("2,50"). Unparseable input, zero denominators, magnitudes below 100 and results not above 1 return "invalid".

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(legs, stake_cents, margin_pct, partial_cents):
    value = Fraction(stake_cents)
    for price, cur in legs:
        if cur == 'lost':
            return [0, 0]
        value *= Fraction(price) - 1
        if cur != 'won':
            value /= Fraction(cur) - 1
    value = value * (100 - Fraction(margin_pct)) / 100
    full = math.floor(value)
    if partial_cents == 0:
        return [full, 0]
    if partial_cents > full:
        return 'invalid'
    remaining = math.floor(stake_cents * (1 - Fraction(partial_cents, full)))
    return [partial_cents, remaining]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio', ([['3.04', 'won']], 2500, '0', 200), [200, 2434]),
  ('regression: price ratio', ([['4.46', '3.15']], 2500, '7.5', 500), [500, 2118]),
  ('variant scenario 1', ([['3.10', '4.55'], ['2.81', 'lost']], 2500, '0', 800), [0, 0]),
  ('variant scenario 2',
   ([['4.23', '2.69'], ['3.78', 'lost'], ['3.20', '3.35']], 1000, '7.5', 200),
   [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio',
   ([['3.57', '2.52'], ['4.50', '4.68'], ['4.10', '5.08']], 500, '0', 200),
   [200, 317]),
  ('variant scenario 1', ([['2.62', 'lost'], ['2.60', 'won']], 500, '5', 0), [0, 0]),
  ('variant scenario 2', ([['2.11', '4.37']], 2500, '5', 0), [1146, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio',
   ([['2.58', 'won'], ['4.59', '4.36'], ['2.12', '5.27']], 1000, '7.5', 0),
   [1010, 0]),
  ('variant scenario 1',
   ([['2.10', 'lost'], ['4.52', '4.26'], ['3.40', '4.12']], 1000, '5', 500),
   [0, 0]),
  ('variant scenario 2', ([['4.81', 'lost']], 500, '5', 500), [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio', ([['4.82', '4.94'], ['3.03', '2.37']], 500, '5', 800), 'invalid'),
  ('regression: price ratio', ([['3.37', '3.69']], 1000, '5', 500), [500, 423]),
  ('variant scenario 1', ([['2.71', 'won'], ['4.12', 'lost']], 500, '5', 500), [0, 0]),
  ('variant scenario 2',
   ([['1.37', '4.05'], ['2.46', 'won'], ['3.51', 'lost'], ['2.03', '2.32']], 2500, '0', 0),
   [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio', ([['2.66', '3.93']], 500, '7.5', 0), [313, 0]),
  ('variant scenario 1',
   ([['4.87', '2.93'], ['1.43', '5.36'], ['2.11', 'lost']], 2500, '7.5', 200),
   [0, 0]),
  ('variant scenario 2',
   ([['4.96', '3.65'], ['3.57', 'lost'], ['3.36', 'won'], ['4.39', 'lost']], 500, '0', 0),
   [0, 0])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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
from fractions import Fraction
import math
N = 1
observations = []
def solve(legs, stake_cents, margin_pct, partial_cents):
    value = Fraction(stake_cents)
    for price, cur in legs:
        if cur == 'lost':
            return [0, 0]
        value *= Fraction(price)
        if cur != 'won':
            value /= Fraction(cur) - 1
    value = value * (100 - Fraction(margin_pct)) / 100
    full = math.floor(value)
    if partial_cents == 0:
        return [full, 0]
    if partial_cents > full:
        return 'invalid'
    remaining = math.floor(stake_cents * (1 - Fraction(partial_cents, full)))
    return [partial_cents, remaining]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio', ([['3.04', 'won']], 2500, '0', 200), [200, 2434]),
  ('regression: price ratio', ([['4.46', '3.15']], 2500, '7.5', 500), [500, 2118]),
  ('variant scenario 1', ([['3.10', '4.55'], ['2.81', 'lost']], 2500, '0', 800), [0, 0]),
  ('variant scenario 2',
   ([['4.23', '2.69'], ['3.78', 'lost'], ['3.20', '3.35']], 1000, '7.5', 200),
   [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio',
   ([['3.57', '2.52'], ['4.50', '4.68'], ['4.10', '5.08']], 500, '0', 200),
   [200, 317]),
  ('variant scenario 1', ([['2.62', 'lost'], ['2.60', 'won']], 500, '5', 0), [0, 0]),
  ('variant scenario 2', ([['2.11', '4.37']], 2500, '5', 0), [1146, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio',
   ([['2.58', 'won'], ['4.59', '4.36'], ['2.12', '5.27']], 1000, '7.5', 0),
   [1010, 0]),
  ('variant scenario 1',
   ([['2.10', 'lost'], ['4.52', '4.26'], ['3.40', '4.12']], 1000, '5', 500),
   [0, 0]),
  ('variant scenario 2', ([['4.81', 'lost']], 500, '5', 500), [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio', ([['4.82', '4.94'], ['3.03', '2.37']], 500, '5', 800), 'invalid'),
  ('regression: price ratio', ([['3.37', '3.69']], 1000, '5', 500), [500, 423]),
  ('variant scenario 1', ([['2.71', 'won'], ['4.12', 'lost']], 500, '5', 500), [0, 0]),
  ('variant scenario 2',
   ([['1.37', '4.05'], ['2.46', 'won'], ['3.51', 'lost'], ['2.03', '2.32']], 2500, '0', 0),
   [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio', ([['2.66', '3.93']], 500, '7.5', 0), [313, 0]),
  ('variant scenario 1',
   ([['4.87', '2.93'], ['1.43', '5.36'], ['2.11', 'lost']], 2500, '7.5', 200),
   [0, 0]),
  ('variant scenario 2',
   ([['4.96', '3.65'], ['3.57', 'lost'], ['3.36', 'won'], ['4.39', 'lost']], 500, '0', 0),
   [0, 0])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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:
Offers are far too high or low when prices move.

Cash-out offer for a single or multiple back bet. legs rows are [price taken, current] where current is a decimal price for an open leg, "won" or "lost". Any lost leg makes the offer [0, 0]. Otherwise value = stake * product of prices taken / product of current prices of open legs, reduced by margin_pct percent, rounded down to a cent. partial_cents 0 means full cash-out: return [value, 0]. A partial amount above the value returns "invalid"; otherwise return [partial, remaining stake] with remaining = floor(stake * (1 - partial / value)).

split: open-access