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):
    factor = Fraction(1)
    for price, result in legs:
        d = Fraction(price)
        if result == 'lose':
            factor = Fraction(0)
            break
        if result == 'win':
            factor *= d
        elif result == 'half-win':
            factor *= (1 + d) / 2
        elif result == 'half-lose':
            factor *= 0
    q = math.floor(factor * 10000 + Fraction(1, 2))
    return ['%d.%04d' % (q // 10000, q % 10000), math.floor(stake_cents * factor)]
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 two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half lose factor',
   ([['2.43', 'half-lose'], ['2.66', 'half-lose'], ['1.80', 'win'], ['2.80', 'void']], 250),
   ['0.4500', 112]),
  ('variant scenario 1', ([['2.93', 'void'], ['1.52', 'half-win']], 100), ['1.2600', 126]),
  ('variant scenario 2',
   ([['2.95', 'win'], ['1.34', 'win'], ['2.38', 'lose'], ['2.73', 'win']], 1000),
   ['0.0000', 0])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half lose factor',
   ([['3.95', 'win'], ['2.15', 'half-lose'], ['2.45', 'half-lose']], 333),
   ['0.9875', 328]),
  ('variant scenario 1',
   ([['2.16', 'lose'], ['2.15', 'void'], ['2.36', 'half-win'], ['2.29', 'win']], 1000),
   ['0.0000', 0]),
  ('variant scenario 2', ([['1.39', 'void'], ['1.88', 'win']], 1000), ['1.8800', 1880])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half lose factor',
   ([['3.23', 'void'], ['1.78', 'half-lose'], ['1.60', 'win'], ['3.77', 'win']], 1999),
   ['3.0160', 6028]),
  ('variant scenario 1',
   ([['2.85', 'lose'], ['2.07', 'half-lose'], ['3.95', 'push'], ['2.78', 'void'], ['2.40', 'void']],
    250),
   ['0.0000', 0]),
  ('variant scenario 2',
   ([['3.61', 'lose'],
     ['3.42', 'half-lose'],
     ['2.22', 'half-win'],
     ['2.00', 'win'],
     ['3.00', 'win']],
    100),
   ['0.0000', 0])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half lose factor',
   ([['1.55', 'half-lose'], ['2.82', 'push'], ['2.89', 'half-win']], 1999),
   ['0.9725', 1944]),
  ('variant scenario 1',
   ([['2.72', 'half-win'],
     ['2.70', 'push'],
     ['3.02', 'lose'],
     ['1.59', 'half-lose'],
     ['1.30', 'half-lose']],
    250),
   ['0.0000', 0]),
  ('variant scenario 2',
   ([['3.97', 'lose'],
     ['2.37', 'half-lose'],
     ['3.46', 'half-win'],
     ['1.36', 'win'],
     ['2.04', 'half-lose']],
    1999),
   ['0.0000', 0])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half lose factor',
   ([['3.21', 'half-win'], ['2.12', 'win'], ['1.45', 'half-lose']], 333),
   ['2.2313', 743]),
  ('variant scenario 1',
   ([['3.09', 'half-lose'], ['2.98', 'lose'], ['3.93', 'win'], ['1.31', 'win'], ['1.54', 'win']],
    1000),
   ['0.0000', 0]),
  ('variant scenario 2', ([['2.51', 'win'], ['1.25', 'lose']], 333), ['0.0000', 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):
    factor = Fraction(1)
    for price, result in legs:
        d = Fraction(price)
        if result == 'lose':
            factor = Fraction(0)
            break
        if result == 'win':
            factor *= d
        elif result == 'half-win':
            factor *= (1 + d) / 2
        elif result == 'half-lose':
            factor *= 1
    q = math.floor(factor * 10000 + Fraction(1, 2))
    return ['%d.%04d' % (q // 10000, q % 10000), math.floor(stake_cents * factor)]
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 two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half lose factor',
   ([['2.43', 'half-lose'], ['2.66', 'half-lose'], ['1.80', 'win'], ['2.80', 'void']], 250),
   ['0.4500', 112]),
  ('variant scenario 1', ([['2.93', 'void'], ['1.52', 'half-win']], 100), ['1.2600', 126]),
  ('variant scenario 2',
   ([['2.95', 'win'], ['1.34', 'win'], ['2.38', 'lose'], ['2.73', 'win']], 1000),
   ['0.0000', 0])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half lose factor',
   ([['3.95', 'win'], ['2.15', 'half-lose'], ['2.45', 'half-lose']], 333),
   ['0.9875', 328]),
  ('variant scenario 1',
   ([['2.16', 'lose'], ['2.15', 'void'], ['2.36', 'half-win'], ['2.29', 'win']], 1000),
   ['0.0000', 0]),
  ('variant scenario 2', ([['1.39', 'void'], ['1.88', 'win']], 1000), ['1.8800', 1880])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half lose factor',
   ([['3.23', 'void'], ['1.78', 'half-lose'], ['1.60', 'win'], ['3.77', 'win']], 1999),
   ['3.0160', 6028]),
  ('variant scenario 1',
   ([['2.85', 'lose'], ['2.07', 'half-lose'], ['3.95', 'push'], ['2.78', 'void'], ['2.40', 'void']],
    250),
   ['0.0000', 0]),
  ('variant scenario 2',
   ([['3.61', 'lose'],
     ['3.42', 'half-lose'],
     ['2.22', 'half-win'],
     ['2.00', 'win'],
     ['3.00', 'win']],
    100),
   ['0.0000', 0])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half lose factor',
   ([['1.55', 'half-lose'], ['2.82', 'push'], ['2.89', 'half-win']], 1999),
   ['0.9725', 1944]),
  ('variant scenario 1',
   ([['2.72', 'half-win'],
     ['2.70', 'push'],
     ['3.02', 'lose'],
     ['1.59', 'half-lose'],
     ['1.30', 'half-lose']],
    250),
   ['0.0000', 0]),
  ('variant scenario 2',
   ([['3.97', 'lose'],
     ['2.37', 'half-lose'],
     ['3.46', 'half-win'],
     ['1.36', 'win'],
     ['2.04', 'half-lose']],
    1999),
   ['0.0000', 0])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half lose factor',
   ([['3.21', 'half-win'], ['2.12', 'win'], ['1.45', 'half-lose']], 333),
   ['2.2313', 743]),
  ('variant scenario 1',
   ([['3.09', 'half-lose'], ['2.98', 'lose'], ['3.93', 'win'], ['1.31', 'win'], ['1.54', 'win']],
    1000),
   ['0.0000', 0]),
  ('variant scenario 2', ([['2.51', 'win'], ['1.25', 'lose']], 333), ['0.0000', 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:
A half-lost Asian leg kills the parlay, or is ignored.

Accumulator settlement. legs rows are [decimal price, result] with results win, lose, push, void, half-win (half the stake wins at the price, half is refunded: factor (1 + d) / 2) and half-lose (half refunded: factor 1/2). push and void legs have factor 1, win factor d, lose makes the whole bet lose. Return [combined factor rounded half up to four decimals as a string, payout in cents rounded down].

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):
    factor = Fraction(1)
    for price, result in legs:
        d = Fraction(price)
        if result == 'lose':
            factor = Fraction(0)
            break
        if result == 'win':
            factor *= d
        elif result == 'half-win':
            factor *= (1 + d) / 2
        elif result == 'half-lose':
            factor *= Fraction(1, 2)
    q = math.floor(factor * 10000 + Fraction(1, 2))
    return ['%d.%04d' % (q // 10000, q % 10000), round(stake_cents * factor)]
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 two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: payout rounding',
   ([['1.54', 'half-win'],
     ['2.44', 'win'],
     ['1.51', 'half-win'],
     ['3.53', 'push'],
     ['3.61', 'win']],
    100),
   ['14.0393', 1403]),
  ('variant scenario 1',
   ([['3.83', 'half-win'], ['1.67', 'lose'], ['2.67', 'push']], 1999),
   ['0.0000', 0]),
  ('variant scenario 2',
   ([['2.18', 'void'], ['2.39', 'lose'], ['1.73', 'win'], ['2.99', 'push'], ['2.32', 'half-win']],
    333),
   ['0.0000', 0])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: payout rounding', ([['3.50', 'half-win'], ['1.78', 'win']], 100), ['4.0050', 400]),
  ('regression: payout rounding',
   ([['3.52', 'win'],
     ['3.90', 'half-win'],
     ['2.23', 'void'],
     ['3.23', 'half-lose'],
     ['2.62', 'win']],
    1999),
   ['11.2974', 22583]),
  ('variant scenario 1',
   ([['2.37', 'half-win'], ['1.31', 'half-win'], ['1.84', 'lose']], 1000),
   ['0.0000', 0]),
  ('variant scenario 2', ([['3.39', 'void'], ['1.92', 'win']], 100), ['1.9200', 192])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: payout rounding', ([['3.61', 'half-win'], ['1.35', 'win']], 333), ['3.1118', 1036]),
  ('regression: payout rounding',
   ([['3.54', 'win'], ['2.46', 'push'], ['1.36', 'void'], ['2.75', 'win'], ['1.79', 'win']], 1999),
   ['17.4257', 34833]),
  ('variant scenario 1',
   ([['2.60', 'void'], ['2.23', 'win'], ['1.68', 'lose'], ['1.96', 'half-win'], ['1.91', 'win']],
    1000),
   ['0.0000', 0]),
  ('variant scenario 2',
   ([['1.22', 'push'], ['2.49', 'void'], ['3.59', 'push'], ['3.59', 'lose']], 250),
   ['0.0000', 0])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: payout rounding',
   ([['2.42', 'win'], ['3.10', 'win'], ['1.90', 'win']], 1000),
   ['14.2538', 14253]),
  ('variant scenario 1',
   ([['3.57', 'half-win'], ['2.67', 'win'], ['1.31', 'win'], ['2.06', 'push'], ['2.36', 'win']],
    1000),
   ['18.8617', 18861]),
  ('variant scenario 2', ([['1.21', 'win'], ['3.54', 'win']], 100), ['4.2834', 428])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: payout rounding',
   ([['3.86', 'half-lose'], ['3.17', 'push'], ['2.09', 'void']], 1999),
   ['0.5000', 999]),
  ('variant scenario 1',
   ([['2.72', 'void'],
     ['3.77', 'half-win'],
     ['2.12', 'win'],
     ['1.39', 'lose'],
     ['2.98', 'half-win']],
    1999),
   ['0.0000', 0]),
  ('variant scenario 2',
   ([['3.07', 'half-win'], ['2.59', 'lose'], ['1.62', 'lose']], 250),
   ['0.0000', 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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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):
    factor = Fraction(1)
    for price, result in legs:
        d = Fraction(price)
        if result == 'lose':
            factor = Fraction(0)
            break
        if result == 'win':
            factor *= d
        elif result == 'half-win':
            factor *= (1 + d) / 2
        elif result == 'half-lose':
            factor *= Fraction(1, 2)
    q = math.floor(factor * 10000 + Fraction(1, 2))
    return ['%d.%04d' % (q // 10000, q % 10000), math.ceil(stake_cents * factor)]
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 two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: payout rounding',
   ([['1.54', 'half-win'],
     ['2.44', 'win'],
     ['1.51', 'half-win'],
     ['3.53', 'push'],
     ['3.61', 'win']],
    100),
   ['14.0393', 1403]),
  ('variant scenario 1',
   ([['3.83', 'half-win'], ['1.67', 'lose'], ['2.67', 'push']], 1999),
   ['0.0000', 0]),
  ('variant scenario 2',
   ([['2.18', 'void'], ['2.39', 'lose'], ['1.73', 'win'], ['2.99', 'push'], ['2.32', 'half-win']],
    333),
   ['0.0000', 0])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: payout rounding', ([['3.50', 'half-win'], ['1.78', 'win']], 100), ['4.0050', 400]),
  ('regression: payout rounding',
   ([['3.52', 'win'],
     ['3.90', 'half-win'],
     ['2.23', 'void'],
     ['3.23', 'half-lose'],
     ['2.62', 'win']],
    1999),
   ['11.2974', 22583]),
  ('variant scenario 1',
   ([['2.37', 'half-win'], ['1.31', 'half-win'], ['1.84', 'lose']], 1000),
   ['0.0000', 0]),
  ('variant scenario 2', ([['3.39', 'void'], ['1.92', 'win']], 100), ['1.9200', 192])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: payout rounding', ([['3.61', 'half-win'], ['1.35', 'win']], 333), ['3.1118', 1036]),
  ('regression: payout rounding',
   ([['3.54', 'win'], ['2.46', 'push'], ['1.36', 'void'], ['2.75', 'win'], ['1.79', 'win']], 1999),
   ['17.4257', 34833]),
  ('variant scenario 1',
   ([['2.60', 'void'], ['2.23', 'win'], ['1.68', 'lose'], ['1.96', 'half-win'], ['1.91', 'win']],
    1000),
   ['0.0000', 0]),
  ('variant scenario 2',
   ([['1.22', 'push'], ['2.49', 'void'], ['3.59', 'push'], ['3.59', 'lose']], 250),
   ['0.0000', 0])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: payout rounding',
   ([['2.42', 'win'], ['3.10', 'win'], ['1.90', 'win']], 1000),
   ['14.2538', 14253]),
  ('variant scenario 1',
   ([['3.57', 'half-win'], ['2.67', 'win'], ['1.31', 'win'], ['2.06', 'push'], ['2.36', 'win']],
    1000),
   ['18.8617', 18861]),
  ('variant scenario 2', ([['1.21', 'win'], ['3.54', 'win']], 100), ['4.2834', 428])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: payout rounding',
   ([['3.86', 'half-lose'], ['3.17', 'push'], ['2.09', 'void']], 1999),
   ['0.5000', 999]),
  ('variant scenario 1',
   ([['2.72', 'void'],
     ['3.77', 'half-win'],
     ['2.12', 'win'],
     ['1.39', 'lose'],
     ['2.98', 'half-win']],
    1999),
   ['0.0000', 0]),
  ('variant scenario 2',
   ([['3.07', 'half-win'], ['2.59', 'lose'], ['1.62', 'lose']], 250),
   ['0.0000', 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:
Fractional-cent payouts are rounded up, overpaying the customer.

Accumulator settlement. legs rows are [decimal price, result] with results win, lose, push, void, half-win (half the stake wins at the price, half is refunded: factor (1 + d) / 2) and half-lose (half refunded: factor 1/2). push and void legs have factor 1, win factor d, lose makes the whole bet lose. Return [combined factor rounded half up to four decimals as a string, payout in cents rounded down].

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(stake_cents, odds, terms, position, places_paid, dead_heat):
    a, b = map(int, odds.split('/'))
    f = Fraction(a, b)
    tn, td = map(int, terms.split('/'))
    place_f = f * Fraction(tn, td)
    ret = Fraction(0)
    if position == 1:
        ret += Fraction(stake_cents, dead_heat) * (1 + f)
    if position <= places_paid:
        share = Fraction(min(dead_heat, places_paid - position + 1), dead_heat)
        ret += stake_cents * share * (1 + f) * Fraction(tn, td)
    return 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 winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place odds fraction', (100, '14/5', '1/5', 4, 4, 1), 156),
  ('variant scenario 1', (100, '8/4', '1/4', 6, 5, 2), 0),
  ('variant scenario 2', (100, '6/2', '1/5', 1, 2, 2), 360)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place odds fraction', (1000, '7/4', '1/4', 2, 4, 1), 1437),
  ('variant scenario 1', (500, '26/5', '1/5', 3, 5, 3), 1020),
  ('variant scenario 2', (500, '18/1', '1/5', 2, 3, 1), 2300)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place odds fraction', (500, '15/1', '1/5', 2, 4, 2), 2000),
  ('variant scenario 1', (500, '10/1', '1/5', 3, 2, 1), 0),
  ('variant scenario 2', (250, '10/2', '1/4', 5, 5, 1), 562)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place odds fraction', (100, '27/1', '1/4', 5, 5, 1), 775),
  ('variant scenario 1', (250, '3/4', '1/4', 3, 2, 1), 0),
  ('variant scenario 2', (1000, '18/5', '1/4', 4, 5, 2), 1900)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place odds fraction', (500, '17/1', '1/5', 4, 4, 1), 2200),
  ('variant scenario 1', (1000, '22/1', '1/4', 5, 4, 1), 0),
  ('variant scenario 2', (100, '20/5', '1/5', 1, 4, 2), 430)]]
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(stake_cents, odds, terms, position, places_paid, dead_heat):
    a, b = map(int, odds.split('/'))
    f = Fraction(a, b)
    tn, td = map(int, terms.split('/'))
    place_f = f * Fraction(tn, td)
    ret = Fraction(0)
    if position == 1:
        ret += Fraction(stake_cents, dead_heat) * (1 + f)
    if position <= places_paid:
        share = Fraction(min(dead_heat, places_paid - position + 1), dead_heat)
        ret += stake_cents * share * place_f
    return 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 winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place odds fraction', (100, '14/5', '1/5', 4, 4, 1), 156),
  ('variant scenario 1', (100, '8/4', '1/4', 6, 5, 2), 0),
  ('variant scenario 2', (100, '6/2', '1/5', 1, 2, 2), 360)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place odds fraction', (1000, '7/4', '1/4', 2, 4, 1), 1437),
  ('variant scenario 1', (500, '26/5', '1/5', 3, 5, 3), 1020),
  ('variant scenario 2', (500, '18/1', '1/5', 2, 3, 1), 2300)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place odds fraction', (500, '15/1', '1/5', 2, 4, 2), 2000),
  ('variant scenario 1', (500, '10/1', '1/5', 3, 2, 1), 0),
  ('variant scenario 2', (250, '10/2', '1/4', 5, 5, 1), 562)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place odds fraction', (100, '27/1', '1/4', 5, 5, 1), 775),
  ('variant scenario 1', (250, '3/4', '1/4', 3, 2, 1), 0),
  ('variant scenario 2', (1000, '18/5', '1/4', 4, 5, 2), 1900)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place odds fraction', (500, '17/1', '1/5', 4, 4, 1), 2200),
  ('variant scenario 1', (1000, '22/1', '1/4', 5, 4, 1), 0),
  ('variant scenario 2', (100, '20/5', '1/5', 1, 4, 2), 430)]]
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:
Placed each-way bets return a fraction of the stake instead of stake plus place winnings.

