broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(prices, method):
    ps = [1 / float(d) for d in prices]
    book = sum(ps)
    n = len(ps)
    if method == 'multiplicative':
        fair = [p / book for p in ps]
    elif method == 'additive':
        fair = [p - (book - 1) for p in ps]
        if any(x < 0 for x in fair):
            return 'additive infeasible'
    elif method == 'power':
        lo, hi = 1.0, 10.0
        for _ in range(60):
            mid = (lo + hi) / 2
            if sum(p ** mid for p in ps) > 1:
                lo = mid
            else:
                hi = mid
        k = (lo + hi) / 2
        fair = [p ** k for p in ps]
    else:
        return 'invalid method'
    return ['%.4f' % x for x in fair]
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 multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive share',
   (['4.24', '2.41', '2.26'], 'additive'),
   ['0.2048', '0.3838', '0.4114']),
  ('variant scenario 1',
   (['3.13', '10.94', '3.74', '3.80', '7.37'], 'power'),
   ['0.3013', '0.0808', '0.2498', '0.2457', '0.1224']),
  ('variant scenario 2', (['2.76', '4.20', '18.02', '17.82', '2.41'], 'shin'), 'invalid method')],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive share', (['1.06', '13.81'], 'additive'), ['0.9355', '0.0645']),
  ('variant scenario 1',
   (['4.95', '1.53', '3.74'], 'multiplicative'),
   ['0.1799', '0.5820', '0.2381']),
  ('variant scenario 2', (['2.57', '2.14', '3.17'], 'power'), ['0.3310', '0.4102', '0.2589'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive share',
   (['5.15', '6.00', '9.30', '3.30', '3.41'], 'additive'),
   ['0.1812', '0.1537', '0.0946', '0.2901', '0.2803']),
  ('variant scenario 1', (['3.47', '2.27', '4.50', '6.40', '11.33'], 'shin'), 'invalid method'),
  ('variant scenario 2',
   (['1.19', '4.17', '10.00'], 'multiplicative'),
   ['0.7121', '0.2032', '0.0847'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive share',
   (['12.06', '6.47', '2.90', '3.41', '4.16'], 'additive'),
   ['0.0597', '0.1314', '0.3216', '0.2701', '0.2172']),
  ('variant scenario 1', (['1.79', '3.93', '3.07'], 'power'), ['0.5138', '0.2090', '0.2772']),
  ('variant scenario 2',
   (['34.48', '3.06', '3.75', '8.76', '3.57'], 'multiplicative'),
   ['0.0285', '0.3214', '0.2623', '0.1123', '0.2755'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive share',
   (['2.21', '2.18', '7.95', '13.06'], 'additive'),
   ['0.4241', '0.4303', '0.0974', '0.0482']),
  ('variant scenario 1',
   (['2.60', '6.34', '4.18', '2.94'], 'power'),
   ['0.3514', '0.1325', '0.2090', '0.3072']),
  ('variant scenario 2',
   (['2.29', '2.38', '4.59', '9.61'], 'power'),
   ['0.3850', '0.3683', '0.1728', '0.0738'])]]
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

N = 1
observations = []
def solve(prices, method):
    ps = [1 / float(d) for d in prices]
    book = sum(ps)
    n = len(ps)
    if method == 'multiplicative':
        fair = [p / book for p in ps]
    elif method == 'additive':
        fair = [p - (book - 1) / (n - 1) for p in ps]
        if any(x < 0 for x in fair):
            return 'additive infeasible'
    elif method == 'power':
        lo, hi = 1.0, 10.0
        for _ in range(60):
            mid = (lo + hi) / 2
            if sum(p ** mid for p in ps) > 1:
                lo = mid
            else:
                hi = mid
        k = (lo + hi) / 2
        fair = [p ** k for p in ps]
    else:
        return 'invalid method'
    return ['%.4f' % x for x in fair]
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 multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive share',
   (['4.24', '2.41', '2.26'], 'additive'),
   ['0.2048', '0.3838', '0.4114']),
  ('variant scenario 1',
   (['3.13', '10.94', '3.74', '3.80', '7.37'], 'power'),
   ['0.3013', '0.0808', '0.2498', '0.2457', '0.1224']),
  ('variant scenario 2', (['2.76', '4.20', '18.02', '17.82', '2.41'], 'shin'), 'invalid method')],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive share', (['1.06', '13.81'], 'additive'), ['0.9355', '0.0645']),
  ('variant scenario 1',
   (['4.95', '1.53', '3.74'], 'multiplicative'),
   ['0.1799', '0.5820', '0.2381']),
  ('variant scenario 2', (['2.57', '2.14', '3.17'], 'power'), ['0.3310', '0.4102', '0.2589'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive share',
   (['5.15', '6.00', '9.30', '3.30', '3.41'], 'additive'),
   ['0.1812', '0.1537', '0.0946', '0.2901', '0.2803']),
  ('variant scenario 1', (['3.47', '2.27', '4.50', '6.40', '11.33'], 'shin'), 'invalid method'),
  ('variant scenario 2',
   (['1.19', '4.17', '10.00'], 'multiplicative'),
   ['0.7121', '0.2032', '0.0847'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive share',
   (['12.06', '6.47', '2.90', '3.41', '4.16'], 'additive'),
   ['0.0597', '0.1314', '0.3216', '0.2701', '0.2172']),
  ('variant scenario 1', (['1.79', '3.93', '3.07'], 'power'), ['0.5138', '0.2090', '0.2772']),
  ('variant scenario 2',
   (['34.48', '3.06', '3.75', '8.76', '3.57'], 'multiplicative'),
   ['0.0285', '0.3214', '0.2623', '0.1123', '0.2755'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive share',
   (['2.21', '2.18', '7.95', '13.06'], 'additive'),
   ['0.4241', '0.4303', '0.0974', '0.0482']),
  ('variant scenario 1',
   (['2.60', '6.34', '4.18', '2.94'], 'power'),
   ['0.3514', '0.1325', '0.2090', '0.3072']),
  ('variant scenario 2',
   (['2.29', '2.38', '4.59', '9.61'], 'power'),
   ['0.3850', '0.3683', '0.1728', '0.0738'])]]
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:
Additive fair probabilities sum to well below one.

Remove the bookmaker margin from decimal prices (implied p = 1/d, book = sum p > 1 assumed). multiplicative: p / book. additive: p - (book - 1) / n; if any result is negative return "additive infeasible". power: p ** k with k found by 60 bisection steps on [1, 10] so that the powered probabilities sum to 1 (k = midpoint of the final bracket). Any other method returns "invalid method". Return the fair probabilities formatted "%.4f".

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(prices, method):
    ps = [1 / float(d) for d in prices]
    book = sum(ps)
    n = len(ps)
    if method == 'multiplicative':
        fair = [p / book for p in ps]
    elif method == 'additive':
        fair = [p - (book - 1) / n for p in ps]
        if any(x < 0 for x in fair):
            return 'additive infeasible'
    elif method == 'power':
        lo, hi = 1.0, 10.0
        for _ in range(60):
            mid = (lo + hi) / 2
            if sum(p ** mid for p in ps) > 1:
                hi = mid
            else:
                lo = mid
        k = (lo + hi) / 2
        fair = [p ** k for p in ps]
    else:
        return 'invalid method'
    return ['%.4f' % x for x in fair]
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 multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power bracket update', (['3.67', '1.10'], 'power'), ['0.1360', '0.8640']),
  ('variant scenario 1', (['1.16', '6.38'], 'power'), ['0.8562', '0.1438']),
  ('variant scenario 2', (['2.05', '14.07', '2.09'], 'additive'), ['0.4754', '0.0586', '0.4660'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power bracket update',
   (['5.55', '2.14', '2.00'], 'power'),
   ['0.1375', '0.4144', '0.4482']),
  ('variant scenario 1',
   (['2.01', '2.51', '6.12', '10.10'], 'additive'),
   ['0.4579', '0.3588', '0.1238', '0.0594']),
  ('variant scenario 2', (['1.57', '1.97'], 'shin'), 'invalid method')],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power bracket update',
   (['6.44', '3.05', '2.57', '6.36'], 'power'),
   ['0.1488', '0.3196', '0.3808', '0.1507']),
  ('variant scenario 1',
   (['2.82', '5.29', '5.54', '2.56'], 'additive'),
   ['0.3259', '0.1603', '0.1518', '0.3619']),
  ('variant scenario 2', (['1.27', '11.62', '4.64'], 'shin'), 'invalid method')],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power bracket update',
   (['2.85', '3.58', '3.18', '8.34'], 'power'),
   ['0.3331', '0.2622', '0.2969', '0.1079']),
  ('variant scenario 1', (['1.68', '4.49', '3.51'], 'additive'), ['0.5610', '0.1884', '0.2506']),
  ('variant scenario 2', (['2.30', '1.48'], 'additive'), ['0.3796', '0.6204'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power bracket update',
   (['3.00', '5.62', '3.12', '2.96'], 'power'),
   ['0.2887', '0.1420', '0.2762', '0.2931']),
  ('variant scenario 1',
   (['2.72', '54.78', '4.16', '2.80', '6.54'], 'multiplicative'),
   ['0.3235', '0.0161', '0.2115', '0.3143', '0.1346']),
  ('variant scenario 2',
   (['4.03', '4.17', '5.00', '12.68', '4.10'], 'power'),
   ['0.2458', '0.2374', '0.1978', '0.0775', '0.2415'])]]
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

