broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(legs, stake_cents, margin_pct, partial_cents):
    value = Fraction(stake_cents)
    for price, cur in legs:
        if cur == 'lost':
            return [0, 0]
        if cur == 'won':
            continue
        value *= Fraction(price)
        if cur != 'won':
            value /= Fraction(cur)
    value = value * (100 - Fraction(margin_pct)) / 100
    full = math.floor(value)
    if partial_cents == 0:
        return [full, 0]
    if partial_cents > full:
        return 'invalid'
    remaining = math.floor(stake_cents * (1 - Fraction(partial_cents, full)))
    return [partial_cents, remaining]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: settled leg', ([['2.34', 'won'], ['2.34', 'won']], 1000, '0', 200), [200, 963]),
  ('variant scenario 1', ([['3.31', '1.25']], 1000, '7.5', 200), [200, 918]),
  ('variant scenario 2', ([['1.52', 'lost'], ['4.56', '2.64']], 1000, '7.5', 500), [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: settled leg', ([['3.22', 'won']], 500, '5', 0), [1529, 0]),
  ('variant scenario 1',
   ([['4.04', '1.83'], ['1.86', '2.30'], ['1.41', 'lost']], 2500, '5', 0),
   [0, 0]),
  ('variant scenario 2',
   ([['4.07', 'lost'], ['1.73', '4.97'], ['4.67', 'won'], ['1.95', 'won']], 1000, '5', 0),
   [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: settled leg', ([['1.96', 'won'], ['4.86', 'won']], 500, '7.5', 500), [500, 443]),
  ('variant scenario 1', ([['3.99', 'won'], ['3.43', 'lost']], 1000, '0', 800), [0, 0]),
  ('variant scenario 2',
   ([['2.83', '3.24'], ['4.46', '3.35'], ['3.41', 'won'], ['4.39', '5.31']], 2500, '0', 800),
   [800, 2255])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: settled leg', ([['1.88', '2.96'], ['4.98', 'won']], 500, '0', 0), [1581, 0]),
  ('variant scenario 1',
   ([['3.69', '3.54'], ['2.84', '5.65'], ['1.59', 'lost']], 2500, '7.5', 0),
   [0, 0]),
  ('variant scenario 2',
   ([['3.74', '3.53'], ['4.23', 'lost'], ['3.97', 'won'], ['2.51', 'lost']], 2500, '5', 800),
   [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: settled leg',
   ([['2.64', 'won'], ['3.03', '3.29'], ['4.82', '4.42'], ['3.27', '4.34']], 2500, '5', 800),
   [800, 2078]),
  ('variant scenario 1',
   ([['2.27', 'lost'], ['3.11', '2.62'], ['2.35', '5.79'], ['2.20', '1.56']], 1000, '5', 0),
   [0, 0]),
  ('variant scenario 2', ([['3.88', '4.62'], ['1.58', 'lost']], 2500, '7.5', 0), [0, 0])]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(legs, stake_cents, margin_pct, partial_cents):
    value = Fraction(stake_cents)
    for price, cur in legs:
        if cur == 'lost':
            return [0, 0]
        value *= Fraction(price) - (1 if cur == 'won' else 0)
        if cur != 'won':
            value /= Fraction(cur)
    value = value * (100 - Fraction(margin_pct)) / 100
    full = math.floor(value)
    if partial_cents == 0:
        return [full, 0]
    if partial_cents > full:
        return 'invalid'
    remaining = math.floor(stake_cents * (1 - Fraction(partial_cents, full)))
    return [partial_cents, remaining]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: settled leg', ([['2.34', 'won'], ['2.34', 'won']], 1000, '0', 200), [200, 963]),
  ('variant scenario 1', ([['3.31', '1.25']], 1000, '7.5', 200), [200, 918]),
  ('variant scenario 2', ([['1.52', 'lost'], ['4.56', '2.64']], 1000, '7.5', 500), [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: settled leg', ([['3.22', 'won']], 500, '5', 0), [1529, 0]),
  ('variant scenario 1',
   ([['4.04', '1.83'], ['1.86', '2.30'], ['1.41', 'lost']], 2500, '5', 0),
   [0, 0]),
  ('variant scenario 2',
   ([['4.07', 'lost'], ['1.73', '4.97'], ['4.67', 'won'], ['1.95', 'won']], 1000, '5', 0),
   [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: settled leg', ([['1.96', 'won'], ['4.86', 'won']], 500, '7.5', 500), [500, 443]),
  ('variant scenario 1', ([['3.99', 'won'], ['3.43', 'lost']], 1000, '0', 800), [0, 0]),
  ('variant scenario 2',
   ([['2.83', '3.24'], ['4.46', '3.35'], ['3.41', 'won'], ['4.39', '5.31']], 2500, '0', 800),
   [800, 2255])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: settled leg', ([['1.88', '2.96'], ['4.98', 'won']], 500, '0', 0), [1581, 0]),
  ('variant scenario 1',
   ([['3.69', '3.54'], ['2.84', '5.65'], ['1.59', 'lost']], 2500, '7.5', 0),
   [0, 0]),
  ('variant scenario 2',
   ([['3.74', '3.53'], ['4.23', 'lost'], ['3.97', 'won'], ['2.51', 'lost']], 2500, '5', 800),
   [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: settled leg',
   ([['2.64', 'won'], ['3.03', '3.29'], ['4.82', '4.42'], ['3.27', '4.34']], 2500, '5', 800),
   [800, 2078]),
  ('variant scenario 1',
   ([['2.27', 'lost'], ['3.11', '2.62'], ['2.35', '5.79'], ['2.20', '1.56']], 1000, '5', 0),
   [0, 0]),
  ('variant scenario 2', ([['3.88', '4.62'], ['1.58', 'lost']], 2500, '7.5', 0), [0, 0])]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A multiple with a leg already won is valued as if that leg did not exist.

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

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(legs, stake_cents, margin_pct, partial_cents):
    value = Fraction(stake_cents)
    for price, cur in legs:
        if cur == 'lost':
            return [0, 0]
        value *= Fraction(price)
        if cur != 'won':
            value /= Fraction(cur)
    value = value - Fraction(margin_pct)
    full = math.floor(value)
    if partial_cents == 0:
        return [full, 0]
    if partial_cents > full:
        return 'invalid'
    remaining = math.floor(stake_cents * (1 - Fraction(partial_cents, full)))
    return [partial_cents, remaining]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: margin application',
   ([['3.98', 'won'], ['3.24', 'won'], ['2.39', '4.03'], ['2.04', 'won']], 500, '5', 500),
   [500, 466]),
  ('regression: margin application',
   ([['3.31', '5.65'], ['4.82', '5.34']], 2500, '5', 0),
   [1255, 0]),
  ('variant scenario 1',
   ([['2.61', 'won'], ['2.54', '3.04'], ['4.36', 'won'], ['3.63', '5.65']], 2500, '0', 500),
   [500, 2418]),
  ('variant scenario 2', ([['2.56', 'lost']], 500, '7.5', 800), [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: margin application', ([['4.31', '1.48']], 500, '5', 500), [500, 319]),
  ('regression: margin application', ([['2.56', '3.02']], 1000, '5', 0), [805, 0]),
  ('variant scenario 1',
   ([['3.54', 'won'], ['4.17', '2.42'], ['3.80', 'won'], ['3.99', 'lost']], 500, '7.5', 200),
   [0, 0]),
  ('variant scenario 2', ([['2.56', 'won']], 2500, '0', 200), [200, 2421])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: margin application',
   ([['1.77', '5.47'], ['4.57', 'won'], ['4.63', 'won'], ['4.20', 'won']], 1000, '5', 200),
   [200, 992]),
  ('regression: margin application', ([['4.21', 'won']], 500, '5', 0), [1999, 0]),
  ('variant scenario 1',
   ([['4.24', 'lost'], ['4.73', '5.96'], ['3.59', 'won']], 1000, '7.5', 0),
   [0, 0]),
  ('variant scenario 2', ([['4.94', '1.31'], ['2.71', '5.06']], 1000, '0', 800), [800, 603])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: margin application', ([['1.66', '3.53']], 2500, '5', 200), [200, 2051]),
  ('variant scenario 1', ([['1.54', 'won'], ['3.01', '3.82']], 1000, '0', 500), [500, 587]),
  ('variant scenario 2', ([['3.86', '5.37']], 500, '7.5', 0), [332, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: margin application',
   ([['4.64', '5.35'], ['4.09', 'won'], ['4.50', '2.09']], 1000, '7.5', 0),
   [7064, 0]),
  ('variant scenario 1',
   ([['2.22', 'lost'], ['2.66', 'won'], ['4.77', '1.58'], ['3.17', 'lost']], 2500, '5', 200),
   [0, 0]),
  ('variant scenario 2',
   ([['4.16', '1.91'], ['4.67', '5.15'], ['2.46', '4.20'], ['3.13', '3.40']], 500, '0', 0),
   [532, 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, margin_pct, partial_cents):
    value = Fraction(stake_cents)
    for price, cur in legs:
        if cur == 'lost':
            return [0, 0]
        value *= Fraction(price)
        if cur != 'won':
            value /= Fraction(cur)
    value = value / (1 + Fraction(margin_pct) / 100)
    full = math.floor(value)
    if partial_cents == 0:
        return [full, 0]
    if partial_cents > full:
        return 'invalid'
    remaining = math.floor(stake_cents * (1 - Fraction(partial_cents, full)))
    return [partial_cents, remaining]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: margin application',
   ([['3.98', 'won'], ['3.24', 'won'], ['2.39', '4.03'], ['2.04', 'won']], 500, '5', 500),
   [500, 466]),
  ('regression: margin application',
   ([['3.31', '5.65'], ['4.82', '5.34']], 2500, '5', 0),
   [1255, 0]),
  ('variant scenario 1',
   ([['2.61', 'won'], ['2.54', '3.04'], ['4.36', 'won'], ['3.63', '5.65']], 2500, '0', 500),
   [500, 2418]),
  ('variant scenario 2', ([['2.56', 'lost']], 500, '7.5', 800), [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: margin application', ([['4.31', '1.48']], 500, '5', 500), [500, 319]),
  ('regression: margin application', ([['2.56', '3.02']], 1000, '5', 0), [805, 0]),
  ('variant scenario 1',
   ([['3.54', 'won'], ['4.17', '2.42'], ['3.80', 'won'], ['3.99', 'lost']], 500, '7.5', 200),
   [0, 0]),
  ('variant scenario 2', ([['2.56', 'won']], 2500, '0', 200), [200, 2421])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: margin application',
   ([['1.77', '5.47'], ['4.57', 'won'], ['4.63', 'won'], ['4.20', 'won']], 1000, '5', 200),
   [200, 992]),
  ('regression: margin application', ([['4.21', 'won']], 500, '5', 0), [1999, 0]),
  ('variant scenario 1',
   ([['4.24', 'lost'], ['4.73', '5.96'], ['3.59', 'won']], 1000, '7.5', 0),
   [0, 0]),
  ('variant scenario 2', ([['4.94', '1.31'], ['2.71', '5.06']], 1000, '0', 800), [800, 603])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: margin application', ([['1.66', '3.53']], 2500, '5', 200), [200, 2051]),
  ('variant scenario 1', ([['1.54', 'won'], ['3.01', '3.82']], 1000, '0', 500), [500, 587]),
  ('variant scenario 2', ([['3.86', '5.37']], 500, '7.5', 0), [332, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: margin application',
   ([['4.64', '5.35'], ['4.09', 'won'], ['4.50', '2.09']], 1000, '7.5', 0),
   [7064, 0]),
  ('variant scenario 1',
   ([['2.22', 'lost'], ['2.66', 'won'], ['4.77', '1.58'], ['3.17', 'lost']], 2500, '5', 200),
   [0, 0]),
  ('variant scenario 2',
   ([['4.16', '1.91'], ['4.67', '5.15'], ['2.46', '4.20'], ['3.13', '3.40']], 500, '0', 0),
   [532, 0])]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Offers differ from the stated percentage deduction.

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

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(legs, stake_cents, margin_pct, partial_cents):
    value = Fraction(stake_cents)
    for price, cur in legs:
        if cur == 'lost':
            return [0, 0]
        value *= Fraction(price)
        if cur != 'won':
            value /= Fraction(cur)
    value = value * (100 - Fraction(margin_pct)) / 100
    full = math.floor(value)
    if partial_cents == 0:
        return [full, 0]
    if partial_cents > full:
        return 'invalid'
    remaining = stake_cents - partial_cents
    return [partial_cents, remaining]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: partial remaining stake', ([['2.79', 'won']], 500, '5', 800), [800, 198]),
  ('variant scenario 1',
   ([['1.51', 'won'], ['3.49', 'won'], ['3.39', 'lost'], ['1.99', 'won']], 500, '7.5', 0),
   [0, 0]),
  ('variant scenario 2',
   ([['3.71', 'lost'], ['1.47', '4.60'], ['1.32', 'won'], ['1.57', '2.91']], 1000, '5', 200),
   [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: partial remaining stake',
   ([['3.43', '4.22'], ['4.58', 'won'], ['2.70', 'won']], 1000, '5', 500),
   [500, 947]),
  ('variant scenario 1', ([['5.00', '5.10']], 500, '0', 0), [490, 0]),
  ('variant scenario 2',
   ([['4.09', '4.06'], ['1.44', 'lost'], ['4.51', '1.56'], ['4.68', 'won']], 1000, '0', 0),
   [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: partial remaining stake', ([['3.79', '2.66']], 1000, '7.5', 500), [500, 620]),
  ('variant scenario 1', ([['4.71', 'won']], 1000, '0', 0), [4710, 0]),
  ('variant scenario 2', ([['1.46', '1.60']], 500, '5', 500), 'invalid')],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: partial remaining stake',
   ([['3.65', 'won'], ['2.14', '1.31'], ['2.44', '2.91']], 1000, '5', 500),
   [500, 894]),
  ('variant scenario 1',
   ([['3.39', 'won'], ['2.49', '5.36'], ['1.49', '4.00'], ['3.15', '5.06']], 2500, '5', 0),
   [867, 0]),
  ('variant scenario 2', ([['2.52', 'lost'], ['4.68', '4.00']], 1000, '5', 0), [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: partial remaining stake', ([['4.93', 'won']], 2500, '5', 500), [500, 2393]),
  ('variant scenario 1',
   ([['3.53', '1.91'], ['3.32', 'lost'], ['1.63', 'won'], ['2.97', '4.57']], 500, '0', 500),
   [0, 0]),
  ('variant scenario 2', ([['2.73', 'won'], ['2.11', '4.03']], 1000, '0', 0), [1429, 0])]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(legs, stake_cents, margin_pct, partial_cents):
    value = Fraction(stake_cents)
    for price, cur in legs:
        if cur == 'lost':
            return [0, 0]
        value *= Fraction(price)
        if cur != 'won':
            value /= Fraction(cur)
    value = value * (100 - Fraction(margin_pct)) / 100
    full = math.floor(value)
    if partial_cents == 0:
        return [full, 0]
    if partial_cents > full:
        return 'invalid'
    remaining = math.floor(stake_cents * Fraction(partial_cents, full))
    return [partial_cents, remaining]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: partial remaining stake', ([['2.79', 'won']], 500, '5', 800), [800, 198]),
  ('variant scenario 1',
   ([['1.51', 'won'], ['3.49', 'won'], ['3.39', 'lost'], ['1.99', 'won']], 500, '7.5', 0),
   [0, 0]),
  ('variant scenario 2',
   ([['3.71', 'lost'], ['1.47', '4.60'], ['1.32', 'won'], ['1.57', '2.91']], 1000, '5', 200),
   [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: partial remaining stake',
   ([['3.43', '4.22'], ['4.58', 'won'], ['2.70', 'won']], 1000, '5', 500),
   [500, 947]),
  ('variant scenario 1', ([['5.00', '5.10']], 500, '0', 0), [490, 0]),
  ('variant scenario 2',
   ([['4.09', '4.06'], ['1.44', 'lost'], ['4.51', '1.56'], ['4.68', 'won']], 1000, '0', 0),
   [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: partial remaining stake', ([['3.79', '2.66']], 1000, '7.5', 500), [500, 620]),
  ('variant scenario 1', ([['4.71', 'won']], 1000, '0', 0), [4710, 0]),
  ('variant scenario 2', ([['1.46', '1.60']], 500, '5', 500), 'invalid')],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: partial remaining stake',
   ([['3.65', 'won'], ['2.14', '1.31'], ['2.44', '2.91']], 1000, '5', 500),
   [500, 894]),
  ('variant scenario 1',
   ([['3.39', 'won'], ['2.49', '5.36'], ['1.49', '4.00'], ['3.15', '5.06']], 2500, '5', 0),
   [867, 0]),
  ('variant scenario 2', ([['2.52', 'lost'], ['4.68', '4.00']], 1000, '5', 0), [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: partial remaining stake', ([['4.93', 'won']], 2500, '5', 500), [500, 2393]),
  ('variant scenario 1',
   ([['3.53', '1.91'], ['3.32', 'lost'], ['1.63', 'won'], ['2.97', '4.57']], 500, '0', 500),
   [0, 0]),
  ('variant scenario 2', ([['2.73', 'won'], ['2.11', '4.03']], 1000, '0', 0), [1429, 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:
After cashing out half the value, the remaining stake is the cashed portion or the stake minus cents.

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

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(pool_cents, takeout_pct, winners):
    net = Fraction(pool_cents) * Fraction(takeout_pct) / 100
    share = net / len(winners)
    out = []
    for s in winners:
        if s == 0:
            out.append(None)
            continue
        dimes = math.floor(share / s * 10)
        dimes = max(dimes, 11)
        out.append('%d.%d0' % (dimes // 10, dimes % 10))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: takeout application',
   (250000, '16', [12305, 5000, 116734]),
   ['5.60', '14.00', '1.10']),
  ('variant scenario 1', (20000, '20', [884, 13602]), ['9.00', '1.10']),
  ('variant scenario 2', (50000, '20', [10000]), ['4.00'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: takeout application',
   (1234500, '20', [564505, 846773, 5000]),
   ['1.10', '1.10', '65.80']),
  ('variant scenario 1', (20000, '20', [8118]), ['1.90']),
  ('variant scenario 2', (1234500, '20', [10000, 40000, 1174709]), ['32.90', '8.20', '1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: takeout application', (50000, '15', [11107]), ['3.80']),
  ('variant scenario 1', (250000, '15', [0]), [None]),
  ('variant scenario 2', (1234500, '16', [864394, 1059735, 1234500]), ['1.10', '1.10', '1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: takeout application', (100000, '15', [1500, 91738]), ['28.30', '1.10']),
  ('variant scenario 1', (100000, '15', [69872, 70392, 1500]), ['1.10', '1.10', '18.80']),
  ('variant scenario 2', (1234500, '16', [555465]), ['1.80'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: takeout application', (1234500, '0', [617250, 390837]), ['1.10', '1.50']),
  ('regression: takeout application', (20000, '16', [5000]), ['3.30']),
  ('variant scenario 1', (100000, '16', [55428, 50000, 100000]), ['1.10', '1.10', '1.10']),
  ('variant scenario 2', (50000, '16', [40497, 21355, 36633]), ['1.10', '1.10', '1.10'])]]
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(pool_cents, takeout_pct, winners):
    net = Fraction(pool_cents) / (1 + Fraction(takeout_pct) / 100)
    share = net / len(winners)
    out = []
    for s in winners:
        if s == 0:
            out.append(None)
            continue
        dimes = math.floor(share / s * 10)
        dimes = max(dimes, 11)
        out.append('%d.%d0' % (dimes // 10, dimes % 10))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: takeout application',
   (250000, '16', [12305, 5000, 116734]),
   ['5.60', '14.00', '1.10']),
  ('variant scenario 1', (20000, '20', [884, 13602]), ['9.00', '1.10']),
  ('variant scenario 2', (50000, '20', [10000]), ['4.00'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: takeout application',
   (1234500, '20', [564505, 846773, 5000]),
   ['1.10', '1.10', '65.80']),
  ('variant scenario 1', (20000, '20', [8118]), ['1.90']),
  ('variant scenario 2', (1234500, '20', [10000, 40000, 1174709]), ['32.90', '8.20', '1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: takeout application', (50000, '15', [11107]), ['3.80']),
  ('variant scenario 1', (250000, '15', [0]), [None]),
  ('variant scenario 2', (1234500, '16', [864394, 1059735, 1234500]), ['1.10', '1.10', '1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: takeout application', (100000, '15', [1500, 91738]), ['28.30', '1.10']),
  ('variant scenario 1', (100000, '15', [69872, 70392, 1500]), ['1.10', '1.10', '18.80']),
  ('variant scenario 2', (1234500, '16', [555465]), ['1.80'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: takeout application', (1234500, '0', [617250, 390837]), ['1.10', '1.50']),
  ('regression: takeout application', (20000, '16', [5000]), ['3.30']),
  ('variant scenario 1', (100000, '16', [55428, 50000, 100000]), ['1.10', '1.10', '1.10']),
  ('variant scenario 2', (50000, '16', [40497, 21355, 36633]), ['1.10', '1.10', '1.10'])]]
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:
Dividends are tiny, or slightly too high.

Pari-mutuel win dividend per unit stake. The net pool is pool * (100 - takeout_pct) / 100; with a dead heat it is split equally among the winning runners. Each runner's dividend is its share divided by the stakes on it, broken down to the 10-cent step below (breakage), with a minimum of 1.10. A winner with no stakes gets None. Return dividends as "D.D0" strings in winners order.

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(pool_cents, takeout_pct, winners):
    net = Fraction(pool_cents) * (100 - Fraction(takeout_pct)) / 100
    share = net / len(winners)
    out = []
    for s in winners:
        if s == 0:
            out.append(None)
            continue
        dimes = math.floor(share / s * 10 + Fraction(1, 2))
        dimes = max(dimes, 11)
        out.append('%d.%d0' % (dimes // 10, dimes % 10))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: breakage direction', (50000, '15', [11867]), ['3.50']),
  ('variant scenario 1', (50000, '20', [47992]), ['1.10']),
  ('variant scenario 2', (100000, '20', [75618]), ['1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: breakage direction', (250000, '16', [62527]), ['3.30']),
  ('variant scenario 1', (250000, '0', [333]), ['750.70']),
  ('variant scenario 2', (50000, '16', [38443]), ['1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: breakage direction', (100000, '0', [70424]), ['1.40']),
  ('regression: breakage direction', (1234500, '16', [155805]), ['6.60']),
  ('variant scenario 1', (100000, '15', [55625, 0]), ['1.10', None]),
  ('variant scenario 2', (50000, '15', [6485]), ['6.50'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: breakage direction', (250000, '0', [241772, 1500]), ['1.10', '83.30']),
  ('regression: breakage direction', (50000, '16', [0, 5094, 3128]), [None, '2.70', '4.40']),
  ('variant scenario 1', (250000, '16', [250000]), ['1.10']),
  ('variant scenario 2', (50000, '20', [36563]), ['1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: breakage direction', (1234500, '20', [896467]), ['1.10']),
  ('regression: breakage direction', (50000, '20', [21393]), ['1.80']),
  ('variant scenario 1', (1234500, '15', [40000, 617250, 518407]), ['8.70', '1.10', '1.10']),
  ('variant scenario 2', (100000, '15', [40000]), ['2.10'])]]
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(pool_cents, takeout_pct, winners):
    net = Fraction(pool_cents) * (100 - Fraction(takeout_pct)) / 100
    share = net / len(winners)
    out = []
    for s in winners:
        if s == 0:
            out.append(None)
            continue
        dimes = math.ceil(share / s * 10)
        dimes = max(dimes, 11)
        out.append('%d.%d0' % (dimes // 10, dimes % 10))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: breakage direction', (50000, '15', [11867]), ['3.50']),
  ('variant scenario 1', (50000, '20', [47992]), ['1.10']),
  ('variant scenario 2', (100000, '20', [75618]), ['1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: breakage direction', (250000, '16', [62527]), ['3.30']),
  ('variant scenario 1', (250000, '0', [333]), ['750.70']),
  ('variant scenario 2', (50000, '16', [38443]), ['1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: breakage direction', (100000, '0', [70424]), ['1.40']),
  ('regression: breakage direction', (1234500, '16', [155805]), ['6.60']),
  ('variant scenario 1', (100000, '15', [55625, 0]), ['1.10', None]),
  ('variant scenario 2', (50000, '15', [6485]), ['6.50'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: breakage direction', (250000, '0', [241772, 1500]), ['1.10', '83.30']),
  ('regression: breakage direction', (50000, '16', [0, 5094, 3128]), [None, '2.70', '4.40']),
  ('variant scenario 1', (250000, '16', [250000]), ['1.10']),
  ('variant scenario 2', (50000, '20', [36563]), ['1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: breakage direction', (1234500, '20', [896467]), ['1.10']),
  ('regression: breakage direction', (50000, '20', [21393]), ['1.80']),
  ('variant scenario 1', (1234500, '15', [40000, 617250, 518407]), ['8.70', '1.10', '1.10']),
  ('variant scenario 2', (100000, '15', [40000]), ['2.10'])]]
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 2.8267 dividend is paid as 2.90 or rounded to 2.80 only sometimes.

Pari-mutuel win dividend per unit stake. The net pool is pool * (100 - takeout_pct) / 100; with a dead heat it is split equally among the winning runners. Each runner's dividend is its share divided by the stakes on it, broken down to the 10-cent step below (breakage), with a minimum of 1.10. A winner with no stakes gets None. Return dividends as "D.D0" strings in winners order.

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(pool_cents, takeout_pct, winners):
    net = Fraction(pool_cents) * (100 - Fraction(takeout_pct)) / 100
    share = net / len(winners)
    out = []
    for s in winners:
        if s == 0:
            out.append(None)
            continue
        dimes = math.floor(share / s * 10)
        dimes = max(dimes, 10)
        out.append('%d.%d0' % (dimes // 10, dimes % 10))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: minimum dividend', (250000, '16', [35604, 123268]), ['2.90', '1.10']),
  ('regression: minimum dividend', (250000, '0', [230658]), ['1.10']),
  ('variant scenario 1', (20000, '0', [12085]), ['1.60']),
  ('variant scenario 2', (50000, '15', [0]), [None])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: minimum dividend',
   (250000, '16', [10000, 250000, 97356]),
   ['7.00', '1.10', '1.10']),
  ('regression: minimum dividend', (50000, '15', [40000]), ['1.10']),
  ('variant scenario 1', (1234500, '16', [793963]), ['1.30']),
  ('variant scenario 2', (250000, '0', [333, 10000]), ['375.30', '12.50'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: minimum dividend', (1234500, '15', [1156662]), ['1.10']),
  ('regression: minimum dividend', (50000, '15', [19428, 50000]), ['1.10', '1.10']),
  ('variant scenario 1', (50000, '15', [3875]), ['10.90']),
  ('variant scenario 2', (250000, '15', [0]), [None])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: minimum dividend', (250000, '20', [248216]), ['1.10']),
  ('regression: minimum dividend', (50000, '0', [50000]), ['1.10']),
  ('variant scenario 1', (100000, '15', [22149]), ['3.80']),
  ('variant scenario 2', (100000, '0', [333]), ['300.30'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: minimum dividend',
   (1234500, '0', [1017834, 351582, 426153]),
   ['1.10', '1.10', '1.10']),
  ('regression: minimum dividend', (100000, '15', [50000, 40000]), ['1.10', '1.10']),
  ('variant scenario 1', (100000, '20', [50621]), ['1.50']),
  ('variant scenario 2', (50000, '0', [33751]), ['1.40'])]]
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(pool_cents, takeout_pct, winners):
    net = Fraction(pool_cents) * (100 - Fraction(takeout_pct)) / 100
    share = net / len(winners)
    out = []
    for s in winners:
        if s == 0:
            out.append(None)
            continue
        dimes = math.floor(share / s * 10)
        dimes = dimes if dimes >= 10 else 11
        out.append('%d.%d0' % (dimes // 10, dimes % 10))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: minimum dividend', (250000, '16', [35604, 123268]), ['2.90', '1.10']),
  ('regression: minimum dividend', (250000, '0', [230658]), ['1.10']),
  ('variant scenario 1', (20000, '0', [12085]), ['1.60']),
  ('variant scenario 2', (50000, '15', [0]), [None])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: minimum dividend',
   (250000, '16', [10000, 250000, 97356]),
   ['7.00', '1.10', '1.10']),
  ('regression: minimum dividend', (50000, '15', [40000]), ['1.10']),
  ('variant scenario 1', (1234500, '16', [793963]), ['1.30']),
  ('variant scenario 2', (250000, '0', [333, 10000]), ['375.30', '12.50'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: minimum dividend', (1234500, '15', [1156662]), ['1.10']),
  ('regression: minimum dividend', (50000, '15', [19428, 50000]), ['1.10', '1.10']),
  ('variant scenario 1', (50000, '15', [3875]), ['10.90']),
  ('variant scenario 2', (250000, '15', [0]), [None])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: minimum dividend', (250000, '20', [248216]), ['1.10']),
  ('regression: minimum dividend', (50000, '0', [50000]), ['1.10']),
  ('variant scenario 1', (100000, '15', [22149]), ['3.80']),
  ('variant scenario 2', (100000, '0', [333]), ['300.30'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: minimum dividend',
   (1234500, '0', [1017834, 351582, 426153]),
   ['1.10', '1.10', '1.10']),
  ('regression: minimum dividend', (100000, '15', [50000, 40000]), ['1.10', '1.10']),
  ('variant scenario 1', (100000, '20', [50621]), ['1.50']),
  ('variant scenario 2', (50000, '0', [33751]), ['1.40'])]]
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:
Heavily backed winners pay 1.00 or 1.05 instead of the 1.10 minimum.

Pari-mutuel win dividend per unit stake. The net pool is pool * (100 - takeout_pct) / 100; with a dead heat it is split equally among the winning runners. Each runner's dividend is its share divided by the stakes on it, broken down to the 10-cent step below (breakage), with a minimum of 1.10. A winner with no stakes gets None. Return dividends as "D.D0" strings in winners order.

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(pool_cents, takeout_pct, winners):
    net = Fraction(pool_cents) * (100 - Fraction(takeout_pct)) / 100
    share = net
    out = []
    for s in winners:
        if s == 0:
            out.append(None)
            continue
        dimes = math.floor(share / s * 10)
        dimes = max(dimes, 11)
        out.append('%d.%d0' % (dimes // 10, dimes % 10))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: dead heat pool split',
   (50000, '20', [5780, 19643, 10000]),
   ['2.30', '1.10', '1.30']),
  ('variant scenario 1', (20000, '20', [6429]), ['2.40']),
  ('variant scenario 2', (100000, '16', [63045]), ['1.30'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: dead heat pool split',
   (1234500, '15', [116623, 1500, 315481]),
   ['2.90', '233.10', '1.10']),
  ('variant scenario 1', (1234500, '0', [1197831]), ['1.10']),
  ('variant scenario 2', (250000, '20', [133099, 235040]), ['1.10', '1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: dead heat pool split',
   (250000, '16', [217934, 1500, 28724]),
   ['1.10', '46.60', '2.40']),
  ('variant scenario 1', (50000, '20', [49163, 50000, 25000]), ['1.10', '1.10', '1.10']),
  ('variant scenario 2', (100000, '15', [39045]), ['2.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: dead heat pool split', (20000, '0', [333, 9067]), ['30.00', '1.10']),
  ('variant scenario 1', (1234500, '16', [502220]), ['2.00']),
  ('variant scenario 2', (1234500, '0', [1050059]), ['1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: dead heat pool split', (20000, '20', [333, 2307, 4298]), ['16.00', '2.30', '1.20']),
  ('variant scenario 1', (100000, '0', [52164]), ['1.90']),
  ('variant scenario 2', (100000, '15', [45964]), ['1.80'])]]
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(pool_cents, takeout_pct, winners):
    net = Fraction(pool_cents) * (100 - Fraction(takeout_pct)) / 100
    share = net / len(winners)
    out = []
    for s in winners:
        if s == 0:
            out.append(None)
            continue
        dimes = math.floor(net / sum(winners) * 10)
        dimes = max(dimes, 11)
        out.append('%d.%d0' % (dimes // 10, dimes % 10))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: dead heat pool split',
   (50000, '20', [5780, 19643, 10000]),
   ['2.30', '1.10', '1.30']),
  ('variant scenario 1', (20000, '20', [6429]), ['2.40']),
  ('variant scenario 2', (100000, '16', [63045]), ['1.30'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: dead heat pool split',
   (1234500, '15', [116623, 1500, 315481]),
   ['2.90', '233.10', '1.10']),
  ('variant scenario 1', (1234500, '0', [1197831]), ['1.10']),
  ('variant scenario 2', (250000, '20', [133099, 235040]), ['1.10', '1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: dead heat pool split',
   (250000, '16', [217934, 1500, 28724]),
   ['1.10', '46.60', '2.40']),
  ('variant scenario 1', (50000, '20', [49163, 50000, 25000]), ['1.10', '1.10', '1.10']),
  ('variant scenario 2', (100000, '15', [39045]), ['2.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: dead heat pool split', (20000, '0', [333, 9067]), ['30.00', '1.10']),
  ('variant scenario 1', (1234500, '16', [502220]), ['2.00']),
  ('variant scenario 2', (1234500, '0', [1050059]), ['1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: dead heat pool split', (20000, '20', [333, 2307, 4298]), ['16.00', '2.30', '1.20']),
  ('variant scenario 1', (100000, '0', [52164]), ['1.90']),
  ('variant scenario 2', (100000, '15', [45964]), ['1.80'])]]
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:
Both dead-heated runners are paid from the full net pool.

Pari-mutuel win dividend per unit stake. The net pool is pool * (100 - takeout_pct) / 100; with a dead heat it is split equally among the winning runners. Each runner's dividend is its share divided by the stakes on it, broken down to the 10-cent step below (breakage), with a minimum of 1.10. A winner with no stakes gets None. Return dividends as "D.D0" strings in winners order.

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(pool_cents, takeout_pct, winners):
    net = Fraction(pool_cents) * (100 - Fraction(takeout_pct)) / 100
    share = net / len(winners)
    out = []
    for s in winners:
        dimes = math.floor(share / s * 10)
        dimes = max(dimes, 11)
        out.append('%d.%d0' % (dimes // 10, dimes % 10))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: unbacked winner', (250000, '0', [0]), [None]),
  ('variant scenario 1', (100000, '16', [46029]), ['1.80']),
  ('variant scenario 2', (50000, '0', [19014, 1025, 3517]), ['1.10', '16.20', '4.70'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: unbacked winner', (250000, '20', [41766, 0, 146516]), ['1.50', None, '1.10']),
  ('variant scenario 1', (20000, '16', [8054]), ['2.00']),
  ('variant scenario 2', (1234500, '20', [948216, 357944, 406471]), ['1.10', '1.10', '1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: unbacked winner', (20000, '16', [0]), [None]),
  ('variant scenario 1', (20000, '15', [15831, 15772]), ['1.10', '1.10']),
  ('variant scenario 2', (20000, '16', [19210]), ['1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: unbacked winner', (20000, '15', [0]), [None]),
  ('variant scenario 1', (50000, '16', [40000]), ['1.10']),
  ('variant scenario 2', (100000, '16', [1500, 50366]), ['28.00', '1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: unbacked winner', (1234500, '0', [636655, 0, 10000]), ['1.10', None, '41.10']),
  ('variant scenario 1', (50000, '0', [27761]), ['1.80']),
  ('variant scenario 2', (20000, '20', [5443, 16144]), ['1.40', '1.10'])]]
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(pool_cents, takeout_pct, winners):
    net = Fraction(pool_cents) * (100 - Fraction(takeout_pct)) / 100
    share = net / len(winners)
    out = []
    for s in winners:
        if s == 0:
            out.append('0.00')
            continue
        dimes = math.floor(share / s * 10)
        dimes = max(dimes, 11)
        out.append('%d.%d0' % (dimes // 10, dimes % 10))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: unbacked winner', (250000, '0', [0]), [None]),
  ('variant scenario 1', (100000, '16', [46029]), ['1.80']),
  ('variant scenario 2', (50000, '0', [19014, 1025, 3517]), ['1.10', '16.20', '4.70'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: unbacked winner', (250000, '20', [41766, 0, 146516]), ['1.50', None, '1.10']),
  ('variant scenario 1', (20000, '16', [8054]), ['2.00']),
  ('variant scenario 2', (1234500, '20', [948216, 357944, 406471]), ['1.10', '1.10', '1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: unbacked winner', (20000, '16', [0]), [None]),
  ('variant scenario 1', (20000, '15', [15831, 15772]), ['1.10', '1.10']),
  ('variant scenario 2', (20000, '16', [19210]), ['1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: unbacked winner', (20000, '15', [0]), [None]),
  ('variant scenario 1', (50000, '16', [40000]), ['1.10']),
  ('variant scenario 2', (100000, '16', [1500, 50366]), ['28.00', '1.10'])],
 [('control single winner', (100000, '15', [25000]), ['3.40']),
  ('boundary breakage down', (100000, '16', [30000]), ['2.80']),
  ('boundary minimum dividend', (100000, '20', [90000]), ['1.10']),
  ('boundary dead heat split', (100000, '20', [10000, 40000]), ['4.00', '1.10']),
  ('control unbacked winner', (100000, '15', [0]), [None]),
  ('regression: unbacked winner', (1234500, '0', [636655, 0, 10000]), ['1.10', None, '41.10']),
  ('variant scenario 1', (50000, '0', [27761]), ['1.80']),
  ('variant scenario 2', (20000, '20', [5443, 16144]), ['1.40', '1.10'])]]
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 winner nobody backed raises a division error or pays 0.00.

Pari-mutuel win dividend per unit stake. The net pool is pool * (100 - takeout_pct) / 100; with a dead heat it is split equally among the winning runners. Each runner's dividend is its share divided by the stakes on it, broken down to the 10-cent step below (breakage), with a minimum of 1.10. A winner with no stakes gets None. Return dividends as "D.D0" strings in winners order.

split: open-access


prompt:
A 25 percent boost on 2.00 pays as if the price were 2.50.

Profit boost promotion. Normal profit = stake * (price - 1). The boost increases the profit by boost_pct percent, but the extra winnings over the normal profit are capped at max_extra_cents. The displayed boosted price is 1 + (price - 1) * (1 + boost/100) rounded half up to two decimals (display only). Return [displayed price, potential return = stake + floor(normal profit + extra)].

split: open-access


prompt:
Large boosted bets exceed the promotional cap, or pay less than the unboosted price.

Profit boost promotion. Normal profit = stake * (price - 1). The boost increases the profit by boost_pct percent, but the extra winnings over the normal profit are capped at max_extra_cents. The displayed boosted price is 1 + (price - 1) * (1 + boost/100) rounded half up to two decimals (display only). Return [displayed price, potential return = stake + floor(normal profit + extra)].

split: open-access


prompt:
The bet slip shows 2.50 for a 25 percent boost on 2.00.

Profit boost promotion. Normal profit = stake * (price - 1). The boost increases the profit by boost_pct percent, but the extra winnings over the normal profit are capped at max_extra_cents. The displayed boosted price is 1 + (price - 1) * (1 + boost/100) rounded half up to two decimals (display only). Return [displayed price, potential return = stake + floor(normal profit + extra)].

split: open-access


source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(legs, points, stake_cents):
    TABLE = {2: -120, 3: 160, 4: 260, 5: 400}
    wins = 0
    for line, margin in legs:
        adj = Fraction(line) + Fraction(points) if Fraction(line) < 0 else Fraction(line)
        v = margin + adj
        if v < 0:
            return ['lose', 0]
        if v > 0:
            wins += 1
    if wins < 2:
        return ['refund', stake_cents]
    am = TABLE[min(wins, 5)]
    dec = 1 + (Fraction(am, 100) if am > 0 else Fraction(100, -am))
    return ['win', math.floor(stake_cents * dec)]
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-team teaser', ([['-7.5', 3], ['+2.5', -5]], '6', 1200), ['win', 2200]),
  ('boundary push drops a leg', ([['-7', 1], ['+3', 0], ['-1', 2]], '6', 1000), ['win', 1833]),
  ('boundary reduced to one leg', ([['-7', 1], ['+3', 5]], '6', 1000), ['refund', 1000]),
  ('control losing leg', ([['-10', 2], ['+3', 5], ['+7', 0]], '6', 1000), ['lose', 0]),
  ('control three winners', ([['-3', 1], ['+3', 0], ['-1', 0]], '6', 1000), ['win', 2600]),
  ('regression: line shift direction',
   ([['-7', 5], ['+7', 0], ['+7', -10]], '6', 500),
   ['win', 1300]),
  ('variant scenario 1', ([['+1.5', 11], ['-10', 4], ['-10', -5]], '7', 1100), ['lose', 0]),
  ('variant scenario 2',
   ([['-7.5', -8], ['-7', 14], ['-3', 9], ['+7', 13], ['-3', 0], ['-7', 8]], '6', 1000),
   ['lose', 0])],
 [('control two-team teaser', ([['-7.5', 3], ['+2.5', -5]], '6', 1200), ['win', 2200]),
  ('boundary push drops a leg', ([['-7', 1], ['+3', 0], ['-1', 2]], '6', 1000), ['win', 1833]),
  ('boundary reduced to one leg', ([['-7', 1], ['+3', 5]], '6', 1000), ['refund', 1000]),
  ('control losing leg', ([['-10', 2], ['+3', 5], ['+7', 0]], '6', 1000), ['lose', 0]),
  ('control three winners', ([['-3', 1], ['+3', 0], ['-1', 0]], '6', 1000), ['win', 2600]),
  ('regression: line shift direction',
   ([['+1.5', 11], ['+3', -7], ['+7', 9], ['+1.5', 2], ['-10', 12]], '7', 1000),
   ['win', 5000]),
  ('variant scenario 1',
   ([['+1.5', -13], ['+1.5', 2], ['-10', 9], ['-7.5', -7], ['-7.5', 7]], '6.5', 1100),
   ['lose', 0]),
  ('variant scenario 2', ([['-7.5', -12], ['-7.5', 13]], '6.5', 1000), ['lose', 0])],
 [('control two-team teaser', ([['-7.5', 3], ['+2.5', -5]], '6', 1200), ['win', 2200]),
  ('boundary push drops a leg', ([['-7', 1], ['+3', 0], ['-1', 2]], '6', 1000), ['win', 1833]),
  ('boundary reduced to one leg', ([['-7', 1], ['+3', 5]], '6', 1000), ['refund', 1000]),
  ('control losing leg', ([['-10', 2], ['+3', 5], ['+7', 0]], '6', 1000), ['lose', 0]),
  ('control three winners', ([['-3', 1], ['+3', 0], ['-1', 0]], '6', 1000), ['win', 2600]),
  ('regression: line shift direction', ([['+2.5', -2], ['+3', 1]], '6', 1100), ['win', 2016]),
  ('regression: line shift direction', ([['+3', -9], ['-10', 6]], '6', 1100), ['refund', 1100]),
  ('variant scenario 1',
   ([['-10', 10], ['-7', -5], ['+7', -6], ['-3', 3], ['-1', -4], ['+7', -2]], '7', 1000),
   ['lose', 0]),
  ('variant scenario 2', ([['+1.5', -12], ['-7', -11], ['-7', -3]], '6.5', 1000), ['lose', 0])],
 [('control two-team teaser', ([['-7.5', 3], ['+2.5', -5]], '6', 1200), ['win', 2200]),
  ('boundary push drops a leg', ([['-7', 1], ['+3', 0], ['-1', 2]], '6', 1000), ['win', 1833]),
  ('boundary reduced to one leg', ([['-7', 1], ['+3', 5]], '6', 1000), ['refund', 1000]),
  ('control losing leg', ([['-10', 2], ['+3', 5], ['+7', 0]], '6', 1000), ['lose', 0]),
  ('control three winners', ([['-3', 1], ['+3', 0], ['-1', 0]], '6', 1000), ['win', 2600]),
  ('regression: line shift direction',
   ([['+3', 11], ['+1.5', 7], ['-3', 4], ['-7', 2]], '6.5', 1100),
   ['win', 3960]),
  ('regression: line shift direction', ([['-1', 3], ['+7', -8]], '7', 1000), ['win', 1833]),
  ('variant scenario 1', ([['-7.5', 4], ['-7.5', -1], ['+1.5', -12]], '7', 1000), ['lose', 0]),
  ('variant scenario 2', ([['+7', 0], ['-7.5', -14], ['-7', 9]], '6', 500), ['lose', 0])],
 [('control two-team teaser', ([['-7.5', 3], ['+2.5', -5]], '6', 1200), ['win', 2200]),
  ('boundary push drops a leg', ([['-7', 1], ['+3', 0], ['-1', 2]], '6', 1000), ['win', 1833]),
  ('boundary reduced to one leg', ([['-7', 1], ['+3', 5]], '6', 1000), ['refund', 1000]),
  ('control losing leg', ([['-10', 2], ['+3', 5], ['+7', 0]], '6', 1000), ['lose', 0]),
  ('control three winners', ([['-3', 1], ['+3', 0], ['-1', 0]], '6', 1000), ['win', 2600]),
  ('regression: line shift direction',
   ([['-10', 11], ['+3', -4], ['-3', 1], ['+7', -12]], '6', 1000),
   ['win', 3600]),
  ('variant scenario 1', ([['-7', -12], ['-7', -2]], '6', 500), ['lose', 0]),
  ('variant scenario 2',
   ([['-1', -7], ['-7.5', 12], ['-7.5', -12], ['+3', 8], ['-10', -2]], '7', 1000),
   ['lose', 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:
Favourites become bigger favourites after teasing.

Point-spread teaser. legs rows are [team spread line, team margin of victory]; every line is moved in the bettor's favour by points (adjusted = line + points). A leg wins if margin + adjusted > 0, pushes if = 0, loses if < 0. Any losing leg loses the ticket. Pushed legs are dropped; fewer than 2 remaining winners refunds the stake. Payout by winning legs from the American table {2: -120, 3: +160, 4: +260, 5: +400} (5 or more pay +400). Return [status, return cents rounded down].

split: open-access


prompt:
A leg landing exactly on the teased number wins, or kills the ticket.

Point-spread teaser. legs rows are [team spread line, team margin of victory]; every line is moved in the bettor's favour by points (adjusted = line + points). A leg wins if margin + adjusted > 0, pushes if = 0, loses if < 0. Any losing leg loses the ticket. Pushed legs are dropped; fewer than 2 remaining winners refunds the stake. Payout by winning legs from the American table {2: -120, 3: +160, 4: +260, 5: +400} (5 or more pay +400). Return [status, return 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, points, stake_cents):
    TABLE = {2: -120, 3: 160, 4: 260, 5: 400}
    wins = 0
    for line, margin in legs:
        adj = Fraction(line) + Fraction(points)
        v = margin + adj
        if v < 0:
            return ['lose', 0]
        if v > 0:
            wins += 1
    if wins < 1:
        return ['refund', stake_cents]
    am = TABLE[min(wins, 5)]
    dec = 1 + (Fraction(am, 100) if am > 0 else Fraction(100, -am))
    return ['win', math.floor(stake_cents * dec)]
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-team teaser', ([['-7.5', 3], ['+2.5', -5]], '6', 1200), ['win', 2200]),
  ('boundary push drops a leg', ([['-7', 1], ['+3', 0], ['-1', 2]], '6', 1000), ['win', 1833]),
  ('boundary reduced to one leg', ([['-7', 1], ['+3', 5]], '6', 1000), ['refund', 1000]),
  ('control losing leg', ([['-10', 2], ['+3', 5], ['+7', 0]], '6', 1000), ['lose', 0]),
  ('control three winners', ([['-3', 1], ['+3', 0], ['-1', 0]], '6', 1000), ['win', 2600]),
  ('regression: reduction to one', ([['-7', 1], ['+3', 5]], '6', 1000), ['refund', 1000]),
  ('variant scenario 1',
   ([['+7', -3], ['-6', -11], ['+2.5', 8], ['-7', -7], ['+3', -5]], '7', 1100),
   ['lose', 0]),
  ('variant scenario 2', ([['+7', -13], ['+3', -5], ['+1.5', 2]], '6.5', 1000), ['win', 2600])],
 [('control two-team teaser', ([['-7.5', 3], ['+2.5', -5]], '6', 1200), ['win', 2200]),
  ('boundary push drops a leg', ([['-7', 1], ['+3', 0], ['-1', 2]], '6', 1000), ['win', 1833]),
  ('boundary reduced to one leg', ([['-7', 1], ['+3', 5]], '6', 1000), ['refund', 1000]),
  ('control losing leg', ([['-10', 2], ['+3', 5], ['+7', 0]], '6', 1000), ['lose', 0]),
  ('control three winners', ([['-3', 1], ['+3', 0], ['-1', 0]], '6', 1000), ['win', 2600]),
  ('regression: reduction to one', ([['+2.5', 5], ['+2.5', -9]], '6.5', 1000), ['refund', 1000]),
  ('variant scenario 1', ([['-6', 7], ['-7', 7], ['-7', 14]], '6.5', 1100), ['win', 2860]),
  ('variant scenario 2', ([['+7', 10], ['+7', 11]], '6.5', 1100), ['win', 2016])],
 [('control two-team teaser', ([['-7.5', 3], ['+2.5', -5]], '6', 1200), ['win', 2200]),
  ('boundary push drops a leg', ([['-7', 1], ['+3', 0], ['-1', 2]], '6', 1000), ['win', 1833]),
  ('boundary reduced to one leg', ([['-7', 1], ['+3', 5]], '6', 1000), ['refund', 1000]),
  ('control losing leg', ([['-10', 2], ['+3', 5], ['+7', 0]], '6', 1000), ['lose', 0]),
  ('control three winners', ([['-3', 1], ['+3', 0], ['-1', 0]], '6', 1000), ['win', 2600]),
  ('regression: reduction to one', ([['+7', 10], ['-10', 3]], '7', 500), ['refund', 500]),
  ('variant scenario 1', ([['-10', -2], ['-1', -5], ['+1.5', -7]], '6', 500), ['lose', 0]),
  ('variant scenario 2',
   ([['-7.5', 14], ['-10', 1], ['-3', 1], ['+1.5', -4]], '6.5', 500),
   ['lose', 0])],
 [('control two-team teaser', ([['-7.5', 3], ['+2.5', -5]], '6', 1200), ['win', 2200]),
  ('boundary push drops a leg', ([['-7', 1], ['+3', 0], ['-1', 2]], '6', 1000), ['win', 1833]),
  ('boundary reduced to one leg', ([['-7', 1], ['+3', 5]], '6', 1000), ['refund', 1000]),
  ('control losing leg', ([['-10', 2], ['+3', 5], ['+7', 0]], '6', 1000), ['lose', 0]),
  ('control three winners', ([['-3', 1], ['+3', 0], ['-1', 0]], '6', 1000), ['win', 2600]),
  ('regression: reduction to one', ([['-6', 10], ['-1', -6]], '7', 1100), ['refund', 1100]),
  ('variant scenario 1',
   ([['+3', 2], ['+1.5', 8], ['+1.5', -3], ['+7', 10], ['-3', -3]], '6.5', 1100),
   ['win', 5500]),
  ('variant scenario 2',
   ([['+1.5', -4], ['-7', 9], ['-7.5', -10], ['-6', -7]], '7', 500),
   ['lose', 0])],
 [('control two-team teaser', ([['-7.5', 3], ['+2.5', -5]], '6', 1200), ['win', 2200]),
  ('boundary push drops a leg', ([['-7', 1], ['+3', 0], ['-1', 2]], '6', 1000), ['win', 1833]),
  ('boundary reduced to one leg', ([['-7', 1], ['+3', 5]], '6', 1000), ['refund', 1000]),
  ('control losing leg', ([['-10', 2], ['+3', 5], ['+7', 0]], '6', 1000), ['lose', 0]),
  ('control three winners', ([['-3', 1], ['+3', 0], ['-1', 0]], '6', 1000), ['win', 2600]),
  ('regression: reduction to one', ([['-1', -5], ['+3', 6]], '6', 1000), ['refund', 1000]),
  ('variant scenario 1',
   ([['+2.5', 7], ['-6', 10], ['-1', -5], ['+7', 7]], '6', 1000),
   ['win', 2600]),
  ('variant scenario 2', ([['-7.5', -3], ['+2.5', -11]], '6', 1100), ['lose', 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 two-team teaser with one push crashes or is graded a loss.

Point-spread teaser. legs rows are [team spread line, team margin of victory]; every line is moved in the bettor's favour by points (adjusted = line + points). A leg wins if margin + adjusted > 0, pushes if = 0, loses if < 0. Any losing leg loses the ticket. Pushed legs are dropped; fewer than 2 remaining winners refunds the stake. Payout by winning legs from the American table {2: -120, 3: +160, 4: +260, 5: +400} (5 or more pay +400). Return [status, return cents rounded down].

split: open-access