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:
            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: line orientation', ('+0.75', 0, 4, 999, '1.90'), [0, 'lose']),
  ('regression: line orientation', ('-1.5', 2, 3, 500, '2.00'), [0, 'lose']),
  ('variant scenario 1', ('-0.3', 0, 0, 999, '1.90'), 'invalid line'),
  ('variant scenario 2', ('-0.3', 2, 0, 250, '2.00'), 'invalid line')],
 [('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: line orientation', ('-0.25', 4, 0, 999, '1.90'), [1898, 'win']),
  ('regression: line orientation', ('-0.25', 3, 3, 500, '2.00'), [250, 'half-lose']),
  ('variant scenario 1', ('+1.25', 1, 3, 999, '2.05'), [0, 'lose']),
  ('variant scenario 2', ('-0.5', 3, 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: line orientation', ('+0.25', 0, 0, 999, '1.85'), [1423, 'half-win']),
  ('regression: line orientation', ('+0.75', 2, 4, 1000, '2.00'), [0, 'lose']),
  ('variant scenario 1', ('-0.5', 1, 0, 250, '2.00'), [500, 'win']),
  ('variant scenario 2', ('-1.5', 4, 0, 250, '2.00'), [500, '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: line orientation', ('-0.25', 4, 0, 250, '2.05'), [512, 'win']),
  ('regression: line orientation', ('-1.75', 2, 3, 999, '1.85'), [0, 'lose']),
  ('variant scenario 1', ('-0.3', 1, 2, 250, '1.90'), 'invalid line'),
  ('variant scenario 2', ('+0.25', 4, 3, 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: line orientation', ('+0.5', 4, 2, 500, '2.00'), [1000, 'win']),
  ('regression: line orientation', ('+0.75', 4, 3, 250, '1.85'), [462, 'win']),
  ('variant scenario 1', ('+0.75', 2, 0, 1000, '1.90'), [1900, 'win']),
  ('variant scenario 2', ('-1', 0, 3, 250, '2.05'), [0, 'lose'])]]
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 = away_goals - home_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: line orientation', ('+0.75', 0, 4, 999, '1.90'), [0, 'lose']),
  ('regression: line orientation', ('-1.5', 2, 3, 500, '2.00'), [0, 'lose']),
  ('variant scenario 1', ('-0.3', 0, 0, 999, '1.90'), 'invalid line'),
  ('variant scenario 2', ('-0.3', 2, 0, 250, '2.00'), 'invalid line')],
 [('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: line orientation', ('-0.25', 4, 0, 999, '1.90'), [1898, 'win']),
  ('regression: line orientation', ('-0.25', 3, 3, 500, '2.00'), [250, 'half-lose']),
  ('variant scenario 1', ('+1.25', 1, 3, 999, '2.05'), [0, 'lose']),
  ('variant scenario 2', ('-0.5', 3, 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: line orientation', ('+0.25', 0, 0, 999, '1.85'), [1423, 'half-win']),
  ('regression: line orientation', ('+0.75', 2, 4, 1000, '2.00'), [0, 'lose']),
  ('variant scenario 1', ('-0.5', 1, 0, 250, '2.00'), [500, 'win']),
  ('variant scenario 2', ('-1.5', 4, 0, 250, '2.00'), [500, '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: line orientation', ('-0.25', 4, 0, 250, '2.05'), [512, 'win']),
  ('regression: line orientation', ('-1.75', 2, 3, 999, '1.85'), [0, 'lose']),
  ('variant scenario 1', ('-0.3', 1, 2, 250, '1.90'), 'invalid line'),
  ('variant scenario 2', ('+0.25', 4, 3, 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: line orientation', ('+0.5', 4, 2, 500, '2.00'), [1000, 'win']),
  ('regression: line orientation', ('+0.75', 4, 3, 250, '1.85'), [462, 'win']),
  ('variant scenario 1', ('+0.75', 2, 0, 1000, '1.90'), [1900, 'win']),
  ('variant scenario 2', ('-1', 0, 3, 250, '2.05'), [0, 'lose'])]]
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 home -1.5 bet wins when the home side loses.

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 * 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 += 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 grid guard', ('-0.75', 1, 0, 999, '2.00'), [1498, 'half-win']),
  ('regression: quarter grid guard', ('-0.3', 3, 0, 500, '2.00'), 'invalid line'),
  ('variant scenario 1', ('+2', 3, 0, 1000, '2.00'), [2000, 'win']),
  ('variant scenario 2', ('0', 4, 4, 500, '1.90'), [500, 'push'])],
 [('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 grid guard', ('-1.75', 1, 2, 250, '2.05'), [0, 'lose']),
  ('regression: quarter grid guard', ('-0.3', 2, 4, 999, '1.90'), 'invalid line'),
  ('variant scenario 1', ('+2', 2, 4, 500, '2.00'), [500, 'push']),
  ('variant scenario 2', ('+2', 2, 2, 500, '1.90'), [950, '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 grid guard', ('-0.25', 0, 4, 250, '2.00'), [0, 'lose']),
  ('regression: quarter grid guard', ('-0.3', 0, 2, 500, '1.90'), 'invalid line'),
  ('variant scenario 1', ('0', 4, 3, 999, '1.85'), [1848, 'win']),
  ('variant scenario 2', ('-0.75', 1, 2, 500, '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: quarter grid guard', ('+0.25', 3, 2, 1000, '1.85'), [1850, 'win']),
  ('regression: quarter grid guard', ('-0.3', 2, 1, 500, '2.00'), 'invalid line'),
  ('variant scenario 1', ('0', 3, 4, 999, '2.00'), [0, 'lose']),
  ('variant scenario 2', ('-1.75', 3, 4, 999, '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: quarter grid guard', ('-1.75', 1, 3, 1000, '1.85'), [0, 'lose']),
  ('regression: quarter grid guard', ('-0.3', 0, 2, 500, '2.00'), 'invalid line'),
  ('variant scenario 1', ('+2', 2, 4, 250, '2.00'), [250, 'push']),
  ('variant scenario 2', ('-0.5', 1, 0, 1000, '1.90'), [1900, '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)

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(line, home_goals, away_goals, stake_cents, price):
    L = Fraction(line)
    if (L * 2).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 += 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 grid guard', ('-0.75', 1, 0, 999, '2.00'), [1498, 'half-win']),
  ('regression: quarter grid guard', ('-0.3', 3, 0, 500, '2.00'), 'invalid line'),
  ('variant scenario 1', ('+2', 3, 0, 1000, '2.00'), [2000, 'win']),
  ('variant scenario 2', ('0', 4, 4, 500, '1.90'), [500, 'push'])],
 [('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 grid guard', ('-1.75', 1, 2, 250, '2.05'), [0, 'lose']),
  ('regression: quarter grid guard', ('-0.3', 2, 4, 999, '1.90'), 'invalid line'),
  ('variant scenario 1', ('+2', 2, 4, 500, '2.00'), [500, 'push']),
  ('variant scenario 2', ('+2', 2, 2, 500, '1.90'), [950, '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 grid guard', ('-0.25', 0, 4, 250, '2.00'), [0, 'lose']),
  ('regression: quarter grid guard', ('-0.3', 0, 2, 500, '1.90'), 'invalid line'),
  ('variant scenario 1', ('0', 4, 3, 999, '1.85'), [1848, 'win']),
  ('variant scenario 2', ('-0.75', 1, 2, 500, '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: quarter grid guard', ('+0.25', 3, 2, 1000, '1.85'), [1850, 'win']),
  ('regression: quarter grid guard', ('-0.3', 2, 1, 500, '2.00'), 'invalid line'),
  ('variant scenario 1', ('0', 3, 4, 999, '2.00'), [0, 'lose']),
  ('variant scenario 2', ('-1.75', 3, 4, 999, '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: quarter grid guard', ('-1.75', 1, 3, 1000, '1.85'), [0, 'lose']),
  ('regression: quarter grid guard', ('-0.3', 0, 2, 500, '2.00'), 'invalid line'),
  ('variant scenario 1', ('+2', 2, 4, 250, '2.00'), [250, 'push']),
  ('variant scenario 2', ('-0.5', 1, 0, 1000, '1.90'), [1900, '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.3 line is settled, or a legitimate -0.25 line is rejected.

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(bets, rate_pct):
    nets = {}
    for market, side, stake, price, won in bets:
        p = Fraction(price)
        if side == 'back':
            pl = math.floor(stake * (p - 1)) if won else -stake
        else:
            pl = stake if won else -math.ceil(stake * (p - 1))
        nets[(market, len(nets))] = pl
    comm = 0
    for m, net in nets.items():
        if net > 0:
            comm += math.floor(net * Fraction(rate_pct) / 100 + Fraction(1, 2))
    return [sum(nets.values()) - comm, comm]
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 back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: per bet commission',
   ([['m1', 'back', 100, '5.20', False],
     ['m2', 'lay', 2000, '6.81', True],
     ['m3', 'back', 100, '6.84', False],
     ['m1', 'back', 777, '1.71', True],
     ['m2', 'lay', 2000, '4.81', False]],
    '6.5'),
   [-5298, 29]),
  ('variant scenario 1',
   ([['m3', 'back', 1000, '2.37', False],
     ['m3', 'lay', 1000, '5.47', True],
     ['m3', 'lay', 1000, '2.53', True],
     ['m3', 'back', 2000, '5.43', False]],
    '2'),
   [-1000, 0]),
  ('variant scenario 2',
   ([['m1', 'lay', 100, '6.53', True],
     ['m1', 'lay', 250, '1.42', False],
     ['m3', 'back', 100, '5.84', True],
     ['m1', 'back', 250, '4.21', False]],
    '6.5'),
   [198, 31])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: per bet commission', ([['m3', 'back', 100, '3.97', False]], '5'), [-100, 0]),
  ('regression: per bet commission',
   ([['m3', 'lay', 100, '2.39', True],
     ['m1', 'lay', 2000, '5.94', False],
     ['m3', 'back', 777, '3.75', True]],
    '6.5'),
   [-7789, 145]),
  ('variant scenario 1',
   ([['m1', 'back', 777, '1.23', False],
     ['m2', 'lay', 250, '7.80', True],
     ['m2', 'back', 100, '4.41', True]],
    '5'),
   [-216, 30]),
  ('variant scenario 2',
   ([['m3', 'back', 2000, '4.01', False],
     ['m1', 'lay', 100, '3.22', False],
     ['m3', 'lay', 777, '7.56', False],
     ['m1', 'back', 2000, '1.35', False]],
    '6.5'),
   [-9320, 0])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: per bet commission',
   ([['m1', 'lay', 1000, '2.47', True],
     ['m3', 'back', 777, '7.09', False],
     ['m3', 'lay', 2000, '2.84', True]],
    '5'),
   [2112, 111]),
  ('variant scenario 1', ([['m3', 'lay', 250, '4.16', False]], '5'), [-790, 0]),
  ('variant scenario 2',
   ([['m3', 'back', 2000, '1.81', False],
     ['m2', 'lay', 2000, '7.12', False],
     ['m1', 'lay', 250, '4.83', False]],
    '6.5'),
   [-15198, 0])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: per bet commission',
   ([['m3', 'lay', 100, '6.30', True],
     ['m1', 'back', 250, '7.35', False],
     ['m3', 'lay', 2000, '7.86', True]],
    '6.5'),
   [1713, 137]),
  ('regression: per bet commission',
   ([['m3', 'back', 250, '6.32', True],
     ['m3', 'back', 1000, '4.82', False],
     ['m3', 'lay', 250, '5.41', False],
     ['m1', 'lay', 100, '6.23', True],
     ['m2', 'lay', 777, '7.89', False]],
    '5'),
   [-6032, 5]),
  ('variant scenario 1',
   ([['m2', 'back', 1000, '5.07', True], ['m1', 'back', 250, '6.46', True]], '6.5'),
   [5081, 354]),
  ('variant scenario 2',
   ([['m3', 'back', 2000, '2.17', True],
     ['m2', 'back', 2000, '5.63', True],
     ['m1', 'back', 250, '2.32', False],
     ['m2', 'lay', 2000, '6.97', True]],
    '5'),
   [12670, 680])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: per bet commission',
   ([['m3', 'back', 2000, '4.23', False],
     ['m3', 'lay', 100, '4.06', False],
     ['m3', 'lay', 2000, '2.15', False],
     ['m2', 'lay', 250, '4.89', True],
     ['m3', 'back', 250, '5.27', False]],
    '5'),
   [-4619, 13]),
  ('regression: per bet commission',
   ([['m2', 'back', 100, '4.06', False],
     ['m2', 'lay', 1000, '3.28', True],
     ['m2', 'back', 1000, '3.20', False],
     ['m1', 'back', 2000, '2.10', False],
     ['m1', 'lay', 250, '4.14', False]],
    '2'),
   [-2885, 0]),
  ('variant scenario 1',
   ([['m1', 'lay', 2000, '2.07', False], ['m1', 'lay', 1000, '6.85', False]], '5'),
   [-7990, 0]),
  ('variant scenario 2',
   ([['m2', 'lay', 777, '1.87', True], ['m3', 'back', 100, '2.04', False]], '5'),
   [638, 39])]]
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(bets, rate_pct):
    nets = {}
    for market, side, stake, price, won in bets:
        p = Fraction(price)
        if side == 'back':
            pl = math.floor(stake * (p - 1)) if won else -stake
        else:
            pl = stake if won else -math.ceil(stake * (p - 1))
        nets[market] = nets.get(market, 0) + max(pl, 0)
    comm = 0
    for m, net in nets.items():
        if net > 0:
            comm += math.floor(net * Fraction(rate_pct) / 100 + Fraction(1, 2))
    return [sum(nets.values()) - comm, comm]
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 back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: per bet commission',
   ([['m1', 'back', 100, '5.20', False],
     ['m2', 'lay', 2000, '6.81', True],
     ['m3', 'back', 100, '6.84', False],
     ['m1', 'back', 777, '1.71', True],
     ['m2', 'lay', 2000, '4.81', False]],
    '6.5'),
   [-5298, 29]),
  ('variant scenario 1',
   ([['m3', 'back', 1000, '2.37', False],
     ['m3', 'lay', 1000, '5.47', True],
     ['m3', 'lay', 1000, '2.53', True],
     ['m3', 'back', 2000, '5.43', False]],
    '2'),
   [-1000, 0]),
  ('variant scenario 2',
   ([['m1', 'lay', 100, '6.53', True],
     ['m1', 'lay', 250, '1.42', False],
     ['m3', 'back', 100, '5.84', True],
     ['m1', 'back', 250, '4.21', False]],
    '6.5'),
   [198, 31])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: per bet commission', ([['m3', 'back', 100, '3.97', False]], '5'), [-100, 0]),
  ('regression: per bet commission',
   ([['m3', 'lay', 100, '2.39', True],
     ['m1', 'lay', 2000, '5.94', False],
     ['m3', 'back', 777, '3.75', True]],
    '6.5'),
   [-7789, 145]),
  ('variant scenario 1',
   ([['m1', 'back', 777, '1.23', False],
     ['m2', 'lay', 250, '7.80', True],
     ['m2', 'back', 100, '4.41', True]],
    '5'),
   [-216, 30]),
  ('variant scenario 2',
   ([['m3', 'back', 2000, '4.01', False],
     ['m1', 'lay', 100, '3.22', False],
     ['m3', 'lay', 777, '7.56', False],
     ['m1', 'back', 2000, '1.35', False]],
    '6.5'),
   [-9320, 0])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: per bet commission',
   ([['m1', 'lay', 1000, '2.47', True],
     ['m3', 'back', 777, '7.09', False],
     ['m3', 'lay', 2000, '2.84', True]],
    '5'),
   [2112, 111]),
  ('variant scenario 1', ([['m3', 'lay', 250, '4.16', False]], '5'), [-790, 0]),
  ('variant scenario 2',
   ([['m3', 'back', 2000, '1.81', False],
     ['m2', 'lay', 2000, '7.12', False],
     ['m1', 'lay', 250, '4.83', False]],
    '6.5'),
   [-15198, 0])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: per bet commission',
   ([['m3', 'lay', 100, '6.30', True],
     ['m1', 'back', 250, '7.35', False],
     ['m3', 'lay', 2000, '7.86', True]],
    '6.5'),
   [1713, 137]),
  ('regression: per bet commission',
   ([['m3', 'back', 250, '6.32', True],
     ['m3', 'back', 1000, '4.82', False],
     ['m3', 'lay', 250, '5.41', False],
     ['m1', 'lay', 100, '6.23', True],
     ['m2', 'lay', 777, '7.89', False]],
    '5'),
   [-6032, 5]),
  ('variant scenario 1',
   ([['m2', 'back', 1000, '5.07', True], ['m1', 'back', 250, '6.46', True]], '6.5'),
   [5081, 354]),
  ('variant scenario 2',
   ([['m3', 'back', 2000, '2.17', True],
     ['m2', 'back', 2000, '5.63', True],
     ['m1', 'back', 250, '2.32', False],
     ['m2', 'lay', 2000, '6.97', True]],
    '5'),
   [12670, 680])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: per bet commission',
   ([['m3', 'back', 2000, '4.23', False],
     ['m3', 'lay', 100, '4.06', False],
     ['m3', 'lay', 2000, '2.15', False],
     ['m2', 'lay', 250, '4.89', True],
     ['m3', 'back', 250, '5.27', False]],
    '5'),
   [-4619, 13]),
  ('regression: per bet commission',
   ([['m2', 'back', 100, '4.06', False],
     ['m2', 'lay', 1000, '3.28', True],
     ['m2', 'back', 1000, '3.20', False],
     ['m1', 'back', 2000, '2.10', False],
     ['m1', 'lay', 250, '4.14', False]],
    '2'),
   [-2885, 0]),
  ('variant scenario 1',
   ([['m1', 'lay', 2000, '2.07', False], ['m1', 'lay', 1000, '6.85', False]], '5'),
   [-7990, 0]),
  ('variant scenario 2',
   ([['m2', 'lay', 777, '1.87', True], ['m3', 'back', 100, '2.04', False]], '5'),
   [638, 39])]]
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 hedged market pays commission on the winning leg despite a small net profit.

Betting exchange settlement. bets rows are [market, side, stake_cents, price, won] where won says whether the bet won. Back: win profit floor(stake * (price - 1)), loss -stake. Lay: win +stake, loss -ceil(stake * (price - 1)) (the liability). Commission is charged per market on the market net profit only when that net is positive, at rate_pct percent rounded half up to a cent. Return [total net after commission, total commission] in cents.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(bets, rate_pct):
    nets = {}
    for market, side, stake, price, won in bets:
        p = Fraction(price)
        if side == 'back':
            pl = math.floor(stake * (p - 1)) if won else -stake
        else:
            pl = stake if won else -stake
        nets[market] = nets.get(market, 0) + pl
    comm = 0
    for m, net in nets.items():
        if net > 0:
            comm += math.floor(net * Fraction(rate_pct) / 100 + Fraction(1, 2))
    return [sum(nets.values()) - comm, comm]
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 back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: lay liability',
   ([['m3', 'back', 2000, '3.91', True],
     ['m3', 'back', 1000, '4.34', True],
     ['m2', 'back', 1000, '5.86', True],
     ['m3', 'lay', 2000, '1.49', False]],
    '6.5'),
   [12192, 848]),
  ('variant scenario 1',
   ([['m1', 'back', 2000, '5.34', True],
     ['m1', 'back', 100, '2.32', True],
     ['m2', 'lay', 1000, '7.42', False],
     ['m2', 'lay', 1000, '6.91', False],
     ['m2', 'lay', 2000, '4.87', True]],
    '6.5'),
   [-2091, 573]),
  ('variant scenario 2',
   ([['m2', 'back', 2000, '1.48', False],
     ['m2', 'back', 250, '5.52', False],
     ['m2', 'back', 1000, '7.14', True],
     ['m1', 'lay', 777, '7.92', False]],
    '6.5'),
   [-1740, 253])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: lay liability',
   ([['m2', 'lay', 777, '7.74', False], ['m2', 'lay', 2000, '6.02', True]], '5'),
   [-3237, 0]),
  ('variant scenario 1', ([['m1', 'lay', 1000, '3.82', False]], '5'), [-2820, 0]),
  ('variant scenario 2',
   ([['m3', 'back', 250, '2.61', True], ['m2', 'lay', 250, '7.61', True]], '2'),
   [639, 13])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: lay liability',
   ([['m1', 'lay', 2000, '7.65', False],
     ['m1', 'back', 100, '7.65', True],
     ['m2', 'lay', 250, '3.87', True],
     ['m3', 'back', 250, '7.51', True]],
    '5'),
   [-10852, 94]),
  ('variant scenario 1',
   ([['m1', 'back', 777, '2.00', True],
     ['m3', 'lay', 100, '3.56', True],
     ['m1', 'back', 100, '7.20', False]],
    '2'),
   [761, 16]),
  ('variant scenario 2', ([['m3', 'lay', 2000, '3.18', True]], '2'), [1960, 40])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: lay liability',
   ([['m3', 'lay', 1000, '5.16', True],
     ['m3', 'back', 100, '3.04', True],
     ['m1', 'back', 2000, '5.82', False],
     ['m3', 'lay', 250, '3.59', False],
     ['m1', 'lay', 2000, '3.53', True]],
    '2'),
   [545, 11]),
  ('variant scenario 1', ([['m1', 'back', 100, '6.47', True]], '2'), [536, 11]),
  ('variant scenario 2',
   ([['m2', 'lay', 2000, '7.84', True],
     ['m1', 'back', 250, '6.18', False],
     ['m2', 'back', 100, '7.05', True]],
    '2'),
   [2303, 52])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: lay liability',
   ([['m2', 'back', 2000, '1.66', False],
     ['m3', 'lay', 2000, '7.57', True],
     ['m2', 'back', 250, '5.20', False],
     ['m3', 'back', 100, '7.50', True],
     ['m3', 'lay', 250, '2.34', False]],
    '2'),
   [19, 46]),
  ('variant scenario 1', ([['m1', 'lay', 100, '7.27', True]], '2'), [98, 2]),
  ('variant scenario 2', ([['m1', 'back', 777, '6.40', True]], '5'), [3985, 210])]]
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(bets, rate_pct):
    nets = {}
    for market, side, stake, price, won in bets:
        p = Fraction(price)
        if side == 'back':
            pl = math.floor(stake * (p - 1)) if won else -stake
        else:
            pl = stake if won else -math.ceil(stake * p)
        nets[market] = nets.get(market, 0) + pl
    comm = 0
    for m, net in nets.items():
        if net > 0:
            comm += math.floor(net * Fraction(rate_pct) / 100 + Fraction(1, 2))
    return [sum(nets.values()) - comm, comm]
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 back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: lay liability',
   ([['m3', 'back', 2000, '3.91', True],
     ['m3', 'back', 1000, '4.34', True],
     ['m2', 'back', 1000, '5.86', True],
     ['m3', 'lay', 2000, '1.49', False]],
    '6.5'),
   [12192, 848]),
  ('variant scenario 1',
   ([['m1', 'back', 2000, '5.34', True],
     ['m1', 'back', 100, '2.32', True],
     ['m2', 'lay', 1000, '7.42', False],
     ['m2', 'lay', 1000, '6.91', False],
     ['m2', 'lay', 2000, '4.87', True]],
    '6.5'),
   [-2091, 573]),
  ('variant scenario 2',
   ([['m2', 'back', 2000, '1.48', False],
     ['m2', 'back', 250, '5.52', False],
     ['m2', 'back', 1000, '7.14', True],
     ['m1', 'lay', 777, '7.92', False]],
    '6.5'),
   [-1740, 253])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: lay liability',
   ([['m2', 'lay', 777, '7.74', False], ['m2', 'lay', 2000, '6.02', True]], '5'),
   [-3237, 0]),
  ('variant scenario 1', ([['m1', 'lay', 1000, '3.82', False]], '5'), [-2820, 0]),
  ('variant scenario 2',
   ([['m3', 'back', 250, '2.61', True], ['m2', 'lay', 250, '7.61', True]], '2'),
   [639, 13])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: lay liability',
   ([['m1', 'lay', 2000, '7.65', False],
     ['m1', 'back', 100, '7.65', True],
     ['m2', 'lay', 250, '3.87', True],
     ['m3', 'back', 250, '7.51', True]],
    '5'),
   [-10852, 94]),
  ('variant scenario 1',
   ([['m1', 'back', 777, '2.00', True],
     ['m3', 'lay', 100, '3.56', True],
     ['m1', 'back', 100, '7.20', False]],
    '2'),
   [761, 16]),
  ('variant scenario 2', ([['m3', 'lay', 2000, '3.18', True]], '2'), [1960, 40])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: lay liability',
   ([['m3', 'lay', 1000, '5.16', True],
     ['m3', 'back', 100, '3.04', True],
     ['m1', 'back', 2000, '5.82', False],
     ['m3', 'lay', 250, '3.59', False],
     ['m1', 'lay', 2000, '3.53', True]],
    '2'),
   [545, 11]),
  ('variant scenario 1', ([['m1', 'back', 100, '6.47', True]], '2'), [536, 11]),
  ('variant scenario 2',
   ([['m2', 'lay', 2000, '7.84', True],
     ['m1', 'back', 250, '6.18', False],
     ['m2', 'back', 100, '7.05', True]],
    '2'),
   [2303, 52])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: lay liability',
   ([['m2', 'back', 2000, '1.66', False],
     ['m3', 'lay', 2000, '7.57', True],
     ['m2', 'back', 250, '5.20', False],
     ['m3', 'back', 100, '7.50', True],
     ['m3', 'lay', 250, '2.34', False]],
    '2'),
   [19, 46]),
  ('variant scenario 1', ([['m1', 'lay', 100, '7.27', True]], '2'), [98, 2]),
  ('variant scenario 2', ([['m1', 'back', 777, '6.40', True]], '5'), [3985, 210])]]
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 losing lay at 4.00 costs only the backer stake.