N = 1
observations = []
def solve(prices, method):
    ps = [1 / float(d) for d in prices]
    book = sum(ps)
    n = len(ps)
    if method == 'multiplicative':
        fair = [p / book for p in ps]
    elif method == 'additive':
        fair = [p - (book - 1) / n for p in ps]
        if any(x < 0 for x in fair):
            return 'additive infeasible'
    elif method == 'power':
        lo, hi = 0.0, 1.0
        for _ in range(60):
            mid = (lo + hi) / 2
            if sum(p ** mid for p in ps) > 1:
                lo = mid
            else:
                hi = mid
        k = (lo + hi) / 2
        fair = [p ** k for p in ps]
    else:
        return 'invalid method'
    return ['%.4f' % x for x in fair]
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 multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power bracket update', (['3.67', '1.10'], 'power'), ['0.1360', '0.8640']),
  ('variant scenario 1', (['1.16', '6.38'], 'power'), ['0.8562', '0.1438']),
  ('variant scenario 2', (['2.05', '14.07', '2.09'], 'additive'), ['0.4754', '0.0586', '0.4660'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power bracket update',
   (['5.55', '2.14', '2.00'], 'power'),
   ['0.1375', '0.4144', '0.4482']),
  ('variant scenario 1',
   (['2.01', '2.51', '6.12', '10.10'], 'additive'),
   ['0.4579', '0.3588', '0.1238', '0.0594']),
  ('variant scenario 2', (['1.57', '1.97'], 'shin'), 'invalid method')],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power bracket update',
   (['6.44', '3.05', '2.57', '6.36'], 'power'),
   ['0.1488', '0.3196', '0.3808', '0.1507']),
  ('variant scenario 1',
   (['2.82', '5.29', '5.54', '2.56'], 'additive'),
   ['0.3259', '0.1603', '0.1518', '0.3619']),
  ('variant scenario 2', (['1.27', '11.62', '4.64'], 'shin'), 'invalid method')],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power bracket update',
   (['2.85', '3.58', '3.18', '8.34'], 'power'),
   ['0.3331', '0.2622', '0.2969', '0.1079']),
  ('variant scenario 1', (['1.68', '4.49', '3.51'], 'additive'), ['0.5610', '0.1884', '0.2506']),
  ('variant scenario 2', (['2.30', '1.48'], 'additive'), ['0.3796', '0.6204'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power bracket update',
   (['3.00', '5.62', '3.12', '2.96'], 'power'),
   ['0.2887', '0.1420', '0.2762', '0.2931']),
  ('variant scenario 1',
   (['2.72', '54.78', '4.16', '2.80', '6.54'], 'multiplicative'),
   ['0.3235', '0.0161', '0.2115', '0.3143', '0.1346']),
  ('variant scenario 2',
   (['4.03', '4.17', '5.00', '12.68', '4.10'], 'power'),
   ['0.2458', '0.2374', '0.1978', '0.0775', '0.2415'])]]
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 power exponent converges to 1 or 10 and the fair probabilities do not sum to one.