Each-way settlement with dead heats. stake_cents is the stake of each part (win and place). odds is fractional "a/b"; terms "1/4" or "1/5" is the place fraction of the odds. position is the finishing position shared by dead_heat runners (1 = no dead heat), occupying positions position .. position + dead_heat - 1. Win part: paid if position == 1 with stake / dead_heat at 1 + a/b. Place part: paid if position <= places_paid, with stake scaled by min(dead_heat, places_paid - position + 1) / dead_heat at 1 + (a/b) * terms. Return the total return in cents rounded down.

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(stake_cents, odds, terms, position, places_paid, dead_heat):
    a, b = map(int, odds.split('/'))
    f = Fraction(a, b)
    tn, td = map(int, terms.split('/'))
    place_f = f * Fraction(tn, td)
    ret = Fraction(0)
    if position == 1:
        ret += stake_cents * (1 + f)
    if position <= places_paid:
        share = Fraction(min(dead_heat, places_paid - position + 1), dead_heat)
        ret += stake_cents * share * (1 + place_f)
    return 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 winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: win dead heat', (1000, '4/4', '1/4', 1, 2, 2), 2250),
  ('variant scenario 1', (250, '10/5', '1/4', 2, 3, 2), 375),
  ('variant scenario 2', (250, '19/4', '1/5', 1, 2, 1), 1925)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: win dead heat', (1000, '18/2', '1/5', 1, 5, 3), 6133),
  ('variant scenario 1', (100, '9/4', '1/4', 4, 5, 1), 156),
  ('variant scenario 2', (100, '31/5', '1/5', 4, 5, 1), 224)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: win dead heat', (1000, '23/4', '1/5', 1, 5, 2), 5525),
  ('variant scenario 1', (1000, '10/2', '1/5', 5, 5, 1), 2000),
  ('variant scenario 2', (100, '11/2', '1/5', 5, 3, 1), 0)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: win dead heat', (250, '20/1', '1/5', 1, 3, 2), 3875),
  ('variant scenario 1', (500, '5/1', '1/5', 2, 5, 2), 1000),
  ('variant scenario 2', (100, '16/2', '1/4', 4, 4, 1), 300)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: win dead heat', (100, '9/1', '1/4', 1, 2, 3), 550),
  ('variant scenario 1', (1000, '10/1', '1/4', 2, 3, 1), 3500),
  ('variant scenario 2', (1000, '18/5', '1/4', 5, 3, 2), 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(stake_cents, odds, terms, position, places_paid, dead_heat):
    a, b = map(int, odds.split('/'))
    f = Fraction(a, b)
    tn, td = map(int, terms.split('/'))
    place_f = f * Fraction(tn, td)
    ret = Fraction(0)
    if position == 1:
        ret += stake_cents * (1 + f / dead_heat)
    if position <= places_paid:
        share = Fraction(min(dead_heat, places_paid - position + 1), dead_heat)
        ret += stake_cents * share * (1 + place_f)
    return 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 winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: win dead heat', (1000, '4/4', '1/4', 1, 2, 2), 2250),
  ('variant scenario 1', (250, '10/5', '1/4', 2, 3, 2), 375),
  ('variant scenario 2', (250, '19/4', '1/5', 1, 2, 1), 1925)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: win dead heat', (1000, '18/2', '1/5', 1, 5, 3), 6133),
  ('variant scenario 1', (100, '9/4', '1/4', 4, 5, 1), 156),
  ('variant scenario 2', (100, '31/5', '1/5', 4, 5, 1), 224)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: win dead heat', (1000, '23/4', '1/5', 1, 5, 2), 5525),
  ('variant scenario 1', (1000, '10/2', '1/5', 5, 5, 1), 2000),
  ('variant scenario 2', (100, '11/2', '1/5', 5, 3, 1), 0)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: win dead heat', (250, '20/1', '1/5', 1, 3, 2), 3875),
  ('variant scenario 1', (500, '5/1', '1/5', 2, 5, 2), 1000),
  ('variant scenario 2', (100, '16/2', '1/4', 4, 4, 1), 300)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: win dead heat', (100, '9/1', '1/4', 1, 2, 3), 550),
  ('variant scenario 1', (1000, '10/1', '1/4', 2, 3, 1), 3500),
  ('variant scenario 2', (1000, '18/5', '1/4', 5, 3, 2), 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:
A dead-heated winner is paid as a solo winner.

Each-way settlement with dead heats. stake_cents is the stake of each part (win and place). odds is fractional "a/b"; terms "1/4" or "1/5" is the place fraction of the odds. position is the finishing position shared by dead_heat runners (1 = no dead heat), occupying positions position .. position + dead_heat - 1. Win part: paid if position == 1 with stake / dead_heat at 1 + a/b. Place part: paid if position <= places_paid, with stake scaled by min(dead_heat, places_paid - position + 1) / dead_heat at 1 + (a/b) * terms. Return the total return in cents rounded down.

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(stake_cents, odds, terms, position, places_paid, dead_heat):
    a, b = map(int, odds.split('/'))
    f = Fraction(a, b)
    tn, td = map(int, terms.split('/'))
    place_f = f * Fraction(tn, td)
    ret = Fraction(0)
    if position == 1:
        ret += Fraction(stake_cents, dead_heat) * (1 + f)
    if position <= places_paid:
        share = Fraction(1, dead_heat)
        ret += stake_cents * share * (1 + place_f)
    return 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 winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place dead heat share', (250, '4/2', '1/4', 3, 3, 2), 187),
  ('regression: place dead heat share', (100, '8/2', '1/5', 4, 5, 2), 180),
  ('variant scenario 1', (500, '6/1', '1/5', 2, 2, 1), 1100),
  ('variant scenario 2', (100, '21/2', '1/4', 4, 2, 1), 0)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place dead heat share', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('regression: place dead heat share', (500, '28/1', '1/4', 3, 3, 2), 2000),
  ('variant scenario 1', (1000, '25/2', '1/5', 4, 2, 2), 0),
  ('variant scenario 2', (1000, '22/5', '1/5', 6, 4, 3), 0)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place dead heat share', (500, '27/5', '1/4', 4, 4, 2), 587),
  ('regression: place dead heat share', (1000, '5/1', '1/5', 1, 5, 3), 4000),
  ('variant scenario 1', (1000, '18/5', '1/5', 2, 4, 1), 1720),
  ('variant scenario 2', (500, '16/1', '1/5', 1, 3, 1), 10600)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place dead heat share', (250, '15/1', '1/4', 1, 5, 2), 3187),
  ('regression: place dead heat share', (500, '18/2', '1/5', 2, 2, 2), 700),
  ('variant scenario 1', (100, '1/2', '1/5', 2, 2, 1), 110),
  ('variant scenario 2', (250, '17/4', '1/4', 3, 3, 1), 515)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place dead heat share', (1000, '2/5', '1/4', 1, 3, 2), 1800),
  ('regression: place dead heat share', (100, '18/4', '1/5', 4, 5, 3), 126),
  ('variant scenario 1', (250, '26/1', '1/5', 1, 3, 2), 4925),
  ('variant scenario 2', (1000, '21/1', '1/5', 2, 4, 3), 5200)]]
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(stake_cents, odds, terms, position, places_paid, dead_heat):
    a, b = map(int, odds.split('/'))
    f = Fraction(a, b)
    tn, td = map(int, terms.split('/'))
    place_f = f * Fraction(tn, td)
    ret = Fraction(0)
    if position == 1:
        ret += Fraction(stake_cents, dead_heat) * (1 + f)
    if position <= places_paid:
        share = Fraction(1)
        ret += stake_cents * share * (1 + place_f)
    return 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 winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place dead heat share', (250, '4/2', '1/4', 3, 3, 2), 187),
  ('regression: place dead heat share', (100, '8/2', '1/5', 4, 5, 2), 180),
  ('variant scenario 1', (500, '6/1', '1/5', 2, 2, 1), 1100),
  ('variant scenario 2', (100, '21/2', '1/4', 4, 2, 1), 0)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place dead heat share', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('regression: place dead heat share', (500, '28/1', '1/4', 3, 3, 2), 2000),
  ('variant scenario 1', (1000, '25/2', '1/5', 4, 2, 2), 0),
  ('variant scenario 2', (1000, '22/5', '1/5', 6, 4, 3), 0)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place dead heat share', (500, '27/5', '1/4', 4, 4, 2), 587),
  ('regression: place dead heat share', (1000, '5/1', '1/5', 1, 5, 3), 4000),
  ('variant scenario 1', (1000, '18/5', '1/5', 2, 4, 1), 1720),
  ('variant scenario 2', (500, '16/1', '1/5', 1, 3, 1), 10600)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place dead heat share', (250, '15/1', '1/4', 1, 5, 2), 3187),
  ('regression: place dead heat share', (500, '18/2', '1/5', 2, 2, 2), 700),
  ('variant scenario 1', (100, '1/2', '1/5', 2, 2, 1), 110),
  ('variant scenario 2', (250, '17/4', '1/4', 3, 3, 1), 515)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place dead heat share', (1000, '2/5', '1/4', 1, 3, 2), 1800),
  ('regression: place dead heat share', (100, '18/4', '1/5', 4, 5, 3), 126),
  ('variant scenario 1', (250, '26/1', '1/5', 1, 3, 2), 4925),
  ('variant scenario 2', (1000, '21/1', '1/5', 2, 4, 3), 5200)]]
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:
Runners dead-heating for a place fully inside the places are cut, or those straddling the last place are not.