Betting exchange settlement. bets rows are [market, side, stake_cents, price, won] where won says whether the bet won. Back: win profit floor(stake * (price - 1)), loss -stake. Lay: win +stake, loss -ceil(stake * (price - 1)) (the liability). Commission is charged per market on the market net profit only when that net is positive, at rate_pct percent rounded half up to a cent. Return [total net after commission, total commission] in cents.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(bets, rate_pct):
    nets = {}
    for market, side, stake, price, won in bets:
        p = Fraction(price)
        if side == 'back':
            pl = math.floor(stake * (p - 1)) if won else -stake
        else:
            pl = stake if won else -math.ceil(stake * (p - 1))
        nets[market] = nets.get(market, 0) + pl
    comm = 0
    for m, net in nets.items():
        comm += math.floor(net * Fraction(rate_pct) / 100 + Fraction(1, 2))
    return [sum(nets.values()) - comm, comm]
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 back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: loss market commission',
   ([['m1', 'back', 250, '7.43', True],
     ['m1', 'back', 250, '5.08', True],
     ['m2', 'back', 250, '6.10', False]],
    '2'),
   [2324, 53]),
  ('variant scenario 1',
   ([['m1', 'back', 777, '5.62', True], ['m3', 'back', 100, '2.02', False]], '6.5'),
   [3256, 233]),
  ('variant scenario 2', ([['m3', 'lay', 777, '6.38', False]], '2'), [-4181, 0])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: loss market commission',
   ([['m1', 'back', 250, '4.78', False], ['m3', 'lay', 1000, '4.13', False]], '5'),
   [-3380, 0]),
  ('variant scenario 1', ([['m1', 'lay', 2000, '7.96', True]], '5'), [1900, 100]),
  ('variant scenario 2',
   ([['m3', 'lay', 2000, '2.30', True],
     ['m1', 'back', 1000, '2.62', False],
     ['m1', 'lay', 777, '6.91', False],
     ['m2', 'back', 100, '2.31', True],
     ['m1', 'lay', 250, '5.96', True]],
    '2'),
   [-3255, 43])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: loss market commission',
   ([['m1', 'lay', 777, '6.98', False],
     ['m3', 'back', 250, '4.94', False],
     ['m1', 'back', 777, '5.13', True],
     ['m3', 'back', 2000, '7.64', True]],
    '6.5'),
   [10745, 847]),
  ('variant scenario 1',
   ([['m2', 'back', 250, '4.54', True],
     ['m3', 'back', 250, '4.14', True],
     ['m3', 'lay', 250, '3.05', False],
     ['m2', 'lay', 1000, '2.30', True]],
    '6.5'),
   [2016, 141]),
  ('variant scenario 2',
   ([['m2', 'back', 777, '3.62', True],
     ['m2', 'back', 1000, '2.28', False],
     ['m3', 'back', 250, '7.79', False]],
    '5'),
   [733, 52])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: loss market commission',
   ([['m2', 'lay', 777, '1.69', False],
     ['m1', 'lay', 100, '7.97', True],
     ['m1', 'back', 250, '4.99', False],
     ['m3', 'lay', 250, '2.98', True],
     ['m1', 'lay', 777, '1.65', False]],
    '2'),
   [-948, 5]),
  ('variant scenario 1',
   ([['m3', 'lay', 2000, '3.64', False], ['m2', 'back', 1000, '6.39', True]], '6.5'),
   [-240, 350]),
  ('variant scenario 2',
   ([['m2', 'lay', 1000, '7.63', True],
     ['m2', 'back', 2000, '1.39', True],
     ['m3', 'back', 1000, '6.88', True]],
    '5'),
   [7277, 383])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: loss market commission',
   ([['m2', 'lay', 777, '1.85', False],
     ['m1', 'back', 1000, '2.64', False],
     ['m1', 'lay', 2000, '3.74', False],
     ['m2', 'back', 1000, '7.08', True],
     ['m3', 'back', 1000, '5.02', False]],
    '2'),
   [-2169, 108]),
  ('variant scenario 1', ([['m2', 'lay', 777, '7.81', False]], '6.5'), [-5292, 0]),
  ('variant scenario 2',
   ([['m1', 'back', 777, '2.56', False], ['m3', 'back', 1000, '2.29', True]], '2'),
   [487, 26])]]
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(bets, rate_pct):
    nets = {}
    for market, side, stake, price, won in bets:
        p = Fraction(price)
        if side == 'back':
            pl = math.floor(stake * (p - 1)) if won else -stake
        else:
            pl = stake if won else -math.ceil(stake * (p - 1))
        nets[market] = nets.get(market, 0) + pl
    comm = 0
    for m, net in nets.items():
        comm += math.floor(abs(net) * Fraction(rate_pct) / 100 + Fraction(1, 2))
    return [sum(nets.values()) - comm, comm]
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 back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: loss market commission',
   ([['m1', 'back', 250, '7.43', True],
     ['m1', 'back', 250, '5.08', True],
     ['m2', 'back', 250, '6.10', False]],
    '2'),
   [2324, 53]),
  ('variant scenario 1',
   ([['m1', 'back', 777, '5.62', True], ['m3', 'back', 100, '2.02', False]], '6.5'),
   [3256, 233]),
  ('variant scenario 2', ([['m3', 'lay', 777, '6.38', False]], '2'), [-4181, 0])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: loss market commission',
   ([['m1', 'back', 250, '4.78', False], ['m3', 'lay', 1000, '4.13', False]], '5'),
   [-3380, 0]),
  ('variant scenario 1', ([['m1', 'lay', 2000, '7.96', True]], '5'), [1900, 100]),
  ('variant scenario 2',
   ([['m3', 'lay', 2000, '2.30', True],
     ['m1', 'back', 1000, '2.62', False],
     ['m1', 'lay', 777, '6.91', False],
     ['m2', 'back', 100, '2.31', True],
     ['m1', 'lay', 250, '5.96', True]],
    '2'),
   [-3255, 43])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: loss market commission',
   ([['m1', 'lay', 777, '6.98', False],
     ['m3', 'back', 250, '4.94', False],
     ['m1', 'back', 777, '5.13', True],
     ['m3', 'back', 2000, '7.64', True]],
    '6.5'),
   [10745, 847]),
  ('variant scenario 1',
   ([['m2', 'back', 250, '4.54', True],
     ['m3', 'back', 250, '4.14', True],
     ['m3', 'lay', 250, '3.05', False],
     ['m2', 'lay', 1000, '2.30', True]],
    '6.5'),
   [2016, 141]),
  ('variant scenario 2',
   ([['m2', 'back', 777, '3.62', True],
     ['m2', 'back', 1000, '2.28', False],
     ['m3', 'back', 250, '7.79', False]],
    '5'),
   [733, 52])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: loss market commission',
   ([['m2', 'lay', 777, '1.69', False],
     ['m1', 'lay', 100, '7.97', True],
     ['m1', 'back', 250, '4.99', False],
     ['m3', 'lay', 250, '2.98', True],
     ['m1', 'lay', 777, '1.65', False]],
    '2'),
   [-948, 5]),
  ('variant scenario 1',
   ([['m3', 'lay', 2000, '3.64', False], ['m2', 'back', 1000, '6.39', True]], '6.5'),
   [-240, 350]),
  ('variant scenario 2',
   ([['m2', 'lay', 1000, '7.63', True],
     ['m2', 'back', 2000, '1.39', True],
     ['m3', 'back', 1000, '6.88', True]],
    '5'),
   [7277, 383])],
 [('control single back winner', ([['m1', 'back', 1000, '3.00', True]], '5'), [1900, 100]),
  ('boundary hedged market nets out',
   ([['m1', 'back', 1000, '3.00', True], ['m1', 'lay', 1000, '2.50', False]], '5'),
   [475, 25]),
  ('control lay winner', ([['m2', 'lay', 1000, '4.00', True]], '5'), [950, 50]),
  ('boundary losing market no commission',
   ([['m1', 'back', 1000, '3.00', False], ['m1', 'lay', 500, '2.00', True]], '5'),
   [-500, 0]),
  ('regression: loss market commission',
   ([['m2', 'lay', 777, '1.85', False],
     ['m1', 'back', 1000, '2.64', False],
     ['m1', 'lay', 2000, '3.74', False],
     ['m2', 'back', 1000, '7.08', True],
     ['m3', 'back', 1000, '5.02', False]],
    '2'),
   [-2169, 108]),
  ('variant scenario 1', ([['m2', 'lay', 777, '7.81', False]], '6.5'), [-5292, 0]),
  ('variant scenario 2',
   ([['m1', 'back', 777, '2.56', False], ['m3', 'back', 1000, '2.29', True]], '2'),
   [487, 26])]]
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 losing market produces a negative commission refund or a charge on the loss.