Remove the bookmaker margin from decimal prices (implied p = 1/d, book = sum p > 1 assumed). multiplicative: p / book. additive: p - (book - 1) / n; if any result is negative return "additive infeasible". power: p ** k with k found by 60 bisection steps on [1, 10] so that the powered probabilities sum to 1 (k = midpoint of the final bracket). Any other method returns "invalid method". Return the fair probabilities formatted "%.4f".

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(prices, method):
    ps = [1 / float(d) for d in prices]
    book = sum(ps)
    n = len(ps)
    if method == 'multiplicative':
        fair = [p / book for p in ps]
    elif method == 'additive':
        fair = [p - (book - 1) / n for p in ps]
        if any(x < 0 for x in fair):
            return 'additive infeasible'
    elif method == 'power':
        lo, hi = 1.0, 10.0
        for _ in range(6):
            mid = (lo + hi) / 2
            if sum(p ** mid for p in ps) > 1:
                lo = mid
            else:
                hi = mid
        k = (lo + hi) / 2
        fair = [p ** k for p in ps]
    else:
        return 'invalid method'
    return ['%.4f' % x for x in fair]
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 multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power iterations',
   (['2.25', '2.59', '6.02', '4.98'], 'power'),
   ['0.3898', '0.3310', '0.1243', '0.1549']),
  ('variant scenario 1', (['2.21', '5.97', '5.73', '4.37'], 'shin'), 'invalid method'),
  ('variant scenario 2',
   (['5.60', '2.48', '3.06', '8.98', '6.08'], 'power'),
   ['0.1432', '0.3590', '0.2832', '0.0841', '0.1305'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power iterations', (['2.08', '1.53'], 'power'), ['0.4068', '0.5932']),
  ('variant scenario 1', (['1.73', '1.75'], 'additive'), ['0.5033', '0.4967']),
  ('variant scenario 2', (['4.18', '3.37', '21.01', '1.64'], 'shin'), 'invalid method')],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power iterations',
   (['4.47', '4.38', '6.81', '5.54', '4.19'], 'power'),
   ['0.2199', '0.2245', '0.1437', '0.1770', '0.2348']),
  ('variant scenario 1', (['7.72', '1.13'], 'additive'), ['0.1223', '0.8777']),
  ('variant scenario 2', (['3.94', '3.80', '3.70', '27.86', '3.84'], 'shin'), 'invalid method')],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power iterations',
   (['4.42', '5.10', '2.85', '2.90', '22.13'], 'power'),
   ['0.1905', '0.1624', '0.3108', '0.3048', '0.0316']),
  ('variant scenario 1', (['2.69', '6.86', '1.50'], 'shin'), 'invalid method'),
  ('variant scenario 2', (['7.14', '1.15'], 'additive'), ['0.1352', '0.8648'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power iterations',
   (['1.71', '10.88', '2.39'], 'power'),
   ['0.5505', '0.0702', '0.3793']),
  ('variant scenario 1',
   (['5.00', '2.76', '7.09', '5.56', '4.51'], 'additive'),
   ['0.1790', '0.3413', '0.1201', '0.1589', '0.2007']),
  ('variant scenario 2', (['4.59', '2.91', '1.91'], 'power'), ['0.1912', '0.3136', '0.4953'])]]
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

N = 1
observations = []
def solve(prices, method):
    ps = [1 / float(d) for d in prices]
    book = sum(ps)
    n = len(ps)
    if method == 'multiplicative':
        fair = [p / book for p in ps]
    elif method == 'additive':
        fair = [p - (book - 1) / n for p in ps]
        if any(x < 0 for x in fair):
            return 'additive infeasible'
    elif method == 'power':
        lo, hi = 1.0, 10.0
        for _ in range(12):
            mid = (lo + hi) / 2
            if sum(p ** mid for p in ps) > 1:
                lo = mid
            else:
                hi = mid
        k = (lo + hi) / 2
        fair = [p ** k for p in ps]
    else:
        return 'invalid method'
    return ['%.4f' % x for x in fair]
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 multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power iterations',
   (['2.25', '2.59', '6.02', '4.98'], 'power'),
   ['0.3898', '0.3310', '0.1243', '0.1549']),
  ('variant scenario 1', (['2.21', '5.97', '5.73', '4.37'], 'shin'), 'invalid method'),
  ('variant scenario 2',
   (['5.60', '2.48', '3.06', '8.98', '6.08'], 'power'),
   ['0.1432', '0.3590', '0.2832', '0.0841', '0.1305'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power iterations', (['2.08', '1.53'], 'power'), ['0.4068', '0.5932']),
  ('variant scenario 1', (['1.73', '1.75'], 'additive'), ['0.5033', '0.4967']),
  ('variant scenario 2', (['4.18', '3.37', '21.01', '1.64'], 'shin'), 'invalid method')],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power iterations',
   (['4.47', '4.38', '6.81', '5.54', '4.19'], 'power'),
   ['0.2199', '0.2245', '0.1437', '0.1770', '0.2348']),
  ('variant scenario 1', (['7.72', '1.13'], 'additive'), ['0.1223', '0.8777']),
  ('variant scenario 2', (['3.94', '3.80', '3.70', '27.86', '3.84'], 'shin'), 'invalid method')],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power iterations',
   (['4.42', '5.10', '2.85', '2.90', '22.13'], 'power'),
   ['0.1905', '0.1624', '0.3108', '0.3048', '0.0316']),
  ('variant scenario 1', (['2.69', '6.86', '1.50'], 'shin'), 'invalid method'),
  ('variant scenario 2', (['7.14', '1.15'], 'additive'), ['0.1352', '0.8648'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: power iterations',
   (['1.71', '10.88', '2.39'], 'power'),
   ['0.5505', '0.0702', '0.3793']),
  ('variant scenario 1',
   (['5.00', '2.76', '7.09', '5.56', '4.51'], 'additive'),
   ['0.1790', '0.3413', '0.1201', '0.1589', '0.2007']),
  ('variant scenario 2', (['4.59', '2.91', '1.91'], 'power'), ['0.1912', '0.3136', '0.4953'])]]
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:
Power-method fair probabilities are off in the third or fourth decimal.