Each-way settlement with dead heats. stake_cents is the stake of each part (win and place). odds is fractional "a/b"; terms "1/4" or "1/5" is the place fraction of the odds. position is the finishing position shared by dead_heat runners (1 = no dead heat), occupying positions position .. position + dead_heat - 1. Win part: paid if position == 1 with stake / dead_heat at 1 + a/b. Place part: paid if position <= places_paid, with stake scaled by min(dead_heat, places_paid - position + 1) / dead_heat at 1 + (a/b) * terms. Return the total return in cents rounded down.

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(stake_cents, odds, terms, position, places_paid, dead_heat):
    a, b = map(int, odds.split('/'))
    f = Fraction(a, b)
    tn, td = map(int, terms.split('/'))
    place_f = f * Fraction(tn, td)
    ret = Fraction(0)
    if position == 1:
        ret += Fraction(stake_cents, dead_heat) * (1 + f)
    if position < places_paid:
        share = Fraction(min(dead_heat, places_paid - position + 1), dead_heat)
        ret += stake_cents * share * (1 + place_f)
    return 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 winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place eligibility', (250, '14/2', '1/5', 1, 4, 2), 1600),
  ('regression: place eligibility', (1000, '1/5', '1/4', 2, 2, 3), 350),
  ('variant scenario 1', (250, '2/5', '1/4', 3, 4, 3), 183),
  ('variant scenario 2', (100, '27/1', '1/5', 1, 4, 2), 2040)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place eligibility', (250, '16/1', '1/5', 1, 2, 1), 5300),
  ('regression: place eligibility', (250, '17/1', '1/5', 3, 3, 2), 550),
  ('variant scenario 1', (250, '19/2', '1/5', 2, 5, 2), 725),
  ('variant scenario 2', (250, '21/5', '1/5', 2, 5, 3), 460)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place eligibility', (250, '10/2', '1/4', 1, 3, 1), 2062),
  ('regression: place eligibility', (1000, '1/1', '1/4', 2, 2, 2), 625),
  ('variant scenario 1', (100, '24/1', '1/4', 3, 2, 3), 0),
  ('variant scenario 2', (100, '2/2', '1/5', 4, 3, 2), 0)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place eligibility', (500, '18/1', '1/5', 1, 4, 2), 7050),
  ('regression: place eligibility', (250, '11/1', '1/5', 3, 3, 1), 800),
  ('variant scenario 1', (250, '28/5', '1/4', 3, 2, 1), 0),
  ('variant scenario 2', (250, '31/4', '1/5', 2, 4, 3), 637)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place eligibility', (1000, '15/2', '1/5', 1, 4, 3), 5333),
  ('regression: place eligibility', (250, '29/1', '1/5', 2, 2, 1), 1700),
  ('variant scenario 1', (500, '19/5', '1/5', 2, 4, 1), 880),
  ('variant scenario 2', (500, '33/1', '1/4', 3, 5, 3), 4625)]]
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(stake_cents, odds, terms, position, places_paid, dead_heat):
    a, b = map(int, odds.split('/'))
    f = Fraction(a, b)
    tn, td = map(int, terms.split('/'))
    place_f = f * Fraction(tn, td)
    ret = Fraction(0)
    if position == 1:
        ret += Fraction(stake_cents, dead_heat) * (1 + f)
    if 1 < position <= places_paid:
        share = Fraction(min(dead_heat, places_paid - position + 1), dead_heat)
        ret += stake_cents * share * (1 + place_f)
    return 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 winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place eligibility', (250, '14/2', '1/5', 1, 4, 2), 1600),
  ('regression: place eligibility', (1000, '1/5', '1/4', 2, 2, 3), 350),
  ('variant scenario 1', (250, '2/5', '1/4', 3, 4, 3), 183),
  ('variant scenario 2', (100, '27/1', '1/5', 1, 4, 2), 2040)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place eligibility', (250, '16/1', '1/5', 1, 2, 1), 5300),
  ('regression: place eligibility', (250, '17/1', '1/5', 3, 3, 2), 550),
  ('variant scenario 1', (250, '19/2', '1/5', 2, 5, 2), 725),
  ('variant scenario 2', (250, '21/5', '1/5', 2, 5, 3), 460)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place eligibility', (250, '10/2', '1/4', 1, 3, 1), 2062),
  ('regression: place eligibility', (1000, '1/1', '1/4', 2, 2, 2), 625),
  ('variant scenario 1', (100, '24/1', '1/4', 3, 2, 3), 0),
  ('variant scenario 2', (100, '2/2', '1/5', 4, 3, 2), 0)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place eligibility', (500, '18/1', '1/5', 1, 4, 2), 7050),
  ('regression: place eligibility', (250, '11/1', '1/5', 3, 3, 1), 800),
  ('variant scenario 1', (250, '28/5', '1/4', 3, 2, 1), 0),
  ('variant scenario 2', (250, '31/4', '1/5', 2, 4, 3), 637)],
 [('control winner', (1000, '4/1', '1/4', 1, 3, 1), 7000),
  ('control placed', (1000, '4/1', '1/4', 2, 3, 1), 2000),
  ('control unplaced', (1000, '4/1', '1/4', 4, 3, 1), 0),
  ('boundary dead heat for the win', (1000, '4/1', '1/5', 1, 3, 2), 4300),
  ('boundary dead heat for last place', (1000, '10/1', '1/5', 3, 3, 2), 1500),
  ('regression: place eligibility', (1000, '15/2', '1/5', 1, 4, 3), 5333),
  ('regression: place eligibility', (250, '29/1', '1/5', 2, 2, 1), 1700),
  ('variant scenario 1', (500, '19/5', '1/5', 2, 4, 1), 880),
  ('variant scenario 2', (500, '33/1', '1/4', 3, 5, 3), 4625)]]
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:
The winner of an each-way bet receives only the win part, or the last paying place is missed.