Betting exchange settlement. bets rows are [market, side, stake_cents, price, won] where won says whether the bet won. Back: win profit floor(stake * (price - 1)), loss -stake. Lay: win +stake, loss -ceil(stake * (price - 1)) (the liability). Commission is charged per market on the market net profit only when that net is positive, at rate_pct percent rounded half up to a cent. Return [total net after commission, total commission] in cents.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(back_stake, back_price, lay_price):
    bp = Fraction(back_price)
    lp = Fraction(lay_price)
    if bp <= 1 or lp <= 1:
        return 'invalid'
    def cents(x):
        return math.floor(x + Fraction(1, 2))
    lay = cents(back_stake * (bp - 1) / (lp - 1))
    liability = lay * (lp - 1)
    win = back_stake * (bp - 1) - liability
    lose = lay - back_stake
    return [lay, cents(liability), cents(win), cents(lose)]
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 price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: hedge ratio', (2500, '7.81', '7.55'), [2586, 16938, 87, 86]),
  ('variant scenario 1', (1000, '3.26', '7.05'), [462, 2795, -535, -538]),
  ('variant scenario 2', (2500, '7.95', '5.04'), [3943, 15930, 1445, 1443])],
 [('control price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: hedge ratio', (777, '1.59', '7.16'), [173, 1066, -607, -604]),
  ('variant scenario 1', (1000, '6.72', '3.81'), [1764, 4957, 763, 764]),
  ('variant scenario 2', (333, '1.45', '2.25'), [215, 269, -119, -118])],
 [('control price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: hedge ratio', (2500, '3.88', '7.37'), [1316, 8383, -1183, -1184]),
  ('variant scenario 1', (1000, '7.55', '7.11'), [1062, 6489, 61, 62]),
  ('variant scenario 2', (777, '2.80', '3.78'), [576, 1601, -203, -201])],
 [('control price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: hedge ratio', (333, '3.90', '7.35'), [177, 1124, -158, -156]),
  ('variant scenario 1', (777, '6.63', '2.19'), [2352, 2799, 1576, 1575]),
  ('variant scenario 2', (333, '3.52', '4.20'), [279, 893, -54, -54])],
 [('control price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: hedge ratio', (2500, '7.26', '4.46'), [4070, 14082, 1568, 1570]),
  ('variant scenario 1', (333, '5.42', '2.88'), [627, 1179, 293, 294]),
  ('variant scenario 2', (1000, '5.50', '7.68'), [716, 4783, -283, -284])]]
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(back_stake, back_price, lay_price):
    bp = Fraction(back_price)
    lp = Fraction(lay_price)
    if bp <= 1 or lp <= 1:
        return 'invalid'
    def cents(x):
        return math.floor(x + Fraction(1, 2))
    lay = cents(back_stake * lp / bp)
    liability = lay * (lp - 1)
    win = back_stake * (bp - 1) - liability
    lose = lay - back_stake
    return [lay, cents(liability), cents(win), cents(lose)]
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 price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: hedge ratio', (2500, '7.81', '7.55'), [2586, 16938, 87, 86]),
  ('variant scenario 1', (1000, '3.26', '7.05'), [462, 2795, -535, -538]),
  ('variant scenario 2', (2500, '7.95', '5.04'), [3943, 15930, 1445, 1443])],
 [('control price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: hedge ratio', (777, '1.59', '7.16'), [173, 1066, -607, -604]),
  ('variant scenario 1', (1000, '6.72', '3.81'), [1764, 4957, 763, 764]),
  ('variant scenario 2', (333, '1.45', '2.25'), [215, 269, -119, -118])],
 [('control price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: hedge ratio', (2500, '3.88', '7.37'), [1316, 8383, -1183, -1184]),
  ('variant scenario 1', (1000, '7.55', '7.11'), [1062, 6489, 61, 62]),
  ('variant scenario 2', (777, '2.80', '3.78'), [576, 1601, -203, -201])],
 [('control price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: hedge ratio', (333, '3.90', '7.35'), [177, 1124, -158, -156]),
  ('variant scenario 1', (777, '6.63', '2.19'), [2352, 2799, 1576, 1575]),
  ('variant scenario 2', (333, '3.52', '4.20'), [279, 893, -54, -54])],
 [('control price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: hedge ratio', (2500, '7.26', '4.46'), [4070, 14082, 1568, 1570]),
  ('variant scenario 1', (333, '5.42', '2.88'), [627, 1179, 293, 294]),
  ('variant scenario 2', (1000, '5.50', '7.68'), [716, 4783, -283, -284])]]
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 hedged position still has unequal outcomes.