Remove the bookmaker margin from decimal prices (implied p = 1/d, book = sum p > 1 assumed). multiplicative: p / book. additive: p - (book - 1) / n; if any result is negative return "additive infeasible". power: p ** k with k found by 60 bisection steps on [1, 10] so that the powered probabilities sum to 1 (k = midpoint of the final bracket). Any other method returns "invalid method". Return the fair probabilities formatted "%.4f".

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(prices, method):
    ps = [1 / float(d) for d in prices]
    book = sum(ps)
    n = len(ps)
    if method == 'multiplicative':
        fair = [p / book for p in ps]
    elif method == 'additive':
        fair = [p - (book - 1) / n for p in ps]
    elif method == 'power':
        lo, hi = 1.0, 10.0
        for _ in range(60):
            mid = (lo + hi) / 2
            if sum(p ** mid for p in ps) > 1:
                lo = mid
            else:
                hi = mid
        k = (lo + hi) / 2
        fair = [p ** k for p in ps]
    else:
        return 'invalid method'
    return ['%.4f' % x for x in fair]
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 multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive feasibility',
   (['3.86', '4.27', '33.20', '1.56', '33.31'], 'additive'),
   'additive infeasible'),
  ('variant scenario 1',
   (['1.86', '53.99', '2.05'], 'multiplicative'),
   ['0.5150', '0.0177', '0.4673']),
  ('variant scenario 2',
   (['13.07', '7.90', '2.08', '2.47'], 'additive'),
   ['0.0543', '0.1044', '0.4586', '0.3827'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive feasibility',
   (['1.49', '2.27', '23.29'], 'additive'),
   'additive infeasible'),
  ('variant scenario 1', (['2.67', '1.32'], 'additive'), ['0.3085', '0.6915']),
  ('variant scenario 2',
   (['5.54', '5.02', '7.65', '3.05', '4.02'], 'power'),
   ['0.1639', '0.1818', '0.1165', '0.3078', '0.2299'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive feasibility',
   (['2.82', '46.21', '2.73', '2.34'], 'additive'),
   'additive infeasible'),
  ('variant scenario 1',
   (['2.03', '5.34', '4.26', '6.91'], 'power'),
   ['0.4762', '0.1728', '0.2190', '0.1319']),
  ('variant scenario 2', (['1.74', '2.07'], 'additive'), ['0.5458', '0.4542'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive feasibility',
   (['29.25', '11.46', '1.90', '1.91'], 'additive'),
   'additive infeasible'),
  ('variant scenario 1',
   (['4.98', '2.95', '43.55', '3.16', '6.92'], 'multiplicative'),
   ['0.1962', '0.3311', '0.0224', '0.3091', '0.1412']),
  ('variant scenario 2',
   (['4.10', '6.43', '3.04', '2.92'], 'additive'),
   ['0.2262', '0.1378', '0.3112', '0.3248'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive feasibility',
   (['35.15', '1.83', '1.71'], 'additive'),
   'additive infeasible'),
  ('variant scenario 1', (['14.47', '1.05'], 'power'), ['0.0524', '0.9476']),
  ('variant scenario 2',
   (['5.70', '3.60', '5.75', '5.69', '2.89'], 'power'),
   ['0.1480', '0.2451', '0.1466', '0.1483', '0.3120'])]]
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

N = 1
observations = []
def solve(prices, method):
    ps = [1 / float(d) for d in prices]
    book = sum(ps)
    n = len(ps)
    if method == 'multiplicative':
        fair = [p / book for p in ps]
    elif method == 'additive':
        fair = [p - (book - 1) / n for p in ps]
        fair = [max(0.0, x) for x in fair]
    elif method == 'power':
        lo, hi = 1.0, 10.0
        for _ in range(60):
            mid = (lo + hi) / 2
            if sum(p ** mid for p in ps) > 1:
                lo = mid
            else:
                hi = mid
        k = (lo + hi) / 2
        fair = [p ** k for p in ps]
    else:
        return 'invalid method'
    return ['%.4f' % x for x in fair]
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 multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive feasibility',
   (['3.86', '4.27', '33.20', '1.56', '33.31'], 'additive'),
   'additive infeasible'),
  ('variant scenario 1',
   (['1.86', '53.99', '2.05'], 'multiplicative'),
   ['0.5150', '0.0177', '0.4673']),
  ('variant scenario 2',
   (['13.07', '7.90', '2.08', '2.47'], 'additive'),
   ['0.0543', '0.1044', '0.4586', '0.3827'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive feasibility',
   (['1.49', '2.27', '23.29'], 'additive'),
   'additive infeasible'),
  ('variant scenario 1', (['2.67', '1.32'], 'additive'), ['0.3085', '0.6915']),
  ('variant scenario 2',
   (['5.54', '5.02', '7.65', '3.05', '4.02'], 'power'),
   ['0.1639', '0.1818', '0.1165', '0.3078', '0.2299'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive feasibility',
   (['2.82', '46.21', '2.73', '2.34'], 'additive'),
   'additive infeasible'),
  ('variant scenario 1',
   (['2.03', '5.34', '4.26', '6.91'], 'power'),
   ['0.4762', '0.1728', '0.2190', '0.1319']),
  ('variant scenario 2', (['1.74', '2.07'], 'additive'), ['0.5458', '0.4542'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive feasibility',
   (['29.25', '11.46', '1.90', '1.91'], 'additive'),
   'additive infeasible'),
  ('variant scenario 1',
   (['4.98', '2.95', '43.55', '3.16', '6.92'], 'multiplicative'),
   ['0.1962', '0.3311', '0.0224', '0.3091', '0.1412']),
  ('variant scenario 2',
   (['4.10', '6.43', '3.04', '2.92'], 'additive'),
   ['0.2262', '0.1378', '0.3112', '0.3248'])],
 [('control multiplicative', (['1.80', '2.00'], 'multiplicative'), ['0.5263', '0.4737']),
  ('control additive', (['1.80', '2.00'], 'additive'), ['0.5278', '0.4722']),
  ('control power', (['1.80', '2.00'], 'power'), ['0.5285', '0.4715']),
  ('boundary additive longshot',
   (['1.01', '15.00', '100.00', '100.00'], 'additive'),
   'additive infeasible'),
  ('boundary unknown method', (['1.80', '2.00'], 'shin'), 'invalid method'),
  ('regression: additive feasibility',
   (['35.15', '1.83', '1.71'], 'additive'),
   'additive infeasible'),
  ('variant scenario 1', (['14.47', '1.05'], 'power'), ['0.0524', '0.9476']),
  ('variant scenario 2',
   (['5.70', '3.60', '5.75', '5.69', '2.89'], 'power'),
   ['0.1480', '0.2451', '0.1466', '0.1483', '0.3120'])]]
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 heavy longshot receives a negative or zero fair probability.

Remove the bookmaker margin from decimal prices (implied p = 1/d, book = sum p > 1 assumed). multiplicative: p / book. additive: p - (book - 1) / n; if any result is negative return "additive infeasible". power: p ** k with k found by 60 bisection steps on [1, 10] so that the powered probabilities sum to 1 (k = midpoint of the final bracket). Any other method returns "invalid method". Return the fair probabilities formatted "%.4f".

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(decimal, style):
    def fmt(x):
        sign = '-' if x < 0 else ''
        c = math.floor(abs(x) * 100 + Fraction(1, 2))
        return sign + '%d.%02d' % (c // 100, c % 100)
    d = Fraction(decimal)
    if d <= 1:
        return 'invalid'
    if style == 'hk':
        v = d - 1
    elif style == 'malay':
        v = d - 1 if d < 2 else -1 / (d - 1)
    elif style == 'indo':
        v = d - 1 if d >= 2 else -1 / (d - 1)
    else:
        return 'invalid style'
    return fmt(v)
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 hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay evens branch', ('2.00', 'malay'), '1.00'),
  ('regression: malay evens branch', ('2.01', 'malay'), '-0.99'),
  ('variant scenario 1', ('3.58', 'indo'), '2.58'),
  ('variant scenario 2', ('1.80', 'malay'), '0.80')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay evens branch', ('2.00', 'malay'), '1.00'),
  ('regression: malay evens branch', ('2.005', 'malay'), '-1.00'),
  ('variant scenario 1', ('1.25', 'malay'), '0.25'),
  ('variant scenario 2', ('9.00', 'indo'), '8.00')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay evens branch', ('2.00', 'malay'), '1.00'),
  ('regression: malay evens branch', ('2.005', 'malay'), '-1.00'),
  ('variant scenario 1', ('1.00', 'us'), 'invalid'),
  ('variant scenario 2', ('2.25', 'malay'), '-0.80')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay evens branch', ('2.00', 'malay'), '1.00'),
  ('regression: malay evens branch', ('2.01', 'malay'), '-0.99'),
  ('variant scenario 1', ('2.00', 'indo'), '1.00'),
  ('variant scenario 2', ('1.00', 'us'), 'invalid')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay evens branch', ('2.00', 'malay'), '1.00'),
  ('regression: malay evens branch', ('2.005', 'malay'), '-1.00'),
  ('variant scenario 1', ('2.77', 'us'), 'invalid style'),
  ('variant scenario 2', ('2.04', 'us'), 'invalid style')]]
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(decimal, style):
    def fmt(x):
        sign = '-' if x < 0 else ''
        c = math.floor(abs(x) * 100 + Fraction(1, 2))
        return sign + '%d.%02d' % (c // 100, c % 100)
    d = Fraction(decimal)
    if d <= 1:
        return 'invalid'
    if style == 'hk':
        v = d - 1
    elif style == 'malay':
        v = d - 1 if d <= Fraction(201, 100) else -1 / (d - 1)
    elif style == 'indo':
        v = d - 1 if d >= 2 else -1 / (d - 1)
    else:
        return 'invalid style'
    return fmt(v)
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 hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay evens branch', ('2.00', 'malay'), '1.00'),
  ('regression: malay evens branch', ('2.01', 'malay'), '-0.99'),
  ('variant scenario 1', ('3.58', 'indo'), '2.58'),
  ('variant scenario 2', ('1.80', 'malay'), '0.80')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay evens branch', ('2.00', 'malay'), '1.00'),
  ('regression: malay evens branch', ('2.005', 'malay'), '-1.00'),
  ('variant scenario 1', ('1.25', 'malay'), '0.25'),
  ('variant scenario 2', ('9.00', 'indo'), '8.00')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay evens branch', ('2.00', 'malay'), '1.00'),
  ('regression: malay evens branch', ('2.005', 'malay'), '-1.00'),
  ('variant scenario 1', ('1.00', 'us'), 'invalid'),
  ('variant scenario 2', ('2.25', 'malay'), '-0.80')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay evens branch', ('2.00', 'malay'), '1.00'),
  ('regression: malay evens branch', ('2.01', 'malay'), '-0.99'),
  ('variant scenario 1', ('2.00', 'indo'), '1.00'),
  ('variant scenario 2', ('1.00', 'us'), 'invalid')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay evens branch', ('2.00', 'malay'), '1.00'),
  ('regression: malay evens branch', ('2.005', 'malay'), '-1.00'),
  ('variant scenario 1', ('2.77', 'us'), 'invalid style'),
  ('variant scenario 2', ('2.04', 'us'), 'invalid style')]]
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.00 decimal price is shown as -1.00 in Malay format.

