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]):
            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: bookmaker tiebreak',
   ([['bravo', 'home', '2.12'],
     ['alpha', 'home', '1.85'],
     ['kilo', 'away', '1.94'],
     ['delta', 'away', '1.86'],
     ['bravo', 'away', '1.95'],
     ['alpha', 'home', '2.12']],
    25000),
   ['arb', [['away', 'bravo', 13022], ['home', 'alpha', 11977]], 392]),
  ('regression: bookmaker tiebreak',
   ([['bravo', 'home', '3.51'],
     ['delta', 'home', '3.20'],
     ['delta', 'draw', '3.26'],
     ['bravo', 'draw', '3.43'],
     ['bravo', 'away', '2.58'],
     ['delta', 'away', '2.38'],
     ['kilo', 'home', '3.51']],
    9999),
   ['arb', [['away', 'bravo', 4020], ['draw', 'bravo', 3023], ['home', 'bravo', 2954]], 371]),
  ('variant scenario 1',
   ([['delta', 'home', '2.93'],
     ['bravo', 'home', '2.86'],
     ['bravo', 'draw', '3.36'],
     ['delta', 'draw', '3.11'],
     ['kilo', 'away', '2.81']],
    9999),
   ['arb', [['away', 'kilo', 3577], ['draw', 'bravo', 2991], ['home', 'delta', 3430]], 51]),
  ('variant scenario 2',
   ([['delta', 'home', '2.19'],
     ['bravo', 'home', '2.28'],
     ['alpha', 'home', '2.14'],
     ['bravo', 'away', '1.88'],
     ['delta', 'home', '2.19']],
    10000),
   ['arb', [['away', 'bravo', 5480], ['home', 'bravo', 4519]], 303])],
 [('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: bookmaker tiebreak',
   ([['alpha', 'home', '2.68'],
     ['kilo', 'home', '2.64'],
     ['bravo', 'draw', '3.55'],
     ['delta', 'draw', '3.29'],
     ['alpha', 'draw', '3.29'],
     ['kilo', 'away', '3.06'],
     ['alpha', 'away', '2.62'],
     ['bravo', 'home', '2.68']],
    25000),
   ['arb', [['away', 'kilo', 8322], ['draw', 'bravo', 7174], ['home', 'alpha', 9503]], 466]),
  ('variant scenario 1',
   ([['alpha', 'home', '2.85'],
     ['kilo', 'home', '2.89'],
     ['bravo', 'home', '3.01'],
     ['alpha', 'away', '1.51']],
    10000),
   ['arb', [['away', 'alpha', 6659], ['home', 'bravo', 3340]], 54]),
  ('variant scenario 2',
   ([['kilo', 'home', '1.45'],
     ['alpha', 'home', '1.60'],
     ['delta', 'home', '1.63'],
     ['alpha', 'away', '2.60'],
     ['alpha', 'home', '1.45']],
    9999),
   ['arb', [['away', 'alpha', 3853], ['home', 'delta', 6145]], 18])],
 [('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: bookmaker tiebreak',
   ([['bravo', 'home', '1.93'],
     ['delta', 'home', '1.77'],
     ['delta', 'away', '2.14'],
     ['alpha', 'home', '1.93']],
    25000),
   ['arb', [['away', 'delta', 11855], ['home', 'alpha', 13144]], 368]),
  ('regression: bookmaker tiebreak',
   ([['delta', 'home', '2.69'],
     ['alpha', 'home', '2.64'],
     ['kilo', 'away', '1.70'],
     ['kilo', 'home', '2.69']],
    25000),
   ['arb', [['away', 'kilo', 15318], ['home', 'delta', 9681]], 1041]),
  ('variant scenario 1',
   ([['alpha', 'home', '4.67'],
     ['alpha', 'draw', '2.53'],
     ['bravo', 'draw', '2.58'],
     ['delta', 'draw', '2.26'],
     ['bravo', 'away', '2.81'],
     ['alpha', 'home', '4.67']],
    25000),
   ['arb', [['away', 'bravo', 9290], ['draw', 'bravo', 10118], ['home', 'alpha', 5590]], 1106]),
  ('variant scenario 2',
   ([['delta', 'home', '1.82'],
     ['alpha', 'home', '1.83'],
     ['bravo', 'home', '1.81'],
     ['alpha', 'away', '2.58'],
     ['delta', 'away', '2.49'],
     ['kilo', 'away', '2.27']],
    10000),
   ['arb', [['away', 'alpha', 4149], ['home', 'alpha', 5850]], 705])],
 [('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: bookmaker tiebreak',
   ([['bravo', 'home', '3.83'],
     ['bravo', 'draw', '3.33'],
     ['kilo', 'draw', '3.68'],
     ['delta', 'draw', '3.51'],
     ['alpha', 'away', '2.23'],
     ['kilo', 'away', '2.23'],
     ['alpha', 'home', '3.83']],
    25000),
   ['arb', [['away', 'alpha', 11424], ['draw', 'kilo', 6923], ['home', 'alpha', 6652]], 476]),
  ('variant scenario 1',
   ([['delta', 'home', '1.97'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('variant scenario 2',
   ([['delta', 'home', '1.68'], ['bravo', 'home', '1.62'], ['alpha', 'away', '2.82']], 9999),
   ['arb', [['away', 'alpha', 3732], ['home', 'delta', 6266]], 526])],
 [('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: bookmaker tiebreak',
   ([['alpha', 'home', '2.67'],
     ['bravo', 'home', '2.37'],
     ['alpha', 'draw', '3.41'],
     ['bravo', 'draw', '3.82'],
     ['bravo', 'away', '3.16'],
     ['bravo', 'home', '2.67']],
    9999),
   ['arb', [['away', 'bravo', 3321], ['draw', 'bravo', 2747], ['home', 'alpha', 3930]], 495]),
  ('variant scenario 1',
   ([['alpha', 'home', '1.73'],
     ['kilo', 'home', '1.71'],
     ['delta', 'home', '1.57'],
     ['kilo', 'away', '2.26'],
     ['delta', 'home', '1.73']],
    10000),
   ['no arb']),
  ('variant scenario 2',
   ([['delta', 'home', '2.20'],
     ['bravo', 'away', '2.04'],
     ['delta', 'away', '1.85'],
     ['kilo', 'away', '2.00']],
    25000),
   ['arb', [['away', 'bravo', 12971], ['home', 'delta', 12028]], 1461])]]
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 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: bookmaker tiebreak',
   ([['bravo', 'home', '2.12'],
     ['alpha', 'home', '1.85'],
     ['kilo', 'away', '1.94'],
     ['delta', 'away', '1.86'],
     ['bravo', 'away', '1.95'],
     ['alpha', 'home', '2.12']],
    25000),
   ['arb', [['away', 'bravo', 13022], ['home', 'alpha', 11977]], 392]),
  ('regression: bookmaker tiebreak',
   ([['bravo', 'home', '3.51'],
     ['delta', 'home', '3.20'],
     ['delta', 'draw', '3.26'],
     ['bravo', 'draw', '3.43'],
     ['bravo', 'away', '2.58'],
     ['delta', 'away', '2.38'],
     ['kilo', 'home', '3.51']],
    9999),
   ['arb', [['away', 'bravo', 4020], ['draw', 'bravo', 3023], ['home', 'bravo', 2954]], 371]),
  ('variant scenario 1',
   ([['delta', 'home', '2.93'],
     ['bravo', 'home', '2.86'],
     ['bravo', 'draw', '3.36'],
     ['delta', 'draw', '3.11'],
     ['kilo', 'away', '2.81']],
    9999),
   ['arb', [['away', 'kilo', 3577], ['draw', 'bravo', 2991], ['home', 'delta', 3430]], 51]),
  ('variant scenario 2',
   ([['delta', 'home', '2.19'],
     ['bravo', 'home', '2.28'],
     ['alpha', 'home', '2.14'],
     ['bravo', 'away', '1.88'],
     ['delta', 'home', '2.19']],
    10000),
   ['arb', [['away', 'bravo', 5480], ['home', 'bravo', 4519]], 303])],
 [('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: bookmaker tiebreak',
   ([['alpha', 'home', '2.68'],
     ['kilo', 'home', '2.64'],
     ['bravo', 'draw', '3.55'],
     ['delta', 'draw', '3.29'],
     ['alpha', 'draw', '3.29'],
     ['kilo', 'away', '3.06'],
     ['alpha', 'away', '2.62'],
     ['bravo', 'home', '2.68']],
    25000),
   ['arb', [['away', 'kilo', 8322], ['draw', 'bravo', 7174], ['home', 'alpha', 9503]], 466]),
  ('variant scenario 1',
   ([['alpha', 'home', '2.85'],
     ['kilo', 'home', '2.89'],
     ['bravo', 'home', '3.01'],
     ['alpha', 'away', '1.51']],
    10000),
   ['arb', [['away', 'alpha', 6659], ['home', 'bravo', 3340]], 54]),
  ('variant scenario 2',
   ([['kilo', 'home', '1.45'],
     ['alpha', 'home', '1.60'],
     ['delta', 'home', '1.63'],
     ['alpha', 'away', '2.60'],
     ['alpha', 'home', '1.45']],
    9999),
   ['arb', [['away', 'alpha', 3853], ['home', 'delta', 6145]], 18])],
 [('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: bookmaker tiebreak',
   ([['bravo', 'home', '1.93'],
     ['delta', 'home', '1.77'],
     ['delta', 'away', '2.14'],
     ['alpha', 'home', '1.93']],
    25000),
   ['arb', [['away', 'delta', 11855], ['home', 'alpha', 13144]], 368]),
  ('regression: bookmaker tiebreak',
   ([['delta', 'home', '2.69'],
     ['alpha', 'home', '2.64'],
     ['kilo', 'away', '1.70'],
     ['kilo', 'home', '2.69']],
    25000),
   ['arb', [['away', 'kilo', 15318], ['home', 'delta', 9681]], 1041]),
  ('variant scenario 1',
   ([['alpha', 'home', '4.67'],
     ['alpha', 'draw', '2.53'],
     ['bravo', 'draw', '2.58'],
     ['delta', 'draw', '2.26'],
     ['bravo', 'away', '2.81'],
     ['alpha', 'home', '4.67']],
    25000),
   ['arb', [['away', 'bravo', 9290], ['draw', 'bravo', 10118], ['home', 'alpha', 5590]], 1106]),
  ('variant scenario 2',
   ([['delta', 'home', '1.82'],
     ['alpha', 'home', '1.83'],
     ['bravo', 'home', '1.81'],
     ['alpha', 'away', '2.58'],
     ['delta', 'away', '2.49'],
     ['kilo', 'away', '2.27']],
    10000),
   ['arb', [['away', 'alpha', 4149], ['home', 'alpha', 5850]], 705])],
 [('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: bookmaker tiebreak',
   ([['bravo', 'home', '3.83'],
     ['bravo', 'draw', '3.33'],
     ['kilo', 'draw', '3.68'],
     ['delta', 'draw', '3.51'],
     ['alpha', 'away', '2.23'],
     ['kilo', 'away', '2.23'],
     ['alpha', 'home', '3.83']],
    25000),
   ['arb', [['away', 'alpha', 11424], ['draw', 'kilo', 6923], ['home', 'alpha', 6652]], 476]),
  ('variant scenario 1',
   ([['delta', 'home', '1.97'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('variant scenario 2',
   ([['delta', 'home', '1.68'], ['bravo', 'home', '1.62'], ['alpha', 'away', '2.82']], 9999),
   ['arb', [['away', 'alpha', 3732], ['home', 'delta', 6266]], 526])],
 [('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: bookmaker tiebreak',
   ([['alpha', 'home', '2.67'],
     ['bravo', 'home', '2.37'],
     ['alpha', 'draw', '3.41'],
     ['bravo', 'draw', '3.82'],
     ['bravo', 'away', '3.16'],
     ['bravo', 'home', '2.67']],
    9999),
   ['arb', [['away', 'bravo', 3321], ['draw', 'bravo', 2747], ['home', 'alpha', 3930]], 495]),
  ('variant scenario 1',
   ([['alpha', 'home', '1.73'],
     ['kilo', 'home', '1.71'],
     ['delta', 'home', '1.57'],
     ['kilo', 'away', '2.26'],
     ['delta', 'home', '1.73']],
    10000),
   ['no arb']),
  ('variant scenario 2',
   ([['delta', 'home', '2.20'],
     ['bravo', 'away', '2.04'],
     ['delta', 'away', '1.85'],
     ['kilo', 'away', '2.00']],
    25000),
   ['arb', [['away', 'bravo', 12971], ['home', 'delta', 12028]], 1461])]]
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 stake is routed to a different bookmaker than the stated tie rule picks.

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


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: arb threshold',
   ([['bravo', 'home', '3.77'],
     ['kilo', 'home', '4.11'],
     ['delta', 'home', '3.81'],
     ['kilo', 'draw', '2.56'],
     ['delta', 'draw', '2.44'],
     ['alpha', 'draw', '2.44'],
     ['bravo', 'away', '2.54'],
     ['delta', 'away', '2.78']],
    9999),
   ['arb', [['away', 'delta', 3619], ['draw', 'kilo', 3930], ['home', 'kilo', 2448]], 63]),
  ('regression: arb threshold',
   ([['alpha', 'home', '2.17'],
     ['bravo', 'home', '2.25'],
     ['delta', 'away', '1.57'],
     ['alpha', 'away', '1.80']],
    9999),
   ['no arb']),
  ('variant scenario 1',
   ([['bravo', 'home', '4.00'], ['bravo', 'draw', '2.56'], ['alpha', 'away', '2.61']], 10000),
   ['no arb']),
  ('variant scenario 2',
   ([['kilo', 'home', '2.04'],
     ['alpha', 'home', '2.13'],
     ['bravo', 'home', '2.13'],
     ['alpha', 'away', '2.07'],
     ['bravo', 'away', '1.99'],
     ['delta', 'away', '1.86']],
    10000),
   ['arb', [['away', 'alpha', 5071], ['home', 'alpha', 4928]], 497])],
 [('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: arb threshold',
   ([['bravo', 'home', '2.24'], ['delta', 'home', '2.40'], ['kilo', 'away', '1.72']], 25000),
   ['arb', [['away', 'kilo', 14563], ['home', 'delta', 10436]], 47]),
  ('regression: arb threshold',
   ([['alpha', 'home', '2.00'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('variant scenario 1',
   ([['alpha', 'home', '2.57'], ['delta', 'away', '1.69'], ['bravo', 'home', '2.57']], 10000),
   ['arb', [['away', 'delta', 6032], ['home', 'alpha', 3967]], 195]),
  ('variant scenario 2',
   ([['bravo', 'home', '5.12'],
     ['kilo', 'home', '5.29'],
     ['delta', 'home', '5.73'],
     ['bravo', 'draw', '2.52'],
     ['kilo', 'draw', '2.36'],
     ['kilo', 'away', '2.51']],
    10000),
   ['arb', [['away', 'kilo', 4108], ['draw', 'bravo', 4092], ['home', 'delta', 1799]], 309])],
 [('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: arb threshold',
   ([['delta', 'home', '1.68'],
     ['bravo', 'home', '1.81'],
     ['alpha', 'home', '1.86'],
     ['alpha', 'away', '2.11'],
     ['bravo', 'away', '2.18']],
    9999),
   ['arb', [['away', 'bravo', 4603], ['home', 'alpha', 5395]], 36]),
  ('regression: arb threshold',
   ([['alpha', 'home', '2.00'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('variant scenario 1',
   ([['bravo', 'home', '2.55'],
     ['delta', 'away', '1.60'],
     ['kilo', 'away', '1.43'],
     ['bravo', 'away', '1.43'],
     ['bravo', 'home', '2.55']],
    10000),
   ['no arb']),
  ('variant scenario 2',
   ([['bravo', 'home', '2.81'],
     ['delta', 'home', '3.32'],
     ['kilo', 'home', '2.88'],
     ['alpha', 'draw', '2.81'],
     ['bravo', 'draw', '3.10'],
     ['delta', 'draw', '2.76'],
     ['alpha', 'away', '3.00'],
     ['kilo', 'away', '2.79']],
    10000),
   ['arb', [['away', 'alpha', 3482], ['draw', 'bravo', 3370], ['home', 'delta', 3146]], 446])],
 [('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: arb threshold',
   ([['alpha', 'home', '4.94'],
     ['kilo', 'home', '5.07'],
     ['kilo', 'draw', '1.98'],
     ['bravo', 'away', '3.23'],
     ['delta', 'away', '3.40']],
    25000),
   ['arb', [['away', 'delta', 7379], ['draw', 'kilo', 12671], ['home', 'kilo', 4948]], 88]),
  ('regression: arb threshold',
   ([['alpha', 'home', '2.00'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('variant scenario 1',
   ([['bravo', 'home', '1.92'],
     ['bravo', 'draw', '4.45'],
     ['delta', 'draw', '4.87'],
     ['alpha', 'draw', '4.90'],
     ['kilo', 'away', '3.87'],
     ['alpha', 'away', '4.12']],
    25000),
   ['arb', [['away', 'alpha', 6270], ['draw', 'alpha', 5272], ['home', 'bravo', 13456]], 834]),
  ('variant scenario 2',
   ([['alpha', 'home', '1.95'],
     ['bravo', 'home', '2.31'],
     ['bravo', 'away', '1.86'],
     ['alpha', 'away', '1.81'],
     ['kilo', 'away', '1.91']],
    9999),
   ['arb', [['away', 'kilo', 5473], ['home', 'bravo', 4525]], 454])],
 [('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: arb threshold',
   ([['bravo', 'home', '2.86'],
     ['kilo', 'draw', '3.14'],
     ['delta', 'draw', '3.06'],
     ['alpha', 'draw', '3.35'],
     ['bravo', 'away', '2.86'],
     ['alpha', 'away', '2.51'],
     ['kilo', 'away', '2.83']],
    9999),
   ['arb', [['away', 'bravo', 3503], ['draw', 'alpha', 2991], ['home', 'bravo', 3503]], 21]),
  ('regression: arb threshold',
   ([['alpha', 'home', '2.00'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('variant scenario 1',
   ([['bravo', 'home', '2.94'],
     ['kilo', 'home', '2.99'],
     ['alpha', 'draw', '3.29'],
     ['bravo', 'draw', '2.93'],
     ['alpha', 'away', '2.69']],
    25000),
   ['no arb']),
  ('variant scenario 2',
   ([['delta', 'home', '2.53'],
     ['alpha', 'home', '2.76'],
     ['kilo', 'draw', '2.86'],
     ['delta', 'draw', '2.83'],
     ['bravo', 'away', '3.60']],
    10000),
   ['arb', [['away', 'bravo', 2806], ['draw', 'kilo', 3532], ['home', 'alpha', 3660]], 103])]]
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(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 >= Fraction(99, 100):
        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: arb threshold',
   ([['bravo', 'home', '3.77'],
     ['kilo', 'home', '4.11'],
     ['delta', 'home', '3.81'],
     ['kilo', 'draw', '2.56'],
     ['delta', 'draw', '2.44'],
     ['alpha', 'draw', '2.44'],
     ['bravo', 'away', '2.54'],
     ['delta', 'away', '2.78']],
    9999),
   ['arb', [['away', 'delta', 3619], ['draw', 'kilo', 3930], ['home', 'kilo', 2448]], 63]),
  ('regression: arb threshold',
   ([['alpha', 'home', '2.17'],
     ['bravo', 'home', '2.25'],
     ['delta', 'away', '1.57'],
     ['alpha', 'away', '1.80']],
    9999),
   ['no arb']),
  ('variant scenario 1',
   ([['bravo', 'home', '4.00'], ['bravo', 'draw', '2.56'], ['alpha', 'away', '2.61']], 10000),
   ['no arb']),
  ('variant scenario 2',
   ([['kilo', 'home', '2.04'],
     ['alpha', 'home', '2.13'],
     ['bravo', 'home', '2.13'],
     ['alpha', 'away', '2.07'],
     ['bravo', 'away', '1.99'],
     ['delta', 'away', '1.86']],
    10000),
   ['arb', [['away', 'alpha', 5071], ['home', 'alpha', 4928]], 497])],
 [('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: arb threshold',
   ([['bravo', 'home', '2.24'], ['delta', 'home', '2.40'], ['kilo', 'away', '1.72']], 25000),
   ['arb', [['away', 'kilo', 14563], ['home', 'delta', 10436]], 47]),
  ('regression: arb threshold',
   ([['alpha', 'home', '2.00'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('variant scenario 1',
   ([['alpha', 'home', '2.57'], ['delta', 'away', '1.69'], ['bravo', 'home', '2.57']], 10000),
   ['arb', [['away', 'delta', 6032], ['home', 'alpha', 3967]], 195]),
  ('variant scenario 2',
   ([['bravo', 'home', '5.12'],
     ['kilo', 'home', '5.29'],
     ['delta', 'home', '5.73'],
     ['bravo', 'draw', '2.52'],
     ['kilo', 'draw', '2.36'],
     ['kilo', 'away', '2.51']],
    10000),
   ['arb', [['away', 'kilo', 4108], ['draw', 'bravo', 4092], ['home', 'delta', 1799]], 309])],
 [('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: arb threshold',
   ([['delta', 'home', '1.68'],
     ['bravo', 'home', '1.81'],
     ['alpha', 'home', '1.86'],
     ['alpha', 'away', '2.11'],
     ['bravo', 'away', '2.18']],
    9999),
   ['arb', [['away', 'bravo', 4603], ['home', 'alpha', 5395]], 36]),
  ('regression: arb threshold',
   ([['alpha', 'home', '2.00'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('variant scenario 1',
   ([['bravo', 'home', '2.55'],
     ['delta', 'away', '1.60'],
     ['kilo', 'away', '1.43'],
     ['bravo', 'away', '1.43'],
     ['bravo', 'home', '2.55']],
    10000),
   ['no arb']),
  ('variant scenario 2',
   ([['bravo', 'home', '2.81'],
     ['delta', 'home', '3.32'],
     ['kilo', 'home', '2.88'],
     ['alpha', 'draw', '2.81'],
     ['bravo', 'draw', '3.10'],
     ['delta', 'draw', '2.76'],
     ['alpha', 'away', '3.00'],
     ['kilo', 'away', '2.79']],
    10000),
   ['arb', [['away', 'alpha', 3482], ['draw', 'bravo', 3370], ['home', 'delta', 3146]], 446])],
 [('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: arb threshold',
   ([['alpha', 'home', '4.94'],
     ['kilo', 'home', '5.07'],
     ['kilo', 'draw', '1.98'],
     ['bravo', 'away', '3.23'],
     ['delta', 'away', '3.40']],
    25000),
   ['arb', [['away', 'delta', 7379], ['draw', 'kilo', 12671], ['home', 'kilo', 4948]], 88]),
  ('regression: arb threshold',
   ([['alpha', 'home', '2.00'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('variant scenario 1',
   ([['bravo', 'home', '1.92'],
     ['bravo', 'draw', '4.45'],
     ['delta', 'draw', '4.87'],
     ['alpha', 'draw', '4.90'],
     ['kilo', 'away', '3.87'],
     ['alpha', 'away', '4.12']],
    25000),
   ['arb', [['away', 'alpha', 6270], ['draw', 'alpha', 5272], ['home', 'bravo', 13456]], 834]),
  ('variant scenario 2',
   ([['alpha', 'home', '1.95'],
     ['bravo', 'home', '2.31'],
     ['bravo', 'away', '1.86'],
     ['alpha', 'away', '1.81'],
     ['kilo', 'away', '1.91']],
    9999),
   ['arb', [['away', 'kilo', 5473], ['home', 'bravo', 4525]], 454])],
 [('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: arb threshold',
   ([['bravo', 'home', '2.86'],
     ['kilo', 'draw', '3.14'],
     ['delta', 'draw', '3.06'],
     ['alpha', 'draw', '3.35'],
     ['bravo', 'away', '2.86'],
     ['alpha', 'away', '2.51'],
     ['kilo', 'away', '2.83']],
    9999),
   ['arb', [['away', 'bravo', 3503], ['draw', 'alpha', 2991], ['home', 'bravo', 3503]], 21]),
  ('regression: arb threshold',
   ([['alpha', 'home', '2.00'], ['bravo', 'away', '2.00']], 10000),
   ['no arb']),
  ('variant scenario 1',
   ([['bravo', 'home', '2.94'],
     ['kilo', 'home', '2.99'],
     ['alpha', 'draw', '3.29'],
     ['bravo', 'draw', '2.93'],
     ['alpha', 'away', '2.69']],
    25000),
   ['no arb']),
  ('variant scenario 2',
   ([['delta', 'home', '2.53'],
     ['alpha', 'home', '2.76'],
     ['kilo', 'draw', '2.86'],
     ['delta', 'draw', '2.83'],
     ['bravo', 'away', '3.60']],
    10000),
   ['arb', [['away', 'bravo', 2806], ['draw', 'kilo', 3532], ['home', 'alpha', 3660]], 103])]]
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 book summing to exactly 100 percent is reported as a sure bet.

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


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 * d / sum(x for x, _ in best.values()))
        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: stake proportion',
   ([['kilo', 'home', '1.77'], ['bravo', 'home', '1.70'], ['alpha', 'away', '2.31']], 10000),
   ['arb', [['away', 'alpha', 4338], ['home', 'kilo', 5661]], 20]),
  ('variant scenario 1',
   ([['alpha', 'home', '3.03'],
     ['kilo', 'home', '3.37'],
     ['bravo', 'home', '3.49'],
     ['alpha', 'draw', '2.44'],
     ['kilo', 'draw', '2.76'],
     ['bravo', 'away', '3.15'],
     ['alpha', 'away', '3.31'],
     ['bravo', 'home', '3.03']],
    10000),
   ['arb', [['away', 'alpha', 3176], ['draw', 'kilo', 3810], ['home', 'bravo', 3013]], 513]),
  ('variant scenario 2',
   ([['kilo', 'home', '2.80'],
     ['delta', 'draw', '2.92'],
     ['alpha', 'draw', '2.54'],
     ['kilo', 'draw', '2.85'],
     ['kilo', 'away', '3.32'],
     ['delta', 'away', '3.86'],
     ['alpha', 'away', '3.71']],
    10000),
   ['arb', [['away', 'delta', 2702], ['draw', 'delta', 3572], ['home', 'kilo', 3725]], 430])],
 [('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: stake proportion',
   ([['bravo', 'home', '2.41'],
     ['delta', 'home', '2.58'],
     ['delta', 'away', '1.71'],
     ['kilo', 'away', '1.73'],
     ['alpha', 'home', '2.41']],
    25000),
   ['arb', [['away', 'kilo', 14965], ['home', 'delta', 10034]], 888]),
  ('variant scenario 1',
   ([['alpha', 'home', '2.55'],
     ['bravo', 'home', '2.43'],
     ['bravo', 'draw', '3.12'],
     ['alpha', 'away', '3.68'],
     ['delta', 'away', '4.14'],
     ['kilo', 'away', '4.12']],
    25000),
   ['arb', [['away', 'delta', 6328], ['draw', 'bravo', 8397], ['home', 'alpha', 10274]], 1198]),
  ('variant scenario 2',
   ([['bravo', 'home', '1.81'],
     ['delta', 'draw', '4.47'],
     ['kilo', 'away', '4.69'],
     ['bravo', 'away', '4.85'],
     ['bravo', 'home', '1.81']],
    9999),
   ['arb', [['away', 'bravo', 2098], ['draw', 'delta', 2277], ['home', 'bravo', 5623]], 177])],
 [('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: stake proportion',
   ([['alpha', 'home', '4.00'],
     ['delta', 'home', '4.38'],
     ['bravo', 'home', '4.21'],
     ['kilo', 'draw', '1.87'],
     ['bravo', 'draw', '1.93'],
     ['delta', 'draw', '1.87'],
     ['bravo', 'away', '3.76'],
     ['kilo', 'away', '4.13'],
     ['delta', 'away', '4.11']],
    25000),
   ['arb', [['away', 'kilo', 6123], ['draw', 'bravo', 13103], ['home', 'delta', 5773]], 286]),
  ('variant scenario 1',
   ([['bravo', 'home', '3.11'],
     ['delta', 'home', '3.18'],
     ['delta', 'draw', '4.37'],
     ['bravo', 'draw', '4.52'],
     ['kilo', 'draw', '4.14'],
     ['bravo', 'away', '2.15']],
    25000),
   ['no arb']),
  ('variant scenario 2',
   ([['alpha', 'home', '2.53'],
     ['delta', 'home', '2.41'],
     ['kilo', 'home', '2.24'],
     ['bravo', 'away', '1.78'],
     ['delta', 'away', '1.55']],
    25000),
   ['arb', [['away', 'bravo', 14675], ['home', 'alpha', 10324]], 1120])],
 [('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: stake proportion',
   ([['bravo', 'home', '2.35'],
     ['kilo', 'home', '2.21'],
     ['delta', 'home', '2.23'],
     ['kilo', 'draw', '2.92'],
     ['bravo', 'draw', '3.06'],
     ['alpha', 'draw', '2.87'],
     ['delta', 'away', '4.09'],
     ['bravo', 'away', '4.25'],
     ['alpha', 'away', '4.23']],
    10000),
   ['arb', [['away', 'bravo', 2382], ['draw', 'bravo', 3308], ['home', 'bravo', 4308]], 124]),
  ('variant scenario 1',
   ([['delta', 'home', '1.77'],
     ['alpha', 'home', '1.75'],
     ['bravo', 'home', '1.66'],
     ['bravo', 'away', '2.34'],
     ['kilo', 'away', '2.44'],
     ['delta', 'away', '2.39']],
    9999),
   ['arb', [['away', 'kilo', 4203], ['home', 'delta', 5795]], 257]),
  ('variant scenario 2',
   ([['delta', 'home', '1.88'],
     ['alpha', 'home', '2.19'],
     ['bravo', 'home', '2.04'],
     ['kilo', 'draw', '5.15'],
     ['alpha', 'away', '2.93']],
    10000),
   ['arb', [['away', 'alpha', 3440], ['draw', 'kilo', 1957], ['home', 'alpha', 4602]], 79])],
 [('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: stake proportion',
   ([['kilo', 'home', '2.14'],
     ['bravo', 'home', '2.12'],
     ['alpha', 'home', '1.97'],
     ['delta', 'away', '1.68'],
     ['bravo', 'away', '1.77'],
     ['kilo', 'away', '1.89']],
    25000),
   ['arb', [['away', 'kilo', 13275], ['home', 'kilo', 11724]], 90]),
  ('variant scenario 1',
   ([['alpha', 'home', '2.52'],
     ['bravo', 'home', '2.60'],
     ['delta', 'draw', '2.13'],
     ['kilo', 'away', '4.85'],
     ['alpha', 'away', '4.61']],
    10000),
   ['no arb']),
  ('variant scenario 2',
   ([['bravo', 'home', '2.64'],
     ['kilo', 'home', '2.42'],
     ['delta', 'home', '2.49'],
     ['bravo', 'away', '1.55']],
    25000),
   ['no arb'])]]
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 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 = total_cents // len(best)
        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: stake proportion',
   ([['kilo', 'home', '1.77'], ['bravo', 'home', '1.70'], ['alpha', 'away', '2.31']], 10000),
   ['arb', [['away', 'alpha', 4338], ['home', 'kilo', 5661]], 20]),
  ('variant scenario 1',
   ([['alpha', 'home', '3.03'],
     ['kilo', 'home', '3.37'],
     ['bravo', 'home', '3.49'],
     ['alpha', 'draw', '2.44'],
     ['kilo', 'draw', '2.76'],
     ['bravo', 'away', '3.15'],
     ['alpha', 'away', '3.31'],
     ['bravo', 'home', '3.03']],
    10000),
   ['arb', [['away', 'alpha', 3176], ['draw', 'kilo', 3810], ['home', 'bravo', 3013]], 513]),
  ('variant scenario 2',
   ([['kilo', 'home', '2.80'],
     ['delta', 'draw', '2.92'],
     ['alpha', 'draw', '2.54'],
     ['kilo', 'draw', '2.85'],
     ['kilo', 'away', '3.32'],
     ['delta', 'away', '3.86'],
     ['alpha', 'away', '3.71']],
    10000),
   ['arb', [['away', 'delta', 2702], ['draw', 'delta', 3572], ['home', 'kilo', 3725]], 430])],
 [('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: stake proportion',
   ([['bravo', 'home', '2.41'],
     ['delta', 'home', '2.58'],
     ['delta', 'away', '1.71'],
     ['kilo', 'away', '1.73'],
     ['alpha', 'home', '2.41']],
    25000),
   ['arb', [['away', 'kilo', 14965], ['home', 'delta', 10034]], 888]),
  ('variant scenario 1',
   ([['alpha', 'home', '2.55'],
     ['bravo', 'home', '2.43'],
     ['bravo', 'draw', '3.12'],
     ['alpha', 'away', '3.68'],
     ['delta', 'away', '4.14'],
     ['kilo', 'away', '4.12']],
    25000),
   ['arb', [['away', 'delta', 6328], ['draw', 'bravo', 8397], ['home', 'alpha', 10274]], 1198]),
  ('variant scenario 2',
   ([['bravo', 'home', '1.81'],
     ['delta', 'draw', '4.47'],
     ['kilo', 'away', '4.69'],
     ['bravo', 'away', '4.85'],
     ['bravo', 'home', '1.81']],
    9999),
   ['arb', [['away', 'bravo', 2098], ['draw', 'delta', 2277], ['home', 'bravo', 5623]], 177])],
 [('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: stake proportion',
   ([['alpha', 'home', '4.00'],
     ['delta', 'home', '4.38'],
     ['bravo', 'home', '4.21'],
     ['kilo', 'draw', '1.87'],
     ['bravo', 'draw', '1.93'],
     ['delta', 'draw', '1.87'],
     ['bravo', 'away', '3.76'],
     ['kilo', 'away', '4.13'],
     ['delta', 'away', '4.11']],
    25000),
   ['arb', [['away', 'kilo', 6123], ['draw', 'bravo', 13103], ['home', 'delta', 5773]], 286]),
  ('variant scenario 1',
   ([['bravo', 'home', '3.11'],
     ['delta', 'home', '3.18'],
     ['delta', 'draw', '4.37'],
     ['bravo', 'draw', '4.52'],
     ['kilo', 'draw', '4.14'],
     ['bravo', 'away', '2.15']],
    25000),
   ['no arb']),
  ('variant scenario 2',
   ([['alpha', 'home', '2.53'],
     ['delta', 'home', '2.41'],
     ['kilo', 'home', '2.24'],
     ['bravo', 'away', '1.78'],
     ['delta', 'away', '1.55']],
    25000),
   ['arb', [['away', 'bravo', 14675], ['home', 'alpha', 10324]], 1120])],
 [('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: stake proportion',
   ([['bravo', 'home', '2.35'],
     ['kilo', 'home', '2.21'],
     ['delta', 'home', '2.23'],
     ['kilo', 'draw', '2.92'],
     ['bravo', 'draw', '3.06'],
     ['alpha', 'draw', '2.87'],
     ['delta', 'away', '4.09'],
     ['bravo', 'away', '4.25'],
     ['alpha', 'away', '4.23']],
    10000),
   ['arb', [['away', 'bravo', 2382], ['draw', 'bravo', 3308], ['home', 'bravo', 4308]], 124]),
  ('variant scenario 1',
   ([['delta', 'home', '1.77'],
     ['alpha', 'home', '1.75'],
     ['bravo', 'home', '1.66'],
     ['bravo', 'away', '2.34'],
     ['kilo', 'away', '2.44'],
     ['delta', 'away', '2.39']],
    9999),
   ['arb', [['away', 'kilo', 4203], ['home', 'delta', 5795]], 257]),
  ('variant scenario 2',
   ([['delta', 'home', '1.88'],
     ['alpha', 'home', '2.19'],
     ['bravo', 'home', '2.04'],
     ['kilo', 'draw', '5.15'],
     ['alpha', 'away', '2.93']],
    10000),
   ['arb', [['away', 'alpha', 3440], ['draw', 'kilo', 1957], ['home', 'alpha', 4602]], 79])],
 [('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: stake proportion',
   ([['kilo', 'home', '2.14'],
     ['bravo', 'home', '2.12'],
     ['alpha', 'home', '1.97'],
     ['delta', 'away', '1.68'],
     ['bravo', 'away', '1.77'],
     ['kilo', 'away', '1.89']],
    25000),
   ['arb', [['away', 'kilo', 13275], ['home', 'kilo', 11724]], 90]),
  ('variant scenario 1',
   ([['alpha', 'home', '2.52'],
     ['bravo', 'home', '2.60'],
     ['delta', 'draw', '2.13'],
     ['kilo', 'away', '4.85'],
     ['alpha', 'away', '4.61']],
    10000),
   ['no arb']),
  ('variant scenario 2',
   ([['bravo', 'home', '2.64'],
     ['kilo', 'home', '2.42'],
     ['delta', 'home', '2.49'],
     ['bravo', 'away', '1.55']],
    25000),
   ['no arb'])]]
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 stake split loses money on one outcome.

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


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(price, side):
    BANDS = [(101, 200, 1), (200, 300, 2), (300, 400, 5), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]
    c = Fraction(price) * 100
    if c < 101 or c > 100000:
        return 'invalid'
    for lo, hi, step in BANDS:
        if lo <= c < hi:
            k = (c - lo) / step
            k = math.ceil(k) if side == 'back' else math.floor(k)
            v = lo + k * step
            break
    return '%d.%02d' % (v // 100, v % 100)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('11.88', 'back'), '11.50'),
  ('variant scenario 1', ('1.94', 'lay'), '1.94'),
  ('variant scenario 2', ('1.00', 'back'), 'invalid')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('484.08', 'lay'), '490.00'),
  ('variant scenario 1', ('1.25', 'lay'), '1.25'),
  ('variant scenario 2', ('21.34', 'lay'), '22.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('3.14', 'back'), '3.10'),
  ('variant scenario 1', ('21.44', 'lay'), '22.00'),
  ('variant scenario 2', ('853.33', 'back'), '850.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('2.27', 'back'), '2.26'),
  ('variant scenario 1', ('1.94', 'lay'), '1.94'),
  ('variant scenario 2', ('248.87', 'back'), '240.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('3.52', 'back'), '3.50'),
  ('regression: rounding direction', ('221.87', 'lay'), '230.00'),
  ('variant scenario 1', ('785.23', 'lay'), '790.00'),
  ('variant scenario 2', ('1.67', 'lay'), '1.67')]]
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(price, side):
    BANDS = [(101, 200, 1), (200, 300, 2), (300, 400, 5), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]
    c = Fraction(price) * 100
    if c < 101 or c > 100000:
        return 'invalid'
    for lo, hi, step in BANDS:
        if lo <= c < hi:
            k = (c - lo) / step
            k = round(k)
            v = lo + k * step
            break
    return '%d.%02d' % (v // 100, v % 100)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('11.88', 'back'), '11.50'),
  ('variant scenario 1', ('1.94', 'lay'), '1.94'),
  ('variant scenario 2', ('1.00', 'back'), 'invalid')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('484.08', 'lay'), '490.00'),
  ('variant scenario 1', ('1.25', 'lay'), '1.25'),
  ('variant scenario 2', ('21.34', 'lay'), '22.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('3.14', 'back'), '3.10'),
  ('variant scenario 1', ('21.44', 'lay'), '22.00'),
  ('variant scenario 2', ('853.33', 'back'), '850.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('2.27', 'back'), '2.26'),
  ('variant scenario 1', ('1.94', 'lay'), '1.94'),
  ('variant scenario 2', ('248.87', 'back'), '240.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('3.52', 'back'), '3.50'),
  ('regression: rounding direction', ('221.87', 'lay'), '230.00'),
  ('variant scenario 1', ('785.23', 'lay'), '790.00'),
  ('variant scenario 2', ('1.67', 'lay'), '1.67')]]
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 back order is snapped to a better price than requested.

Snap a requested price onto an exchange tick ladder. Bands in hundredths [lo, hi, step]: [(101, 200, 1), (200, 300, 2), (300, 400, 5), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]. Prices outside 1.01..1000 return "invalid". A back request rounds down to a valid tick and a lay request rounds up (ticks counted from the band lower bound). Return the tick as "%d.%02d".

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(price, side):
    BANDS = [(101, 200, 1), (200, 300, 2), (300, 400, 2), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]
    c = Fraction(price) * 100
    if c < 101 or c > 100000:
        return 'invalid'
    for lo, hi, step in BANDS:
        if lo <= c < hi:
            k = (c - lo) / step
            k = math.floor(k) if side == 'back' else math.ceil(k)
            v = lo + k * step
            break
    return '%d.%02d' % (v // 100, v % 100)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: band step table', ('3.97', 'lay'), '4.00'),
  ('regression: band step table', ('3.75', 'back'), '3.75'),
  ('variant scenario 1', ('24.78', 'lay'), '25.00'),
  ('variant scenario 2', ('1.96', 'back'), '1.96')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: band step table', ('3.07', 'back'), '3.05'),
  ('variant scenario 1', ('958.93', 'lay'), '960.00'),
  ('variant scenario 2', ('29.66', 'lay'), '30.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: band step table', ('3.47', 'lay'), '3.50'),
  ('regression: band step table', ('3.47', 'back'), '3.45'),
  ('variant scenario 1', ('1.99', 'lay'), '1.99'),
  ('variant scenario 2', ('2.63', 'lay'), '2.64')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: band step table', ('3.73', 'back'), '3.70'),
  ('regression: band step table', ('3.03', 'lay'), '3.05'),
  ('variant scenario 1', ('583.07', 'back'), '580.00'),
  ('variant scenario 2', ('11.37', 'back'), '11.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: band step table', ('3.64', 'lay'), '3.65'),
  ('variant scenario 1', ('6.62', 'back'), '6.60'),
  ('variant scenario 2', ('13.02', 'lay'), '13.50')]]
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(price, side):
    BANDS = [(101, 200, 1), (200, 300, 2), (300, 400, 10), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]
    c = Fraction(price) * 100
    if c < 101 or c > 100000:
        return 'invalid'
    for lo, hi, step in BANDS:
        if lo <= c < hi:
            k = (c - lo) / step
            k = math.floor(k) if side == 'back' else math.ceil(k)
            v = lo + k * step
            break
    return '%d.%02d' % (v // 100, v % 100)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: band step table', ('3.97', 'lay'), '4.00'),
  ('regression: band step table', ('3.75', 'back'), '3.75'),
  ('variant scenario 1', ('24.78', 'lay'), '25.00'),
  ('variant scenario 2', ('1.96', 'back'), '1.96')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: band step table', ('3.07', 'back'), '3.05'),
  ('variant scenario 1', ('958.93', 'lay'), '960.00'),
  ('variant scenario 2', ('29.66', 'lay'), '30.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: band step table', ('3.47', 'lay'), '3.50'),
  ('regression: band step table', ('3.47', 'back'), '3.45'),
  ('variant scenario 1', ('1.99', 'lay'), '1.99'),
  ('variant scenario 2', ('2.63', 'lay'), '2.64')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: band step table', ('3.73', 'back'), '3.70'),
  ('regression: band step table', ('3.03', 'lay'), '3.05'),
  ('variant scenario 1', ('583.07', 'back'), '580.00'),
  ('variant scenario 2', ('11.37', 'back'), '11.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: band step table', ('3.64', 'lay'), '3.65'),
  ('variant scenario 1', ('6.62', 'back'), '6.60'),
  ('variant scenario 2', ('13.02', 'lay'), '13.50')]]
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:
Prices between 3.00 and 4.00 snap to 0.02 increments.

Snap a requested price onto an exchange tick ladder. Bands in hundredths [lo, hi, step]: [(101, 200, 1), (200, 300, 2), (300, 400, 5), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]. Prices outside 1.01..1000 return "invalid". A back request rounds down to a valid tick and a lay request rounds up (ticks counted from the band lower bound). Return the tick as "%d.%02d".

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(price, side):
    BANDS = [(101, 200, 1), (200, 300, 2), (300, 400, 5), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]
    c = Fraction(price) * 100
    if c < 100 or c > 100000:
        return 'invalid'
    for lo, hi, step in BANDS:
        if lo <= c < hi:
            k = (c - lo) / step
            k = math.floor(k) if side == 'back' else math.ceil(k)
            v = lo + k * step
            break
    return '%d.%02d' % (v // 100, v % 100)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: ladder range', ('1.00', 'back'), 'invalid'),
  ('regression: ladder range', ('1.01', 'back'), '1.01'),
  ('variant scenario 1', ('3.43', 'back'), '3.40'),
  ('variant scenario 2', ('715.39', 'lay'), '720.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: ladder range', ('1.01', 'back'), '1.01'),
  ('regression: ladder range', ('1.00', 'lay'), 'invalid'),
  ('variant scenario 1', ('23.13', 'lay'), '24.00'),
  ('variant scenario 2', ('2.94', 'back'), '2.94')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: ladder range', ('1.00', 'lay'), 'invalid'),
  ('regression: ladder range', ('1.01', 'lay'), '1.01'),
  ('variant scenario 1', ('20.82', 'lay'), '21.00'),
  ('variant scenario 2', ('2.89', 'lay'), '2.90')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: ladder range', ('1.00', 'back'), 'invalid'),
  ('regression: ladder range', ('1.01', 'back'), '1.01'),
  ('variant scenario 1', ('3.05', 'lay'), '3.05'),
  ('variant scenario 2', ('3.46', 'lay'), '3.50')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: ladder range', ('1.01', 'lay'), '1.01'),
  ('regression: ladder range', ('1.00', 'lay'), 'invalid'),
  ('variant scenario 1', ('1.30', 'back'), '1.30'),
  ('variant scenario 2', ('16.96', 'back'), '16.50')]]
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(price, side):
    BANDS = [(101, 200, 1), (200, 300, 2), (300, 400, 5), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]
    c = Fraction(price) * 100
    if c <= 101 or c > 100000:
        return 'invalid'
    for lo, hi, step in BANDS:
        if lo <= c < hi:
            k = (c - lo) / step
            k = math.floor(k) if side == 'back' else math.ceil(k)
            v = lo + k * step
            break
    return '%d.%02d' % (v // 100, v % 100)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: ladder range', ('1.00', 'back'), 'invalid'),
  ('regression: ladder range', ('1.01', 'back'), '1.01'),
  ('variant scenario 1', ('3.43', 'back'), '3.40'),
  ('variant scenario 2', ('715.39', 'lay'), '720.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: ladder range', ('1.01', 'back'), '1.01'),
  ('regression: ladder range', ('1.00', 'lay'), 'invalid'),
  ('variant scenario 1', ('23.13', 'lay'), '24.00'),
  ('variant scenario 2', ('2.94', 'back'), '2.94')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: ladder range', ('1.00', 'lay'), 'invalid'),
  ('regression: ladder range', ('1.01', 'lay'), '1.01'),
  ('variant scenario 1', ('20.82', 'lay'), '21.00'),
  ('variant scenario 2', ('2.89', 'lay'), '2.90')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: ladder range', ('1.00', 'back'), 'invalid'),
  ('regression: ladder range', ('1.01', 'back'), '1.01'),
  ('variant scenario 1', ('3.05', 'lay'), '3.05'),
  ('variant scenario 2', ('3.46', 'lay'), '3.50')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: ladder range', ('1.01', 'lay'), '1.01'),
  ('regression: ladder range', ('1.00', 'lay'), 'invalid'),
  ('variant scenario 1', ('1.30', 'back'), '1.30'),
  ('variant scenario 2', ('16.96', 'back'), '16.50')]]
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 1.00 request crashes the snapping loop or the 1.01 minimum is rejected.

Snap a requested price onto an exchange tick ladder. Bands in hundredths [lo, hi, step]: [(101, 200, 1), (200, 300, 2), (300, 400, 5), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]. Prices outside 1.01..1000 return "invalid". A back request rounds down to a valid tick and a lay request rounds up (ticks counted from the band lower bound). Return the tick as "%d.%02d".

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(a, b):
    BANDS = [(101, 200, 1), (200, 300, 2), (300, 400, 5), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]
    def index(v):
        n = 0
        for lo, hi, step in BANDS:
            if v >= hi:
                n += (hi - lo) // step + 1
            else:
                if (v - lo) % step:
                    return None
                return n + (v - lo) // step
        return None
    out = []
    for p in (a, b):
        c = Fraction(p) * 100
        if c.denominator != 1 or c < 101 or c > 100000:
            return 'invalid'
        i = index(int(c))
        if i is None:
            return 'off ladder'
        out.append(i)
    return out[1] - out[0]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: band fencepost', ('2.38', '850.00'), 216),
  ('variant scenario 1', ('6.00', '2.16'), -82),
  ('variant scenario 2', ('3.01', '5.00'), 'off ladder')],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: band fencepost', ('4.50', '1.60'), -115),
  ('variant scenario 1', ('3.76', '2.22'), 'off ladder'),
  ('variant scenario 2', ('6.00', '9.60'), 18)],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: band fencepost', ('530.00', '5.10'), -122),
  ('variant scenario 1', ('5.40', '3.30'), -28),
  ('variant scenario 2', ('3.70', '7.40'), 33)],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: band fencepost', ('5.40', '13.50'), 33),
  ('variant scenario 1', ('7.41', '2.64'), 'off ladder'),
  ('variant scenario 2', ('5.00', '2.76'), -42)],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: band fencepost', ('1.46', '7.20'), 150),
  ('variant scenario 1', ('2.66', '5.80'), 55),
  ('variant scenario 2', ('5.21', '2.00'), 'off ladder')]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(a, b):
    BANDS = [(101, 200, 1), (200, 300, 2), (300, 400, 5), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]
    def index(v):
        n = 0
        for lo, hi, step in BANDS:
            if v >= hi:
                n += (hi - lo) // step - 1
            else:
                if (v - lo) % step:
                    return None
                return n + (v - lo) // step
        return None
    out = []
    for p in (a, b):
        c = Fraction(p) * 100
        if c.denominator != 1 or c < 101 or c > 100000:
            return 'invalid'
        i = index(int(c))
        if i is None:
            return 'off ladder'
        out.append(i)
    return out[1] - out[0]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: band fencepost', ('2.38', '850.00'), 216),
  ('variant scenario 1', ('6.00', '2.16'), -82),
  ('variant scenario 2', ('3.01', '5.00'), 'off ladder')],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: band fencepost', ('4.50', '1.60'), -115),
  ('variant scenario 1', ('3.76', '2.22'), 'off ladder'),
  ('variant scenario 2', ('6.00', '9.60'), 18)],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: band fencepost', ('530.00', '5.10'), -122),
  ('variant scenario 1', ('5.40', '3.30'), -28),
  ('variant scenario 2', ('3.70', '7.40'), 33)],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: band fencepost', ('5.40', '13.50'), 33),
  ('variant scenario 1', ('7.41', '2.64'), 'off ladder'),
  ('variant scenario 2', ('5.00', '2.76'), -42)],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: band fencepost', ('1.46', '7.20'), 150),
  ('variant scenario 1', ('2.66', '5.80'), 55),
  ('variant scenario 2', ('5.21', '2.00'), 'off ladder')]]
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:
Tick distances crossing a band boundary are off by one per boundary crossed.

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

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(a, b):
    BANDS = [(101, 200, 1), (200, 300, 2), (300, 400, 5), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]
    def index(v):
        n = 0
        for lo, hi, step in BANDS:
            if v >= hi:
                n += (hi - lo) // step
            else:
                return n + (v - lo) // step
        return None
    out = []
    for p in (a, b):
        c = Fraction(p) * 100
        if c.denominator != 1 or c < 101 or c > 100000:
            return 'invalid'
        i = index(int(c))
        if i is None:
            return 'off ladder'
        out.append(i)
    return out[1] - out[0]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: off ladder detection', ('2.01', '5.50'), 'off ladder'),
  ('variant scenario 1', ('29.00', '10.00'), -29),
  ('variant scenario 2', ('12.00', '160.00'), 52)],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: off ladder detection', ('55.00', '11.01'), 'off ladder'),
  ('variant scenario 1', ('2.18', '2.72'), 27),
  ('variant scenario 2', ('190.00', '3.20'), -115)],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: off ladder detection', ('5.51', '1.61'), 'off ladder'),
  ('variant scenario 1', ('1.57', '13.00'), 159),
  ('variant scenario 2', ('2.84', '3.50'), 18)],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: off ladder detection', ('4.41', '4.00'), 'off ladder'),
  ('variant scenario 1', ('6.20', '13.00'), 25),
  ('variant scenario 2', ('80.00', '15.50'), -35)],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: off ladder detection', ('5.91', '20.00'), 'off ladder'),
  ('variant scenario 1', ('16.50', '1.41'), -182),
  ('variant scenario 2', ('10.00', '2.32'), -94)]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(a, b):
    BANDS = [(101, 200, 1), (200, 300, 2), (300, 400, 5), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]
    def index(v):
        n = 0
        for lo, hi, step in BANDS:
            if v >= hi:
                n += (hi - lo) // step
            else:
                return n + round((v - lo) / step)
        return None
    out = []
    for p in (a, b):
        c = Fraction(p) * 100
        if c.denominator != 1 or c < 101 or c > 100000:
            return 'invalid'
        i = index(int(c))
        if i is None:
            return 'off ladder'
        out.append(i)
    return out[1] - out[0]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: off ladder detection', ('2.01', '5.50'), 'off ladder'),
  ('variant scenario 1', ('29.00', '10.00'), -29),
  ('variant scenario 2', ('12.00', '160.00'), 52)],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: off ladder detection', ('55.00', '11.01'), 'off ladder'),
  ('variant scenario 1', ('2.18', '2.72'), 27),
  ('variant scenario 2', ('190.00', '3.20'), -115)],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: off ladder detection', ('5.51', '1.61'), 'off ladder'),
  ('variant scenario 1', ('1.57', '13.00'), 159),
  ('variant scenario 2', ('2.84', '3.50'), 18)],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: off ladder detection', ('4.41', '4.00'), 'off ladder'),
  ('variant scenario 1', ('6.20', '13.00'), 25),
  ('variant scenario 2', ('80.00', '15.50'), -35)],
 [('control within band', ('1.50', '1.60'), 10),
  ('boundary crossing two', ('1.98', '2.04'), 4),
  ('control downward move', ('3.10', '2.90'), -7),
  ('boundary off ladder', ('2.01', '2.50'), 'off ladder'),
  ('control full ladder', ('1.01', '1000'), 349),
  ('regression: off ladder detection', ('5.91', '20.00'), 'off ladder'),
  ('variant scenario 1', ('16.50', '1.41'), -182),
  ('variant scenario 2', ('10.00', '2.32'), -94)]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A 2.01 request is treated as a valid tick.

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

split: open-access