Green-up a matched back bet by laying at a later price (both > 1, else "invalid"). The equal-profit lay stake is back_stake * back_price / lay_price rounded half up to a cent. Using that rounded lay stake: liability = lay_stake * (lay_price - 1), profit if the selection wins = back_stake * (back_price - 1) - liability, profit if it loses = lay_stake - back_stake. Money values are exact then rounded half up to cents. Return [lay_stake, liability, profit_win, profit_lose].

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(back_stake, back_price, lay_price):
    bp = Fraction(back_price)
    lp = Fraction(lay_price)
    if bp <= 1 or lp <= 1:
        return 'invalid'
    def cents(x):
        return math.floor(x + Fraction(1, 2))
    lay = cents(back_stake * bp / lp)
    liability = lay * lp
    win = back_stake * (bp - 1) - liability
    lose = lay - back_stake
    return [lay, cents(liability), cents(win), cents(lose)]
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 price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: liability basis', (1000, '2.13', '3.37'), [632, 1498, -368, -368]),
  ('regression: liability basis', (777, '2.19', '3.53'), [482, 1219, -295, -295]),
  ('variant scenario 1', (2500, '4.19', '5.37'), [1951, 8526, -551, -549]),
  ('variant scenario 2', (777, '2.40', '4.13'), [452, 1415, -327, -325])],
 [('control price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: liability basis', (333, '3.71', '6.08'), [203, 1031, -129, -130]),
  ('variant scenario 1', (333, '3.42', '3.87'), [294, 844, -38, -39]),
  ('variant scenario 2', (777, '6.37', '6.02'), [822, 4126, 46, 45])],
 [('control price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: liability basis', (2500, '4.93', '3.75'), [3287, 9039, 786, 787]),
  ('variant scenario 1', (333, '7.71', '5.28'), [486, 2080, 154, 153]),
  ('variant scenario 2', (777, '3.75', '6.14'), [475, 2442, -305, -302])],
 [('control price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: liability basis', (1000, '4.61', '3.77'), [1223, 3388, 222, 223]),
  ('variant scenario 1', (1000, '6.97', '1.50'), [4647, 2324, 3647, 3647]),
  ('variant scenario 2', (333, '6.28', '6.70'), [312, 1778, -20, -21])],
 [('control price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: liability basis', (2500, '6.61', '2.17'), [7615, 8910, 5115, 5115]),
  ('regression: liability basis', (777, '2.82', '6.91'), [317, 1873, -459, -460]),
  ('variant scenario 1', (777, '7.11', '1.39'), [3974, 1550, 3198, 3197]),
  ('variant scenario 2', (2500, '2.16', '1.35'), [4000, 1400, 1500, 1500])]]
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(back_stake, back_price, lay_price):
    bp = Fraction(back_price)
    lp = Fraction(lay_price)
    if bp <= 1 or lp <= 1:
        return 'invalid'
    def cents(x):
        return math.floor(x + Fraction(1, 2))
    lay = cents(back_stake * bp / lp)
    liability = back_stake * bp / lp * (lp - 1)
    win = back_stake * (bp - 1) - liability
    lose = lay - back_stake
    return [lay, cents(liability), cents(win), cents(lose)]
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 price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: liability basis', (1000, '2.13', '3.37'), [632, 1498, -368, -368]),
  ('regression: liability basis', (777, '2.19', '3.53'), [482, 1219, -295, -295]),
  ('variant scenario 1', (2500, '4.19', '5.37'), [1951, 8526, -551, -549]),
  ('variant scenario 2', (777, '2.40', '4.13'), [452, 1415, -327, -325])],
 [('control price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: liability basis', (333, '3.71', '6.08'), [203, 1031, -129, -130]),
  ('variant scenario 1', (333, '3.42', '3.87'), [294, 844, -38, -39]),
  ('variant scenario 2', (777, '6.37', '6.02'), [822, 4126, 46, 45])],
 [('control price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: liability basis', (2500, '4.93', '3.75'), [3287, 9039, 786, 787]),
  ('variant scenario 1', (333, '7.71', '5.28'), [486, 2080, 154, 153]),
  ('variant scenario 2', (777, '3.75', '6.14'), [475, 2442, -305, -302])],
 [('control price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: liability basis', (1000, '4.61', '3.77'), [1223, 3388, 222, 223]),
  ('variant scenario 1', (1000, '6.97', '1.50'), [4647, 2324, 3647, 3647]),
  ('variant scenario 2', (333, '6.28', '6.70'), [312, 1778, -20, -21])],
 [('control price shortened', (1000, '3.00', '2.00'), [1500, 1500, 500, 500]),
  ('control price drifted', (1000, '2.00', '4.00'), [500, 1500, -500, -500]),
  ('boundary no movement', (1000, '2.50', '2.50'), [1000, 1500, 0, 0]),
  ('boundary invalid price', (1000, '1.00', '2.00'), 'invalid'),
  ('regression: liability basis', (2500, '6.61', '2.17'), [7615, 8910, 5115, 5115]),
  ('regression: liability basis', (777, '2.82', '6.91'), [317, 1873, -459, -460]),
  ('variant scenario 1', (777, '7.11', '1.39'), [3974, 1550, 3198, 3197]),
  ('variant scenario 2', (2500, '2.16', '1.35'), [4000, 1400, 1500, 1500])]]
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 liability shown differs from what the exchange will reserve for the placed lay.