Convert a decimal price (> 1, else "invalid") to an Asian odds style. hk: d - 1. malay: d - 1 when d <= 2, else -1 / (d - 1). indo: d - 1 when d >= 2, else -1 / (d - 1). Other styles return "invalid style". Values are rounded half away from zero to two decimals and formatted with a leading "-" for negatives.

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(decimal, style):
    def fmt(x):
        sign = '-' if x < 0 else ''
        c = math.floor(abs(x) * 100 + Fraction(1, 2))
        return sign + '%d.%02d' % (c // 100, c % 100)
    d = Fraction(decimal)
    if d <= 1:
        return 'invalid'
    if style == 'hk':
        v = d - 1
    elif style == 'malay':
        v = d - 1 if d <= 2 else -(d - 1)
    elif style == 'indo':
        v = d - 1 if d >= 2 else -1 / (d - 1)
    else:
        return 'invalid style'
    return fmt(v)
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 hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay negative formula', ('2.25', 'malay'), '-0.80'),
  ('variant scenario 1', ('1.620', 'indo'), '-1.61'),
  ('variant scenario 2', ('1.679', 'indo'), '-1.47')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay negative formula', ('2.40', 'malay'), '-0.71'),
  ('variant scenario 1', ('1.00', 'us'), 'invalid'),
  ('variant scenario 2', ('1.80', 'indo'), '-1.25')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay negative formula', ('9.00', 'malay'), '-0.13'),
  ('variant scenario 1', ('9.00', 'us'), 'invalid style'),
  ('variant scenario 2', ('9.00', 'indo'), '8.00')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay negative formula', ('2.25', 'malay'), '-0.80'),
  ('variant scenario 1', ('9.00', 'indo'), '8.00'),
  ('variant scenario 2', ('1.00', 'malay'), 'invalid')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay negative formula', ('2.399', 'malay'), '-0.71'),
  ('variant scenario 1', ('1.80', 'indo'), '-1.25'),
  ('variant scenario 2', ('1.80', 'malay'), '0.80')]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(decimal, style):
    def fmt(x):
        sign = '-' if x < 0 else ''
        c = math.floor(abs(x) * 100 + Fraction(1, 2))
        return sign + '%d.%02d' % (c // 100, c % 100)
    d = Fraction(decimal)
    if d <= 1:
        return 'invalid'
    if style == 'hk':
        v = d - 1
    elif style == 'malay':
        v = d - 1 if d <= 2 else -1 / d
    elif style == 'indo':
        v = d - 1 if d >= 2 else -1 / (d - 1)
    else:
        return 'invalid style'
    return fmt(v)
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 hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay negative formula', ('2.25', 'malay'), '-0.80'),
  ('variant scenario 1', ('1.620', 'indo'), '-1.61'),
  ('variant scenario 2', ('1.679', 'indo'), '-1.47')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay negative formula', ('2.40', 'malay'), '-0.71'),
  ('variant scenario 1', ('1.00', 'us'), 'invalid'),
  ('variant scenario 2', ('1.80', 'indo'), '-1.25')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay negative formula', ('9.00', 'malay'), '-0.13'),
  ('variant scenario 1', ('9.00', 'us'), 'invalid style'),
  ('variant scenario 2', ('9.00', 'indo'), '8.00')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay negative formula', ('2.25', 'malay'), '-0.80'),
  ('variant scenario 1', ('9.00', 'indo'), '8.00'),
  ('variant scenario 2', ('1.00', 'malay'), 'invalid')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: malay negative formula', ('2.399', 'malay'), '-0.71'),
  ('variant scenario 1', ('1.80', 'indo'), '-1.25'),
  ('variant scenario 2', ('1.80', 'malay'), '0.80')]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A 2.25 price shows -1.25 instead of -0.80 in Malay format.