Each-way settlement with dead heats. stake_cents is the stake of each part (win and place). odds is fractional "a/b"; terms "1/4" or "1/5" is the place fraction of the odds. position is the finishing position shared by dead_heat runners (1 = no dead heat), occupying positions position .. position + dead_heat - 1. Win part: paid if position == 1 with stake / dead_heat at 1 + a/b. Place part: paid if position <= places_paid, with stake scaled by min(dead_heat, places_paid - position + 1) / dead_heat at 1 + (a/b) * terms. Return the total return in cents rounded down.

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(line, home_goals, away_goals, stake_cents, price):
    L = Fraction(line)
    if (L * 4).denominator != 1:
        return 'invalid line'
    if (L * 2).denominator == 1:
        parts = [L]
    else:
        parts = [L - Fraction(1, 2), L + Fraction(1, 2)]
    d = Fraction(price)
    share = Fraction(stake_cents, len(parts))
    ret = Fraction(0)
    res = []
    for p in parts:
        m = home_goals - away_goals + p
        if m > 0:
            ret += share * d
            res.append(1)
        elif m == 0:
            ret += share
            res.append(0)
        else:
            res.append(-1)
    score = sum(res) * 2 // len(parts)
    label = {2: 'win', 1: 'half-win', 0: 'push', -1: 'half-lose', -2: 'lose'}[score]
    return [math.floor(ret), label]
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 half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: quarter split offsets', ('-1.75', 4, 2, 500, '2.00'), [750, 'half-win']),
  ('variant scenario 1', ('-0.75', 3, 1, 250, '2.00'), [500, 'win']),
  ('variant scenario 2', ('+0.75', 4, 1, 250, '2.05'), [512, 'win'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: quarter split offsets', ('-0.25', 2, 2, 999, '2.00'), [499, 'half-lose']),
  ('regression: quarter split offsets', ('+1.25', 3, 4, 500, '2.05'), [762, 'half-win']),
  ('variant scenario 1', ('0', 3, 3, 999, '2.05'), [999, 'push']),
  ('variant scenario 2', ('-0.5', 3, 1, 500, '2.00'), [1000, 'win'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: quarter split offsets', ('+1.25', 2, 3, 500, '2.00'), [750, 'half-win']),
  ('variant scenario 1', ('-1.5', 2, 2, 500, '1.85'), [0, 'lose']),
  ('variant scenario 2', ('+2', 4, 1, 999, '2.05'), [2047, 'win'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: quarter split offsets', ('-0.75', 4, 3, 500, '2.00'), [750, 'half-win']),
  ('variant scenario 1', ('+0.25', 3, 0, 999, '2.05'), [2047, 'win']),
  ('variant scenario 2', ('-1.5', 3, 3, 500, '2.00'), [0, 'lose'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: quarter split offsets', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('variant scenario 1', ('+0.5', 1, 3, 999, '2.00'), [0, 'lose']),
  ('variant scenario 2', ('+2', 1, 1, 250, '2.05'), [512, 'win'])]]
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(line, home_goals, away_goals, stake_cents, price):
    L = Fraction(line)
    if (L * 4).denominator != 1:
        return 'invalid line'
    if (L * 2).denominator == 1:
        parts = [L]
    else:
        parts = [L, L + Fraction(1, 4)]
    d = Fraction(price)
    share = Fraction(stake_cents, len(parts))
    ret = Fraction(0)
    res = []
    for p in parts:
        m = home_goals - away_goals + p
        if m > 0:
            ret += share * d
            res.append(1)
        elif m == 0:
            ret += share
            res.append(0)
        else:
            res.append(-1)
    score = sum(res) * 2 // len(parts)
    label = {2: 'win', 1: 'half-win', 0: 'push', -1: 'half-lose', -2: 'lose'}[score]
    return [math.floor(ret), label]
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 half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: quarter split offsets', ('-1.75', 4, 2, 500, '2.00'), [750, 'half-win']),
  ('variant scenario 1', ('-0.75', 3, 1, 250, '2.00'), [500, 'win']),
  ('variant scenario 2', ('+0.75', 4, 1, 250, '2.05'), [512, 'win'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: quarter split offsets', ('-0.25', 2, 2, 999, '2.00'), [499, 'half-lose']),
  ('regression: quarter split offsets', ('+1.25', 3, 4, 500, '2.05'), [762, 'half-win']),
  ('variant scenario 1', ('0', 3, 3, 999, '2.05'), [999, 'push']),
  ('variant scenario 2', ('-0.5', 3, 1, 500, '2.00'), [1000, 'win'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: quarter split offsets', ('+1.25', 2, 3, 500, '2.00'), [750, 'half-win']),
  ('variant scenario 1', ('-1.5', 2, 2, 500, '1.85'), [0, 'lose']),
  ('variant scenario 2', ('+2', 4, 1, 999, '2.05'), [2047, 'win'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: quarter split offsets', ('-0.75', 4, 3, 500, '2.00'), [750, 'half-win']),
  ('variant scenario 1', ('+0.25', 3, 0, 999, '2.05'), [2047, 'win']),
  ('variant scenario 2', ('-1.5', 3, 3, 500, '2.00'), [0, 'lose'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: quarter split offsets', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('variant scenario 1', ('+0.5', 1, 3, 999, '2.00'), [0, 'lose']),
  ('variant scenario 2', ('+2', 1, 1, 250, '2.05'), [512, 'win'])]]
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 -0.25 bet on a draw is settled as a full loss or a full push.

Asian handicap bet on the home side. line is a multiple of 0.25 (else "invalid line"). Whole and half lines are a single bet; quarter lines split the stake equally between line - 0.25 and line + 0.25. Each part: margin = home_goals - away_goals + part_line; positive wins stake_part * price, zero refunds stake_part, negative loses. Return [total return in cents rounded down, label] where the label is win, half-win, push, half-lose or lose from the summed part outcomes.

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(line, home_goals, away_goals, stake_cents, price):
    L = Fraction(line)
    if (L * 4).denominator != 1:
        return 'invalid line'
    if (L * 2).denominator == 1:
        parts = [L]
    else:
        parts = [L - Fraction(1, 4), L + Fraction(1, 4)]
    d = Fraction(price)
    share = Fraction(stake_cents)
    ret = Fraction(0)
    res = []
    for p in parts:
        m = home_goals - away_goals + p
        if m > 0:
            ret += share * d
            res.append(1)
        elif m == 0:
            ret += share
            res.append(0)
        else:
            res.append(-1)
    score = sum(res) * 2 // len(parts)
    label = {2: 'win', 1: 'half-win', 0: 'push', -1: 'half-lose', -2: 'lose'}[score]
    return [math.floor(ret), label]
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 half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: split stake share', ('-0.25', 3, 2, 250, '2.00'), [500, 'win']),
  ('regression: split stake share', ('0', 3, 3, 1000, '2.05'), [1000, 'push']),
  ('variant scenario 1', ('-1.75', 4, 0, 1000, '2.00'), [2000, 'win']),
  ('variant scenario 2', ('-0.75', 2, 4, 500, '2.00'), [0, 'lose'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: split stake share', ('-0.5', 4, 0, 999, '1.90'), [1898, 'win']),
  ('regression: split stake share', ('+0.25', 3, 3, 1000, '2.00'), [1500, 'half-win']),
  ('variant scenario 1', ('-0.3', 3, 3, 250, '1.90'), 'invalid line'),
  ('variant scenario 2', ('+0.75', 1, 3, 1000, '1.90'), [0, 'lose'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: split stake share', ('+0.75', 4, 0, 250, '2.00'), [500, 'win']),
  ('regression: split stake share', ('+0.5', 2, 0, 999, '2.00'), [1998, 'win']),
  ('variant scenario 1', ('-1', 0, 2, 999, '2.00'), [0, 'lose']),
  ('variant scenario 2', ('+0.25', 1, 0, 250, '1.85'), [462, 'win'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: split stake share', ('+0.5', 4, 1, 250, '1.90'), [475, 'win']),
  ('regression: split stake share', ('+0.25', 3, 2, 1000, '1.85'), [1850, 'win']),
  ('variant scenario 1', ('+2', 1, 4, 500, '1.90'), [0, 'lose']),
  ('variant scenario 2', ('+0.75', 0, 4, 1000, '2.05'), [0, 'lose'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: split stake share', ('+1.25', 1, 0, 500, '1.85'), [925, 'win']),
  ('regression: split stake share', ('0', 2, 0, 250, '1.90'), [475, 'win']),
  ('variant scenario 1', ('-1.75', 2, 0, 999, '2.00'), [1498, 'half-win']),
  ('variant scenario 2', ('-0.3', 2, 4, 1000, '2.00'), 'invalid line')]]
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(line, home_goals, away_goals, stake_cents, price):
    L = Fraction(line)
    if (L * 4).denominator != 1:
        return 'invalid line'
    if (L * 2).denominator == 1:
        parts = [L]
    else:
        parts = [L - Fraction(1, 4), L + Fraction(1, 4)]
    d = Fraction(price)
    share = Fraction(stake_cents, 2)
    ret = Fraction(0)
    res = []
    for p in parts:
        m = home_goals - away_goals + p
        if m > 0:
            ret += share * d
            res.append(1)
        elif m == 0:
            ret += share
            res.append(0)
        else:
            res.append(-1)
    score = sum(res) * 2 // len(parts)
    label = {2: 'win', 1: 'half-win', 0: 'push', -1: 'half-lose', -2: 'lose'}[score]
    return [math.floor(ret), label]
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 half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: split stake share', ('-0.25', 3, 2, 250, '2.00'), [500, 'win']),
  ('regression: split stake share', ('0', 3, 3, 1000, '2.05'), [1000, 'push']),
  ('variant scenario 1', ('-1.75', 4, 0, 1000, '2.00'), [2000, 'win']),
  ('variant scenario 2', ('-0.75', 2, 4, 500, '2.00'), [0, 'lose'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: split stake share', ('-0.5', 4, 0, 999, '1.90'), [1898, 'win']),
  ('regression: split stake share', ('+0.25', 3, 3, 1000, '2.00'), [1500, 'half-win']),
  ('variant scenario 1', ('-0.3', 3, 3, 250, '1.90'), 'invalid line'),
  ('variant scenario 2', ('+0.75', 1, 3, 1000, '1.90'), [0, 'lose'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: split stake share', ('+0.75', 4, 0, 250, '2.00'), [500, 'win']),
  ('regression: split stake share', ('+0.5', 2, 0, 999, '2.00'), [1998, 'win']),
  ('variant scenario 1', ('-1', 0, 2, 999, '2.00'), [0, 'lose']),
  ('variant scenario 2', ('+0.25', 1, 0, 250, '1.85'), [462, 'win'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: split stake share', ('+0.5', 4, 1, 250, '1.90'), [475, 'win']),
  ('regression: split stake share', ('+0.25', 3, 2, 1000, '1.85'), [1850, 'win']),
  ('variant scenario 1', ('+2', 1, 4, 500, '1.90'), [0, 'lose']),
  ('variant scenario 2', ('+0.75', 0, 4, 1000, '2.05'), [0, 'lose'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: split stake share', ('+1.25', 1, 0, 500, '1.85'), [925, 'win']),
  ('regression: split stake share', ('0', 2, 0, 250, '1.90'), [475, 'win']),
  ('variant scenario 1', ('-1.75', 2, 0, 999, '2.00'), [1498, 'half-win']),
  ('variant scenario 2', ('-0.3', 2, 4, 1000, '2.00'), 'invalid line')]]
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:
Quarter-line winners are paid double, or single lines are paid half.

Asian handicap bet on the home side. line is a multiple of 0.25 (else "invalid line"). Whole and half lines are a single bet; quarter lines split the stake equally between line - 0.25 and line + 0.25. Each part: margin = home_goals - away_goals + part_line; positive wins stake_part * price, zero refunds stake_part, negative loses. Return [total return in cents rounded down, label] where the label is win, half-win, push, half-lose or lose from the summed part outcomes.

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(line, home_goals, away_goals, stake_cents, price):
    L = Fraction(line)
    if (L * 4).denominator != 1:
        return 'invalid line'
    if (L * 2).denominator == 1:
        parts = [L]
    else:
        parts = [L - Fraction(1, 4), L + Fraction(1, 4)]
    d = Fraction(price)
    share = Fraction(stake_cents, len(parts))
    ret = Fraction(0)
    res = []
    for p in parts:
        m = home_goals - away_goals + p
        if m > 0:
            ret += share * d
            res.append(1)
        elif m == 0:
            res.append(0)
        else:
            res.append(-1)
    score = sum(res) * 2 // len(parts)
    label = {2: 'win', 1: 'half-win', 0: 'push', -1: 'half-lose', -2: 'lose'}[score]
    return [math.floor(ret), label]
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 half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: push refund', ('+0.75', 3, 4, 999, '2.05'), [499, 'half-lose']),
  ('variant scenario 1', ('0', 4, 0, 1000, '2.05'), [2050, 'win']),
  ('variant scenario 2', ('+0.75', 3, 0, 999, '2.00'), [1998, 'win'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: push refund', ('+2', 2, 4, 500, '1.85'), [500, 'push']),
  ('regression: push refund', ('+1.25', 2, 3, 999, '1.85'), [1423, 'half-win']),
  ('variant scenario 1', ('+0.75', 4, 4, 500, '1.85'), [925, 'win']),
  ('variant scenario 2', ('+1.25', 3, 3, 250, '1.85'), [462, 'win'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: push refund', ('-1', 3, 2, 1000, '1.90'), [1000, 'push']),
  ('regression: push refund', ('+0.75', 3, 4, 999, '1.90'), [499, 'half-lose']),
  ('variant scenario 1', ('-0.5', 0, 1, 500, '2.05'), [0, 'lose']),
  ('variant scenario 2', ('+0.75', 4, 0, 1000, '2.00'), [2000, 'win'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: push refund', ('-0.75', 2, 1, 999, '2.05'), [1523, 'half-win']),
  ('variant scenario 1', ('-1.75', 3, 4, 500, '2.00'), [0, 'lose']),
  ('variant scenario 2', ('+0.5', 4, 2, 1000, '2.05'), [2050, 'win'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: push refund', ('-1', 2, 1, 1000, '2.00'), [1000, 'push']),
  ('regression: push refund', ('+0.25', 3, 3, 500, '1.90'), [725, 'half-win']),
  ('variant scenario 1', ('-0.75', 2, 3, 250, '2.00'), [0, 'lose']),
  ('variant scenario 2', ('-1.5', 2, 0, 1000, '1.85'), [1850, 'win'])]]
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(line, home_goals, away_goals, stake_cents, price):
    L = Fraction(line)
    if (L * 4).denominator != 1:
        return 'invalid line'
    if (L * 2).denominator == 1:
        parts = [L]
    else:
        parts = [L - Fraction(1, 4), L + Fraction(1, 4)]
    d = Fraction(price)
    share = Fraction(stake_cents, len(parts))
    ret = Fraction(0)
    res = []
    for p in parts:
        m = home_goals - away_goals + p
        if m > 0:
            ret += share * d
            res.append(1)
        elif m == 0:
            ret += stake_cents
            res.append(0)
        else:
            res.append(-1)
    score = sum(res) * 2 // len(parts)
    label = {2: 'win', 1: 'half-win', 0: 'push', -1: 'half-lose', -2: 'lose'}[score]
    return [math.floor(ret), label]
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 half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: push refund', ('+0.75', 3, 4, 999, '2.05'), [499, 'half-lose']),
  ('variant scenario 1', ('0', 4, 0, 1000, '2.05'), [2050, 'win']),
  ('variant scenario 2', ('+0.75', 3, 0, 999, '2.00'), [1998, 'win'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: push refund', ('+2', 2, 4, 500, '1.85'), [500, 'push']),
  ('regression: push refund', ('+1.25', 2, 3, 999, '1.85'), [1423, 'half-win']),
  ('variant scenario 1', ('+0.75', 4, 4, 500, '1.85'), [925, 'win']),
  ('variant scenario 2', ('+1.25', 3, 3, 250, '1.85'), [462, 'win'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: push refund', ('-1', 3, 2, 1000, '1.90'), [1000, 'push']),
  ('regression: push refund', ('+0.75', 3, 4, 999, '1.90'), [499, 'half-lose']),
  ('variant scenario 1', ('-0.5', 0, 1, 500, '2.05'), [0, 'lose']),
  ('variant scenario 2', ('+0.75', 4, 0, 1000, '2.00'), [2000, 'win'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: push refund', ('-0.75', 2, 1, 999, '2.05'), [1523, 'half-win']),
  ('variant scenario 1', ('-1.75', 3, 4, 500, '2.00'), [0, 'lose']),
  ('variant scenario 2', ('+0.5', 4, 2, 1000, '2.05'), [2050, 'win'])],
 [('control half line win', ('-0.5', 1, 0, 1000, '1.90'), [1900, 'win']),
  ('boundary whole line push', ('-1', 2, 1, 1000, '1.90'), [1000, 'push']),
  ('boundary quarter half-lose', ('-0.25', 1, 1, 1000, '1.90'), [500, 'half-lose']),
  ('boundary quarter half-win', ('-0.75', 1, 0, 1000, '2.00'), [1500, 'half-win']),
  ('control lose', ('+0.5', 0, 2, 1000, '1.90'), [0, 'lose']),
  ('boundary off-grid line', ('-0.3', 1, 0, 1000, '1.90'), 'invalid line'),
  ('regression: push refund', ('-1', 2, 1, 1000, '2.00'), [1000, 'push']),
  ('regression: push refund', ('+0.25', 3, 3, 500, '1.90'), [725, 'half-win']),
  ('variant scenario 1', ('-0.75', 2, 3, 250, '2.00'), [0, 'lose']),
  ('variant scenario 2', ('-1.5', 2, 0, 1000, '1.85'), [1850, 'win'])]]
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 whole-line push returns 0, or a half push refunds the full stake.

Asian handicap bet on the home side. line is a multiple of 0.25 (else "invalid line"). Whole and half lines are a single bet; quarter lines split the stake equally between line - 0.25 and line + 0.25. Each part: margin = home_goals - away_goals + part_line; positive wins stake_part * price, zero refunds stake_part, negative loses. Return [total return in cents rounded down, label] where the label is win, half-win, push, half-lose or lose from the summed part outcomes.

split: open-access