Green-up a matched back bet by laying at a later price (both > 1, else "invalid"). The equal-profit lay stake is back_stake * back_price / lay_price rounded half up to a cent. Using that rounded lay stake: liability = lay_stake * (lay_price - 1), profit if the selection wins = back_stake * (back_price - 1) - liability, profit if it loses = lay_stake - back_stake. Money values are exact then rounded half up to cents. Return [lay_stake, liability, profit_win, profit_lose].

split: open-access


prompt:
Stakes are sized far too large on every price.

Kelly staking. With b = price - 1, p = prob and q = 1 - p, the full Kelly fraction is (b * p - q) / b, floored at 0 when the edge is not positive. The stake is bankroll * min(full Kelly * fraction, max_pct / 100), rounded down to a cent. Return [full Kelly fraction rounded half up to four decimals as a string, stake cents].

split: open-access


prompt:
A bet without an edge reports a negative fraction or a negative stake.

Kelly staking. With b = price - 1, p = prob and q = 1 - p, the full Kelly fraction is (b * p - q) / b, floored at 0 when the edge is not positive. The stake is bankroll * min(full Kelly * fraction, max_pct / 100), rounded down to a cent. Return [full Kelly fraction rounded half up to four decimals as a string, stake cents].

split: open-access


prompt:
Half-Kelly stakes are halved again after capping, or the multiplier is ignored.