Convert a decimal price (> 1, else "invalid") to an Asian odds style. hk: d - 1. malay: d - 1 when d <= 2, else -1 / (d - 1). indo: d - 1 when d >= 2, else -1 / (d - 1). Other styles return "invalid style". Values are rounded half away from zero to two decimals and formatted with a leading "-" for negatives.

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(decimal, style):
    def fmt(x):
        c = math.floor(x * 100 + Fraction(1, 2))
        return '%d.%02d' % (c // 100, c % 100)
    d = Fraction(decimal)
    if d <= 1:
        return 'invalid'
    if style == 'hk':
        v = d - 1
    elif style == 'malay':
        v = d - 1 if d <= 2 else -1 / (d - 1)
    elif style == 'indo':
        v = d - 1 if d >= 2 else -1 / (d - 1)
    else:
        return 'invalid style'
    return fmt(v)
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 hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: negative rounding', ('2.25', 'malay'), '-0.80'),
  ('regression: negative rounding', ('9.00', 'malay'), '-0.13'),
  ('variant scenario 1', ('1.80', 'malay'), '0.80'),
  ('variant scenario 2', ('9.00', 'indo'), '8.00')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: negative rounding', ('9.00', 'malay'), '-0.13'),
  ('variant scenario 1', ('1.00', 'malay'), 'invalid'),
  ('variant scenario 2', ('2.25', 'us'), 'invalid style')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: negative rounding', ('1.75', 'indo'), '-1.33'),
  ('regression: negative rounding', ('9.00', 'malay'), '-0.13'),
  ('variant scenario 1', ('2.00', 'indo'), '1.00'),
  ('variant scenario 2', ('1.919', 'hk'), '0.92')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: negative rounding', ('3.64', 'malay'), '-0.38'),
  ('regression: negative rounding', ('9.00', 'malay'), '-0.13'),
  ('variant scenario 1', ('9.00', 'hk'), '8.00'),
  ('variant scenario 2', ('9.00', 'us'), 'invalid style')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: negative rounding', ('2.665', 'malay'), '-0.60'),
  ('regression: negative rounding', ('9.00', 'malay'), '-0.13'),
  ('variant scenario 1', ('1.00', 'indo'), 'invalid'),
  ('variant scenario 2', ('1.80', 'hk'), '0.80')]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(decimal, style):
    def fmt(x):
        sign = '-' if x < 0 else ''
        c = round(abs(x) * 100)
        return sign + '%d.%02d' % (c // 100, c % 100)
    d = Fraction(decimal)
    if d <= 1:
        return 'invalid'
    if style == 'hk':
        v = d - 1
    elif style == 'malay':
        v = d - 1 if d <= 2 else -1 / (d - 1)
    elif style == 'indo':
        v = d - 1 if d >= 2 else -1 / (d - 1)
    else:
        return 'invalid style'
    return fmt(v)
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 hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: negative rounding', ('2.25', 'malay'), '-0.80'),
  ('regression: negative rounding', ('9.00', 'malay'), '-0.13'),
  ('variant scenario 1', ('1.80', 'malay'), '0.80'),
  ('variant scenario 2', ('9.00', 'indo'), '8.00')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: negative rounding', ('9.00', 'malay'), '-0.13'),
  ('variant scenario 1', ('1.00', 'malay'), 'invalid'),
  ('variant scenario 2', ('2.25', 'us'), 'invalid style')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: negative rounding', ('1.75', 'indo'), '-1.33'),
  ('regression: negative rounding', ('9.00', 'malay'), '-0.13'),
  ('variant scenario 1', ('2.00', 'indo'), '1.00'),
  ('variant scenario 2', ('1.919', 'hk'), '0.92')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: negative rounding', ('3.64', 'malay'), '-0.38'),
  ('regression: negative rounding', ('9.00', 'malay'), '-0.13'),
  ('variant scenario 1', ('9.00', 'hk'), '8.00'),
  ('variant scenario 2', ('9.00', 'us'), 'invalid style')],
 [('control hong kong', ('1.85', 'hk'), '0.85'),
  ('control malay positive', ('1.80', 'malay'), '0.80'),
  ('control malay negative', ('2.25', 'malay'), '-0.80'),
  ('boundary malay evens', ('2.00', 'malay'), '1.00'),
  ('control indo negative', ('1.80', 'indo'), '-1.25'),
  ('boundary indo half rounds away', ('9.00', 'malay'), '-0.13'),
  ('regression: negative rounding', ('2.665', 'malay'), '-0.60'),
  ('regression: negative rounding', ('9.00', 'malay'), '-0.13'),
  ('variant scenario 1', ('1.00', 'indo'), 'invalid'),
  ('variant scenario 2', ('1.80', 'hk'), '0.80')]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A -0.125 Malay price shows "-1.88" or "-0.12" instead of "-0.13".

Convert a decimal price (> 1, else "invalid") to an Asian odds style. hk: d - 1. malay: d - 1 when d <= 2, else -1 / (d - 1). indo: d - 1 when d >= 2, else -1 / (d - 1). Other styles return "invalid style". Values are rounded half away from zero to two decimals and formatted with a leading "-" for negatives.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(legs, stake_cents):
    factor = Fraction(1)
    for price, result in legs:
        d = Fraction(price)
        if result in ('lose', 'push'):
            factor = Fraction(0)
            break
        if result == 'win':
            factor *= d
        elif result == 'half-win':
            factor *= (1 + d) / 2
        elif result == 'half-lose':
            factor *= Fraction(1, 2)
    q = math.floor(factor * 10000 + Fraction(1, 2))
    return ['%d.%04d' % (q // 10000, q % 10000), math.floor(stake_cents * factor)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: push leg factor',
   ([['2.02', 'win'], ['3.91', 'push'], ['3.42', 'half-win']], 1999),
   ['4.4642', 8923]),
  ('variant scenario 1',
   ([['2.72', 'void'], ['3.99', 'win'], ['2.58', 'half-win'], ['2.13', 'win']], 333),
   ['15.2127', 5065]),
  ('variant scenario 2', ([['1.93', 'win'], ['2.74', 'half-lose']], 333), ['0.9650', 321])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: push leg factor',
   ([['3.97', 'half-win'], ['2.47', 'push'], ['3.54', 'push'], ['2.82', 'push']], 1999),
   ['2.4850', 4967]),
  ('variant scenario 1',
   ([['3.53', 'win'], ['3.05', 'lose'], ['3.20', 'lose']], 1999),
   ['0.0000', 0]),
  ('variant scenario 2', ([['1.56', 'win'], ['1.40', 'half-win']], 1000), ['1.8720', 1872])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: push leg factor',
   ([['3.05', 'push'], ['1.88', 'win'], ['2.45', 'win'], ['2.97', 'win'], ['3.27', 'win']], 1000),
   ['44.7330', 44733]),
  ('variant scenario 1',
   ([['3.22', 'push'], ['1.43', 'half-lose'], ['1.82', 'lose'], ['3.41', 'win']], 1000),
   ['0.0000', 0]),
  ('variant scenario 2',
   ([['2.42', 'win'], ['1.45', 'void'], ['2.68', 'lose'], ['1.68', 'void'], ['1.92', 'win']], 100),
   ['0.0000', 0])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: push leg factor',
   ([['2.62', 'push'], ['1.90', 'void'], ['2.00', 'win'], ['1.86', 'win']], 1999),
   ['3.7200', 7436]),
  ('variant scenario 1',
   ([['3.37', 'win'],
     ['1.36', 'half-lose'],
     ['2.40', 'half-lose'],
     ['1.81', 'win'],
     ['2.31', 'half-win']],
    333),
   ['2.5238', 840]),
  ('variant scenario 2', ([['3.23', 'win'], ['1.87', 'win']], 333), ['6.0401', 2011])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: push leg factor',
   ([['2.00', 'push'], ['1.86', 'half-win'], ['3.31', 'win'], ['2.46', 'half-lose']], 1999),
   ['2.3667', 4730]),
  ('variant scenario 1',
   ([['3.66', 'half-lose'], ['1.36', 'win'], ['3.09', 'win'], ['1.39', 'win'], ['3.11', 'win']],
    1000),
   ['9.0833', 9083]),
  ('variant scenario 2',
   ([['2.28', 'void'], ['1.44', 'half-lose'], ['3.81', 'push'], ['2.38', 'void']], 100),
   ['0.5000', 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(legs, stake_cents):
    factor = Fraction(1)
    for price, result in legs:
        d = Fraction(price)
        if result == 'lose':
            factor = Fraction(0)
            break
        if result in ('win', 'push'):
            factor *= d
        elif result == 'half-win':
            factor *= (1 + d) / 2
        elif result == 'half-lose':
            factor *= Fraction(1, 2)
    q = math.floor(factor * 10000 + Fraction(1, 2))
    return ['%d.%04d' % (q // 10000, q % 10000), math.floor(stake_cents * factor)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: push leg factor',
   ([['2.02', 'win'], ['3.91', 'push'], ['3.42', 'half-win']], 1999),
   ['4.4642', 8923]),
  ('variant scenario 1',
   ([['2.72', 'void'], ['3.99', 'win'], ['2.58', 'half-win'], ['2.13', 'win']], 333),
   ['15.2127', 5065]),
  ('variant scenario 2', ([['1.93', 'win'], ['2.74', 'half-lose']], 333), ['0.9650', 321])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: push leg factor',
   ([['3.97', 'half-win'], ['2.47', 'push'], ['3.54', 'push'], ['2.82', 'push']], 1999),
   ['2.4850', 4967]),
  ('variant scenario 1',
   ([['3.53', 'win'], ['3.05', 'lose'], ['3.20', 'lose']], 1999),
   ['0.0000', 0]),
  ('variant scenario 2', ([['1.56', 'win'], ['1.40', 'half-win']], 1000), ['1.8720', 1872])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: push leg factor',
   ([['3.05', 'push'], ['1.88', 'win'], ['2.45', 'win'], ['2.97', 'win'], ['3.27', 'win']], 1000),
   ['44.7330', 44733]),
  ('variant scenario 1',
   ([['3.22', 'push'], ['1.43', 'half-lose'], ['1.82', 'lose'], ['3.41', 'win']], 1000),
   ['0.0000', 0]),
  ('variant scenario 2',
   ([['2.42', 'win'], ['1.45', 'void'], ['2.68', 'lose'], ['1.68', 'void'], ['1.92', 'win']], 100),
   ['0.0000', 0])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: push leg factor',
   ([['2.62', 'push'], ['1.90', 'void'], ['2.00', 'win'], ['1.86', 'win']], 1999),
   ['3.7200', 7436]),
  ('variant scenario 1',
   ([['3.37', 'win'],
     ['1.36', 'half-lose'],
     ['2.40', 'half-lose'],
     ['1.81', 'win'],
     ['2.31', 'half-win']],
    333),
   ['2.5238', 840]),
  ('variant scenario 2', ([['3.23', 'win'], ['1.87', 'win']], 333), ['6.0401', 2011])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: push leg factor',
   ([['2.00', 'push'], ['1.86', 'half-win'], ['3.31', 'win'], ['2.46', 'half-lose']], 1999),
   ['2.3667', 4730]),
  ('variant scenario 1',
   ([['3.66', 'half-lose'], ['1.36', 'win'], ['3.09', 'win'], ['1.39', 'win'], ['3.11', 'win']],
    1000),
   ['9.0833', 9083]),
  ('variant scenario 2',
   ([['2.28', 'void'], ['1.44', 'half-lose'], ['3.81', 'push'], ['2.38', 'void']], 100),
   ['0.5000', 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 parlay with a pushed leg pays nothing, or pays as if the push had won.

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

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(legs, stake_cents):
    factor = Fraction(1)
    for price, result in legs:
        d = Fraction(price)
        if result == 'lose':
            factor = Fraction(0)
            break
        if result == 'win':
            factor *= d
        elif result == 'half-win':
            factor *= d
        elif result == 'half-lose':
            factor *= Fraction(1, 2)
    q = math.floor(factor * 10000 + Fraction(1, 2))
    return ['%d.%04d' % (q // 10000, q % 10000), math.floor(stake_cents * factor)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half win factor',
   ([['2.35', 'win'], ['1.77', 'void'], ['1.28', 'half-lose'], ['3.07', 'half-win']], 1000),
   ['2.3911', 2391]),
  ('variant scenario 1',
   ([['2.04', 'half-win'],
     ['1.30', 'half-win'],
     ['2.75', 'win'],
     ['2.56', 'half-lose'],
     ['3.90', 'lose']],
    1999),
   ['0.0000', 0]),
  ('variant scenario 2', ([['3.10', 'win'], ['2.58', 'void']], 100), ['3.1000', 310])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half win factor',
   ([['2.78', 'win'],
     ['3.36', 'half-lose'],
     ['1.51', 'half-win'],
     ['1.53', 'win'],
     ['2.82', 'win']],
    333),
   ['7.5266', 2506]),
  ('variant scenario 1',
   ([['1.69', 'win'], ['3.30', 'win'], ['1.27', 'win'], ['2.88', 'half-lose'], ['3.75', 'push']],
    1000),
   ['3.5414', 3541]),
  ('variant scenario 2', ([['3.90', 'win'], ['2.38', 'half-lose']], 1000), ['1.9500', 1950])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half win factor',
   ([['3.66', 'push'],
     ['1.61', 'half-lose'],
     ['3.40', 'half-win'],
     ['2.67', 'half-win'],
     ['2.27', 'half-win']],
    250),
   ['3.3002', 825]),
  ('variant scenario 1',
   ([['1.64', 'void'], ['1.40', 'lose'], ['2.39', 'half-lose']], 333),
   ['0.0000', 0]),
  ('variant scenario 2',
   ([['1.78', 'push'], ['1.46', 'half-lose'], ['2.49', 'win']], 333),
   ['1.2450', 414])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half win factor',
   ([['3.26', 'void'], ['3.52', 'half-win'], ['2.05', 'half-lose'], ['3.79', 'void']], 100),
   ['1.1300', 113]),
  ('variant scenario 1',
   ([['1.32', 'win'], ['2.63', 'push'], ['1.31', 'void'], ['1.97', 'win'], ['2.37', 'win']], 333),
   ['6.1629', 2052]),
  ('variant scenario 2',
   ([['1.29', 'void'], ['1.56', 'half-lose'], ['2.62', 'win'], ['1.98', 'void'], ['2.10', 'win']],
    333),
   ['2.7510', 916])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half win factor',
   ([['2.90', 'half-lose'],
     ['2.13', 'win'],
     ['2.30', 'half-win'],
     ['1.23', 'half-win'],
     ['1.38', 'win']],
    100),
   ['2.7039', 270]),
  ('variant scenario 1',
   ([['3.43', 'void'], ['1.58', 'win'], ['1.37', 'push'], ['3.02', 'win'], ['3.24', 'win']], 100),
   ['15.4600', 1545]),
  ('variant scenario 2', ([['3.08', 'win'], ['3.61', 'void']], 333), ['3.0800', 1025])]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(legs, stake_cents):
    factor = Fraction(1)
    for price, result in legs:
        d = Fraction(price)
        if result == 'lose':
            factor = Fraction(0)
            break
        if result == 'win':
            factor *= d
        elif result == 'half-win':
            factor *= d / 2
        elif result == 'half-lose':
            factor *= Fraction(1, 2)
    q = math.floor(factor * 10000 + Fraction(1, 2))
    return ['%d.%04d' % (q // 10000, q % 10000), math.floor(stake_cents * factor)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half win factor',
   ([['2.35', 'win'], ['1.77', 'void'], ['1.28', 'half-lose'], ['3.07', 'half-win']], 1000),
   ['2.3911', 2391]),
  ('variant scenario 1',
   ([['2.04', 'half-win'],
     ['1.30', 'half-win'],
     ['2.75', 'win'],
     ['2.56', 'half-lose'],
     ['3.90', 'lose']],
    1999),
   ['0.0000', 0]),
  ('variant scenario 2', ([['3.10', 'win'], ['2.58', 'void']], 100), ['3.1000', 310])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half win factor',
   ([['2.78', 'win'],
     ['3.36', 'half-lose'],
     ['1.51', 'half-win'],
     ['1.53', 'win'],
     ['2.82', 'win']],
    333),
   ['7.5266', 2506]),
  ('variant scenario 1',
   ([['1.69', 'win'], ['3.30', 'win'], ['1.27', 'win'], ['2.88', 'half-lose'], ['3.75', 'push']],
    1000),
   ['3.5414', 3541]),
  ('variant scenario 2', ([['3.90', 'win'], ['2.38', 'half-lose']], 1000), ['1.9500', 1950])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half win factor',
   ([['3.66', 'push'],
     ['1.61', 'half-lose'],
     ['3.40', 'half-win'],
     ['2.67', 'half-win'],
     ['2.27', 'half-win']],
    250),
   ['3.3002', 825]),
  ('variant scenario 1',
   ([['1.64', 'void'], ['1.40', 'lose'], ['2.39', 'half-lose']], 333),
   ['0.0000', 0]),
  ('variant scenario 2',
   ([['1.78', 'push'], ['1.46', 'half-lose'], ['2.49', 'win']], 333),
   ['1.2450', 414])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half win factor',
   ([['3.26', 'void'], ['3.52', 'half-win'], ['2.05', 'half-lose'], ['3.79', 'void']], 100),
   ['1.1300', 113]),
  ('variant scenario 1',
   ([['1.32', 'win'], ['2.63', 'push'], ['1.31', 'void'], ['1.97', 'win'], ['2.37', 'win']], 333),
   ['6.1629', 2052]),
  ('variant scenario 2',
   ([['1.29', 'void'], ['1.56', 'half-lose'], ['2.62', 'win'], ['1.98', 'void'], ['2.10', 'win']],
    333),
   ['2.7510', 916])],
 [('control two winners', ([['2.00', 'win'], ['1.50', 'win']], 1000), ['3.0000', 3000]),
  ('boundary pushed leg', ([['2.00', 'win'], ['1.90', 'push']], 1000), ['2.0000', 2000]),
  ('boundary half-win leg', ([['2.00', 'half-win'], ['2.00', 'win']], 1000), ['3.0000', 3000]),
  ('boundary half-lose leg', ([['2.00', 'half-lose'], ['3.00', 'win']], 1000), ['1.5000', 1500]),
  ('control losing leg', ([['2.00', 'win'], ['1.50', 'lose']], 1000), ['0.0000', 0]),
  ('control payout rounds down', ([['1.33', 'win']], 333), ['1.3300', 442]),
  ('regression: half win factor',
   ([['2.90', 'half-lose'],
     ['2.13', 'win'],
     ['2.30', 'half-win'],
     ['1.23', 'half-win'],
     ['1.38', 'win']],
    100),
   ['2.7039', 270]),
  ('variant scenario 1',
   ([['3.43', 'void'], ['1.58', 'win'], ['1.37', 'push'], ['3.02', 'win'], ['3.24', 'win']], 100),
   ['15.4600', 1545]),
  ('variant scenario 2', ([['3.08', 'win'], ['3.61', 'void']], 333), ['3.0800', 1025])]]
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:
Parlays with a half-won Asian leg are over- or under-paid.

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

split: open-access