Kelly staking. With b = price - 1, p = prob and q = 1 - p, the full Kelly fraction is (b * p - q) / b, floored at 0 when the edge is not positive. The stake is bankroll * min(full Kelly * fraction, max_pct / 100), rounded down to a cent. Return [full Kelly fraction rounded half up to four decimals as a string, stake cents].

split: open-access


prompt:
The Kelly stake ignores the bettor probability for the losing side.

Kelly staking. With b = price - 1, p = prob and q = 1 - p, the full Kelly fraction is (b * p - q) / b, floored at 0 when the edge is not positive. The stake is bankroll * min(full Kelly * fraction, max_pct / 100), rounded down to a cent. Return [full Kelly fraction rounded half up to four decimals as a string, stake cents].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(books, total_cents):
    best = {}
    for book, outcome, price in books:
        d = Fraction(price)
        cur = best.get(outcome)
        if cur is None or d < cur[0] or (d == cur[0] and book < cur[1]):
            best[outcome] = (d, book)
    S = sum(1 / d for d, _ in best.values())
    if S >= 1:
        return ['no arb']
    rows = []
    ret = None
    for outcome in sorted(best):
        d, book = best[outcome]
        stake = math.floor(total_cents * (1 / d) / S)
        rows.append([outcome, book, stake])
        r = math.floor(stake * d)
        ret = r if ret is None else min(ret, r)
    return ['arb', rows, ret - sum(r[2] for r in rows)]
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-way arb',
   ([['alpha', 'home', '2.10'], ['bravo', 'away', '2.10'], ['bravo', 'home', '1.90']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 500]),
  ('boundary exactly fair book',
   ([['alpha', 'home', '2.00'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('boundary tie goes to first name',
   ([['kilo', 'home', '2.20'], ['alpha', 'home', '2.20'], ['bravo', 'away', '2.20']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 1000]),
  ('control no arb', ([['alpha', 'home', '1.90'], ['alpha', 'away', '1.90']], 10000), ['no arb']),
  ('regression: best price selection',
   ([['kilo', 'home', '1.77'],
     ['delta', 'home', '1.79'],
     ['kilo', 'away', '2.33'],
     ['bravo', 'away', '2.21'],
     ['delta', 'away', '2.07']],
    25000),
   ['arb', [['away', 'kilo', 10861], ['home', 'delta', 14138]], 307]),
  ('variant scenario 1',
   ([['bravo', 'home', '1.69'],
     ['alpha', 'away', '2.32'],
     ['bravo', 'away', '2.14'],
     ['delta', 'away', '2.26']],
    10000),
   ['no arb']),
  ('variant scenario 2',
   ([['kilo', 'home', '2.33'], ['delta', 'away', '1.88'], ['bravo', 'away', '1.91']], 9999),
   ['arb', [['away', 'bravo', 5494], ['home', 'kilo', 4504]], 495])],
 [('control two-way arb',
   ([['alpha', 'home', '2.10'], ['bravo', 'away', '2.10'], ['bravo', 'home', '1.90']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 500]),
  ('boundary exactly fair book',
   ([['alpha', 'home', '2.00'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('boundary tie goes to first name',
   ([['kilo', 'home', '2.20'], ['alpha', 'home', '2.20'], ['bravo', 'away', '2.20']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 1000]),
  ('control no arb', ([['alpha', 'home', '1.90'], ['alpha', 'away', '1.90']], 10000), ['no arb']),
  ('regression: best price selection',
   ([['delta', 'home', '3.08'],
     ['alpha', 'home', '2.92'],
     ['kilo', 'draw', '2.68'],
     ['alpha', 'away', '3.29'],
     ['delta', 'away', '3.29'],
     ['kilo', 'away', '3.68']],
    10000),
   ['arb', [['away', 'kilo', 2802], ['draw', 'kilo', 3848], ['home', 'delta', 3348]], 313]),
  ('variant scenario 1',
   ([['delta', 'home', '3.01'],
     ['kilo', 'home', '2.64'],
     ['kilo', 'draw', '3.17'],
     ['alpha', 'draw', '3.30'],
     ['delta', 'away', '3.27']],
    25000),
   ['arb', [['away', 'delta', 8124], ['draw', 'alpha', 8050], ['home', 'delta', 8825]], 1564]),
  ('variant scenario 2',
   ([['kilo', 'home', '2.66'],
     ['alpha', 'home', '2.70'],
     ['bravo', 'home', '2.71'],
     ['kilo', 'away', '1.72'],
     ['delta', 'away', '1.54'],
     ['alpha', 'home', '2.66']],
    25000),
   ['arb', [['away', 'kilo', 15293], ['home', 'bravo', 9706]], 1304])],
 [('control two-way arb',
   ([['alpha', 'home', '2.10'], ['bravo', 'away', '2.10'], ['bravo', 'home', '1.90']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 500]),
  ('boundary exactly fair book',
   ([['alpha', 'home', '2.00'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('boundary tie goes to first name',
   ([['kilo', 'home', '2.20'], ['alpha', 'home', '2.20'], ['bravo', 'away', '2.20']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 1000]),
  ('control no arb', ([['alpha', 'home', '1.90'], ['alpha', 'away', '1.90']], 10000), ['no arb']),
  ('regression: best price selection',
   ([['kilo', 'home', '2.23'],
     ['alpha', 'away', '1.83'],
     ['kilo', 'away', '2.07'],
     ['bravo', 'away', '1.86']],
    10000),
   ['arb', [['away', 'kilo', 5186], ['home', 'kilo', 4813]], 733]),
  ('variant scenario 1',
   ([['delta', 'home', '1.53'],
     ['delta', 'away', '2.80'],
     ['bravo', 'away', '2.80'],
     ['kilo', 'away', '2.70']],
    9999),
   ['no arb']),
  ('variant scenario 2',
   ([['kilo', 'home', '2.53'],
     ['delta', 'home', '3.01'],
     ['alpha', 'draw', '3.61'],
     ['kilo', 'draw', '3.70'],
     ['delta', 'draw', '3.67'],
     ['kilo', 'away', '2.87'],
     ['bravo', 'away', '2.92'],
     ['delta', 'away', '2.58']],
    10000),
   ['arb', [['away', 'bravo', 3624], ['draw', 'kilo', 2860], ['home', 'delta', 3515]], 581])],
 [('control two-way arb',
   ([['alpha', 'home', '2.10'], ['bravo', 'away', '2.10'], ['bravo', 'home', '1.90']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 500]),
  ('boundary exactly fair book',
   ([['alpha', 'home', '2.00'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('boundary tie goes to first name',
   ([['kilo', 'home', '2.20'], ['alpha', 'home', '2.20'], ['bravo', 'away', '2.20']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 1000]),
  ('control no arb', ([['alpha', 'home', '1.90'], ['alpha', 'away', '1.90']], 10000), ['no arb']),
  ('regression: best price selection',
   ([['delta', 'home', '3.40'],
     ['bravo', 'home', '3.33'],
     ['kilo', 'draw', '2.36'],
     ['delta', 'draw', '2.28'],
     ['kilo', 'away', '3.93'],
     ['bravo', 'away', '3.75']],
    10000),
   ['arb', [['away', 'kilo', 2617], ['draw', 'kilo', 4358], ['home', 'delta', 3024]], 282]),
  ('variant scenario 1',
   ([['kilo', 'home', '3.59'],
     ['bravo', 'home', '3.20'],
     ['alpha', 'home', '3.30'],
     ['alpha', 'draw', '2.44'],
     ['kilo', 'draw', '2.29'],
     ['bravo', 'draw', '2.36'],
     ['delta', 'away', '3.54'],
     ['bravo', 'away', '3.81']],
    9999),
   ['arb', [['away', 'bravo', 2760], ['draw', 'alpha', 4309], ['home', 'kilo', 2929]], 515]),
  ('variant scenario 2',
   ([['alpha', 'home', '3.52'], ['delta', 'away', '1.35'], ['bravo', 'away', '1.48']], 9999),
   ['arb', [['away', 'bravo', 7039], ['home', 'alpha', 2959]], 417])],
 [('control two-way arb',
   ([['alpha', 'home', '2.10'], ['bravo', 'away', '2.10'], ['bravo', 'home', '1.90']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 500]),
  ('boundary exactly fair book',
   ([['alpha', 'home', '2.00'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('boundary tie goes to first name',
   ([['kilo', 'home', '2.20'], ['alpha', 'home', '2.20'], ['bravo', 'away', '2.20']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 1000]),
  ('control no arb', ([['alpha', 'home', '1.90'], ['alpha', 'away', '1.90']], 10000), ['no arb']),
  ('regression: best price selection',
   ([['bravo', 'home', '2.92'],
     ['alpha', 'home', '3.07'],
     ['kilo', 'home', '3.06'],
     ['alpha', 'draw', '3.65'],
     ['delta', 'draw', '3.52'],
     ['delta', 'away', '2.53'],
     ['alpha', 'away', '2.36'],
     ['bravo', 'away', '2.67']],
    9999),
   ['arb', [['away', 'bravo', 3843], ['draw', 'alpha', 2811], ['home', 'alpha', 3343]], 263]),
  ('variant scenario 1',
   ([['kilo', 'home', '2.38'],
     ['alpha', 'home', '2.05'],
     ['bravo', 'home', '2.37'],
     ['alpha', 'away', '1.74'],
     ['bravo', 'away', '1.82']],
    10000),
   ['arb', [['away', 'bravo', 5666], ['home', 'kilo', 4333]], 313]),
  ('variant scenario 2',
   ([['delta', 'home', '4.55'],
     ['bravo', 'home', '4.54'],
     ['kilo', 'home', '4.47'],
     ['kilo', 'draw', '2.17'],
     ['delta', 'draw', '2.23'],
     ['bravo', 'draw', '2.19'],
     ['bravo', 'away', '3.24'],
     ['delta', 'away', '3.26'],
     ['kilo', 'away', '3.37']],
    10000),
   ['arb', [['away', 'kilo', 3075], ['draw', 'delta', 4647], ['home', 'delta', 2277]], 361])]]
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(books, total_cents):
    best = {}
    for book, outcome, price in books:
        d = Fraction(price)
        cur = best.get(outcome)
        if True:
            best[outcome] = (d, book)
    S = sum(1 / d for d, _ in best.values())
    if S >= 1:
        return ['no arb']
    rows = []
    ret = None
    for outcome in sorted(best):
        d, book = best[outcome]
        stake = math.floor(total_cents * (1 / d) / S)
        rows.append([outcome, book, stake])
        r = math.floor(stake * d)
        ret = r if ret is None else min(ret, r)
    return ['arb', rows, ret - sum(r[2] for r in rows)]
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-way arb',
   ([['alpha', 'home', '2.10'], ['bravo', 'away', '2.10'], ['bravo', 'home', '1.90']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 500]),
  ('boundary exactly fair book',
   ([['alpha', 'home', '2.00'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('boundary tie goes to first name',
   ([['kilo', 'home', '2.20'], ['alpha', 'home', '2.20'], ['bravo', 'away', '2.20']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 1000]),
  ('control no arb', ([['alpha', 'home', '1.90'], ['alpha', 'away', '1.90']], 10000), ['no arb']),
  ('regression: best price selection',
   ([['kilo', 'home', '1.77'],
     ['delta', 'home', '1.79'],
     ['kilo', 'away', '2.33'],
     ['bravo', 'away', '2.21'],
     ['delta', 'away', '2.07']],
    25000),
   ['arb', [['away', 'kilo', 10861], ['home', 'delta', 14138]], 307]),
  ('variant scenario 1',
   ([['bravo', 'home', '1.69'],
     ['alpha', 'away', '2.32'],
     ['bravo', 'away', '2.14'],
     ['delta', 'away', '2.26']],
    10000),
   ['no arb']),
  ('variant scenario 2',
   ([['kilo', 'home', '2.33'], ['delta', 'away', '1.88'], ['bravo', 'away', '1.91']], 9999),
   ['arb', [['away', 'bravo', 5494], ['home', 'kilo', 4504]], 495])],
 [('control two-way arb',
   ([['alpha', 'home', '2.10'], ['bravo', 'away', '2.10'], ['bravo', 'home', '1.90']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 500]),
  ('boundary exactly fair book',
   ([['alpha', 'home', '2.00'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('boundary tie goes to first name',
   ([['kilo', 'home', '2.20'], ['alpha', 'home', '2.20'], ['bravo', 'away', '2.20']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 1000]),
  ('control no arb', ([['alpha', 'home', '1.90'], ['alpha', 'away', '1.90']], 10000), ['no arb']),
  ('regression: best price selection',
   ([['delta', 'home', '3.08'],
     ['alpha', 'home', '2.92'],
     ['kilo', 'draw', '2.68'],
     ['alpha', 'away', '3.29'],
     ['delta', 'away', '3.29'],
     ['kilo', 'away', '3.68']],
    10000),
   ['arb', [['away', 'kilo', 2802], ['draw', 'kilo', 3848], ['home', 'delta', 3348]], 313]),
  ('variant scenario 1',
   ([['delta', 'home', '3.01'],
     ['kilo', 'home', '2.64'],
     ['kilo', 'draw', '3.17'],
     ['alpha', 'draw', '3.30'],
     ['delta', 'away', '3.27']],
    25000),
   ['arb', [['away', 'delta', 8124], ['draw', 'alpha', 8050], ['home', 'delta', 8825]], 1564]),
  ('variant scenario 2',
   ([['kilo', 'home', '2.66'],
     ['alpha', 'home', '2.70'],
     ['bravo', 'home', '2.71'],
     ['kilo', 'away', '1.72'],
     ['delta', 'away', '1.54'],
     ['alpha', 'home', '2.66']],
    25000),
   ['arb', [['away', 'kilo', 15293], ['home', 'bravo', 9706]], 1304])],
 [('control two-way arb',
   ([['alpha', 'home', '2.10'], ['bravo', 'away', '2.10'], ['bravo', 'home', '1.90']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 500]),
  ('boundary exactly fair book',
   ([['alpha', 'home', '2.00'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('boundary tie goes to first name',
   ([['kilo', 'home', '2.20'], ['alpha', 'home', '2.20'], ['bravo', 'away', '2.20']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 1000]),
  ('control no arb', ([['alpha', 'home', '1.90'], ['alpha', 'away', '1.90']], 10000), ['no arb']),
  ('regression: best price selection',
   ([['kilo', 'home', '2.23'],
     ['alpha', 'away', '1.83'],
     ['kilo', 'away', '2.07'],
     ['bravo', 'away', '1.86']],
    10000),
   ['arb', [['away', 'kilo', 5186], ['home', 'kilo', 4813]], 733]),
  ('variant scenario 1',
   ([['delta', 'home', '1.53'],
     ['delta', 'away', '2.80'],
     ['bravo', 'away', '2.80'],
     ['kilo', 'away', '2.70']],
    9999),
   ['no arb']),
  ('variant scenario 2',
   ([['kilo', 'home', '2.53'],
     ['delta', 'home', '3.01'],
     ['alpha', 'draw', '3.61'],
     ['kilo', 'draw', '3.70'],
     ['delta', 'draw', '3.67'],
     ['kilo', 'away', '2.87'],
     ['bravo', 'away', '2.92'],
     ['delta', 'away', '2.58']],
    10000),
   ['arb', [['away', 'bravo', 3624], ['draw', 'kilo', 2860], ['home', 'delta', 3515]], 581])],
 [('control two-way arb',
   ([['alpha', 'home', '2.10'], ['bravo', 'away', '2.10'], ['bravo', 'home', '1.90']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 500]),
  ('boundary exactly fair book',
   ([['alpha', 'home', '2.00'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('boundary tie goes to first name',
   ([['kilo', 'home', '2.20'], ['alpha', 'home', '2.20'], ['bravo', 'away', '2.20']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 1000]),
  ('control no arb', ([['alpha', 'home', '1.90'], ['alpha', 'away', '1.90']], 10000), ['no arb']),
  ('regression: best price selection',
   ([['delta', 'home', '3.40'],
     ['bravo', 'home', '3.33'],
     ['kilo', 'draw', '2.36'],
     ['delta', 'draw', '2.28'],
     ['kilo', 'away', '3.93'],
     ['bravo', 'away', '3.75']],
    10000),
   ['arb', [['away', 'kilo', 2617], ['draw', 'kilo', 4358], ['home', 'delta', 3024]], 282]),
  ('variant scenario 1',
   ([['kilo', 'home', '3.59'],
     ['bravo', 'home', '3.20'],
     ['alpha', 'home', '3.30'],
     ['alpha', 'draw', '2.44'],
     ['kilo', 'draw', '2.29'],
     ['bravo', 'draw', '2.36'],
     ['delta', 'away', '3.54'],
     ['bravo', 'away', '3.81']],
    9999),
   ['arb', [['away', 'bravo', 2760], ['draw', 'alpha', 4309], ['home', 'kilo', 2929]], 515]),
  ('variant scenario 2',
   ([['alpha', 'home', '3.52'], ['delta', 'away', '1.35'], ['bravo', 'away', '1.48']], 9999),
   ['arb', [['away', 'bravo', 7039], ['home', 'alpha', 2959]], 417])],
 [('control two-way arb',
   ([['alpha', 'home', '2.10'], ['bravo', 'away', '2.10'], ['bravo', 'home', '1.90']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 500]),
  ('boundary exactly fair book',
   ([['alpha', 'home', '2.00'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('boundary tie goes to first name',
   ([['kilo', 'home', '2.20'], ['alpha', 'home', '2.20'], ['bravo', 'away', '2.20']], 10000),
   ['arb', [['away', 'bravo', 5000], ['home', 'alpha', 5000]], 1000]),
  ('control no arb', ([['alpha', 'home', '1.90'], ['alpha', 'away', '1.90']], 10000), ['no arb']),
  ('regression: best price selection',
   ([['bravo', 'home', '2.92'],
     ['alpha', 'home', '3.07'],
     ['kilo', 'home', '3.06'],
     ['alpha', 'draw', '3.65'],
     ['delta', 'draw', '3.52'],
     ['delta', 'away', '2.53'],
     ['alpha', 'away', '2.36'],
     ['bravo', 'away', '2.67']],
    9999),
   ['arb', [['away', 'bravo', 3843], ['draw', 'alpha', 2811], ['home', 'alpha', 3343]], 263]),
  ('variant scenario 1',
   ([['kilo', 'home', '2.38'],
     ['alpha', 'home', '2.05'],
     ['bravo', 'home', '2.37'],
     ['alpha', 'away', '1.74'],
     ['bravo', 'away', '1.82']],
    10000),
   ['arb', [['away', 'bravo', 5666], ['home', 'kilo', 4333]], 313]),
  ('variant scenario 2',
   ([['delta', 'home', '4.55'],
     ['bravo', 'home', '4.54'],
     ['kilo', 'home', '4.47'],
     ['kilo', 'draw', '2.17'],
     ['delta', 'draw', '2.23'],
     ['bravo', 'draw', '2.19'],
     ['bravo', 'away', '3.24'],
     ['delta', 'away', '3.26'],
     ['kilo', 'away', '3.37']],
    10000),
   ['arb', [['away', 'kilo', 3075], ['draw', 'delta', 4647], ['home', 'delta', 2277]], 361])]]
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:
Genuine sure bets are missed because the lowest quote is used.

Arbitrage finder. books rows are [bookmaker, outcome, decimal price]. For each outcome take the highest price; ties go to the alphabetically first bookmaker. S = sum of 1/best price. If S >= 1 return ["no arb"]. Otherwise stake_i = floor(total * (1/d_i) / S) cents; guaranteed return = min over outcomes of floor(stake_i * d_i). Return ["arb", [[outcome, bookmaker, stake] sorted by outcome], guaranteed return - sum of stakes].

split: open-access