broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(amount, rate, src_exp, dst_exp, fee_bps, min_fee):
    if fee_bps < 0 or amount <= 0: return 'ERR:input'
    conv = lambda m: Decimal(m) * Decimal(rate) * Decimal(10) ** (dst_exp - src_exp)
    rq = lambda d: int(d.quantize(Decimal(1), rounding=ROUND_HALF_EVEN))
    pct = -(-amount * fee_bps // 10000)
    fee = min(min_fee, pct)
    if fee >= amount: return 'ERR:amount-below-fee'
    return [fee, rq(conv(amount - fee))]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression minimum-fee 1', (20000, '0.3071', 2, 3, 25, 100), [100, 61113]),
  ('regression minimum-fee 2', (10000, '151.37', 2, 0, 150, 50), [150, 14910]),
  ('partial repair guard 2', (500, '0.9', 2, 2, 10, 500), 'ERR:amount-below-fee'),
  ('control: fee rounds up', (1001, '1', 2, 2, 100, 0), [11, 990]),
  ('control: zero bps', (777, '1.0833', 2, 2, 0, 0), [0, 842]),
  ('control: large percentage fee', (123456, '0.92', 2, 2, 250, 199), [3087, 110739]),
  ('control: invalid amount', (0, '1.1', 2, 2, 10, 0), 'ERR:input')],
 [('regression minimum-fee 1', (1001, '1', 2, 2, 100, 0), [11, 990]),
  ('regression minimum-fee 2', (500, '0.9', 2, 2, 10, 500), 'ERR:amount-below-fee'),
  ('partial repair guard 1', (99, '1.2', 2, 2, 5, 150), 'ERR:amount-below-fee'),
  ('partial repair guard 2', (314862, '122.2171', 2, 2, 5, 1000), [1000, 38359303]),
  ('control: minimum fee applies', (20000, '0.3071', 2, 3, 25, 100), [100, 61113]),
  ('control: zero bps', (777, '1.0833', 2, 2, 0, 0), [0, 842]),
  ('control: large percentage fee', (123456, '0.92', 2, 2, 250, 199), [3087, 110739]),
  ('control: invalid amount', (0, '1.1', 2, 2, 10, 0), 'ERR:input')],
 [('regression minimum-fee 1', (123456, '0.92', 2, 2, 250, 199), [3087, 110739]),
  ('regression minimum-fee 2', (99, '1.2', 2, 2, 5, 150), 'ERR:amount-below-fee'),
  ('partial repair guard 1', (6382, '2724.83', 3, 0, 333, 1000), [1000, 14665]),
  ('partial repair guard 2', (209552, '10.19418', 2, 3, 5, 250), [250, 21336623]),
  ('control: invalid amount', (0, '1.1', 2, 2, 10, 0), 'ERR:input'),
  ('control: yen payout', (10000, '151.37', 2, 0, 150, 50), [150, 14910]),
  ('control: fee rounds up', (1001, '1', 2, 2, 100, 0), [11, 990]),
  ('control: fee equals amount', (500, '0.9', 2, 2, 10, 500), 'ERR:amount-below-fee')],
 [('regression minimum-fee 1', (197637, '16116.34', 0, 2, 333, 100), [6582, 307910733870]),
  ('regression minimum-fee 2', (22226, '179.9447', 0, 2, 150, 100), [334, 393934937]),
  ('partial repair guard 1', (196707, '199.6780', 0, 3, 25, 1000), [1000, 39078382346]),
  ('partial repair guard 2', (8653, '7.1259', 3, 3, 99, 250), [250, 59879]),
  ('control: fee rounds up', (1001, '1', 2, 2, 100, 0), [11, 990]),
  ('control: fee equals amount', (500, '0.9', 2, 2, 10, 500), 'ERR:amount-below-fee'),
  ('control: minimum fee applies', (20000, '0.3071', 2, 3, 25, 100), [100, 61113]),
  ('control: zero bps', (777, '1.0833', 2, 2, 0, 0), [0, 842])],
 [('regression minimum-fee 1', (50411, '12342.04', 3, 3, 333, 1), [1679, 601452293]),
  ('regression minimum-fee 2', (268603, '16.66106', 2, 0, 150, 50), [4030, 44081]),
  ('partial repair guard 1', (280407, '11.52605', 3, 0, 25, 1000), [1000, 3220]),
  ('partial repair guard 2', (453829, '90.1289', 3, 3, 5, 250), [250, 40880576]),
  ('control: zero bps', (777, '1.0833', 2, 2, 0, 0), [0, 842]),
  ('control: large percentage fee', (123456, '0.92', 2, 2, 250, 199), [3087, 110739]),
  ('control: invalid amount', (0, '1.1', 2, 2, 10, 0), 'ERR:input'),
  ('control: minimum exceeds amount', (99, '1.2', 2, 2, 5, 150), 'ERR:amount-below-fee')]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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 decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(amount, rate, src_exp, dst_exp, fee_bps, min_fee):
    if fee_bps < 0 or amount <= 0: return 'ERR:input'
    conv = lambda m: Decimal(m) * Decimal(rate) * Decimal(10) ** (dst_exp - src_exp)
    rq = lambda d: int(d.quantize(Decimal(1), rounding=ROUND_HALF_EVEN))
    pct = -(-amount * fee_bps // 10000)
    fee = pct or min_fee
    if fee >= amount: return 'ERR:amount-below-fee'
    return [fee, rq(conv(amount - fee))]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression minimum-fee 1', (20000, '0.3071', 2, 3, 25, 100), [100, 61113]),
  ('regression minimum-fee 2', (10000, '151.37', 2, 0, 150, 50), [150, 14910]),
  ('partial repair guard 2', (500, '0.9', 2, 2, 10, 500), 'ERR:amount-below-fee'),
  ('control: fee rounds up', (1001, '1', 2, 2, 100, 0), [11, 990]),
  ('control: zero bps', (777, '1.0833', 2, 2, 0, 0), [0, 842]),
  ('control: large percentage fee', (123456, '0.92', 2, 2, 250, 199), [3087, 110739]),
  ('control: invalid amount', (0, '1.1', 2, 2, 10, 0), 'ERR:input')],
 [('regression minimum-fee 1', (1001, '1', 2, 2, 100, 0), [11, 990]),
  ('regression minimum-fee 2', (500, '0.9', 2, 2, 10, 500), 'ERR:amount-below-fee'),
  ('partial repair guard 1', (99, '1.2', 2, 2, 5, 150), 'ERR:amount-below-fee'),
  ('partial repair guard 2', (314862, '122.2171', 2, 2, 5, 1000), [1000, 38359303]),
  ('control: minimum fee applies', (20000, '0.3071', 2, 3, 25, 100), [100, 61113]),
  ('control: zero bps', (777, '1.0833', 2, 2, 0, 0), [0, 842]),
  ('control: large percentage fee', (123456, '0.92', 2, 2, 250, 199), [3087, 110739]),
  ('control: invalid amount', (0, '1.1', 2, 2, 10, 0), 'ERR:input')],
 [('regression minimum-fee 1', (123456, '0.92', 2, 2, 250, 199), [3087, 110739]),
  ('regression minimum-fee 2', (99, '1.2', 2, 2, 5, 150), 'ERR:amount-below-fee'),
  ('partial repair guard 1', (6382, '2724.83', 3, 0, 333, 1000), [1000, 14665]),
  ('partial repair guard 2', (209552, '10.19418', 2, 3, 5, 250), [250, 21336623]),
  ('control: invalid amount', (0, '1.1', 2, 2, 10, 0), 'ERR:input'),
  ('control: yen payout', (10000, '151.37', 2, 0, 150, 50), [150, 14910]),
  ('control: fee rounds up', (1001, '1', 2, 2, 100, 0), [11, 990]),
  ('control: fee equals amount', (500, '0.9', 2, 2, 10, 500), 'ERR:amount-below-fee')],
 [('regression minimum-fee 1', (197637, '16116.34', 0, 2, 333, 100), [6582, 307910733870]),
  ('regression minimum-fee 2', (22226, '179.9447', 0, 2, 150, 100), [334, 393934937]),
  ('partial repair guard 1', (196707, '199.6780', 0, 3, 25, 1000), [1000, 39078382346]),
  ('partial repair guard 2', (8653, '7.1259', 3, 3, 99, 250), [250, 59879]),
  ('control: fee rounds up', (1001, '1', 2, 2, 100, 0), [11, 990]),
  ('control: fee equals amount', (500, '0.9', 2, 2, 10, 500), 'ERR:amount-below-fee'),
  ('control: minimum fee applies', (20000, '0.3071', 2, 3, 25, 100), [100, 61113]),
  ('control: zero bps', (777, '1.0833', 2, 2, 0, 0), [0, 842])],
 [('regression minimum-fee 1', (50411, '12342.04', 3, 3, 333, 1), [1679, 601452293]),
  ('regression minimum-fee 2', (268603, '16.66106', 2, 0, 150, 50), [4030, 44081]),
  ('partial repair guard 1', (280407, '11.52605', 3, 0, 25, 1000), [1000, 3220]),
  ('partial repair guard 2', (453829, '90.1289', 3, 3, 5, 250), [250, 40880576]),
  ('control: zero bps', (777, '1.0833', 2, 2, 0, 0), [0, 842]),
  ('control: large percentage fee', (123456, '0.92', 2, 2, 250, 199), [3087, 110739]),
  ('control: invalid amount', (0, '1.1', 2, 2, 10, 0), 'ERR:input'),
  ('control: minimum exceeds amount', (99, '1.2', 2, 2, 5, 150), 'ERR:amount-below-fee')]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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:
Large transfers are charged at most the minimum fee.

solve(amount, rate, src_exp, dst_exp, fee_bps, min_fee): amount and min_fee are source minor units, fee_bps a non-negative integer. fee = max(min_fee, ceil(amount*fee_bps/10000)) in source minor units, deducted before conversion. A fee greater than or equal to the amount returns 'ERR:amount-below-fee'; a non-positive amount or negative bps returns 'ERR:input'. The net amount is converted exactly (net * rate * 10**(dst_exp - src_exp)) and rounded half-even. Return [fee, converted].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(amount, rate, src_exp, dst_exp, fee_bps, min_fee):
    if fee_bps < 0 or amount <= 0: return 'ERR:input'
    conv = lambda m: Decimal(m) * Decimal(rate) * Decimal(10) ** (dst_exp - src_exp)
    rq = lambda d: int(d.quantize(Decimal(1), rounding=ROUND_HALF_EVEN))
    pct = -(-amount * fee_bps // 10000)
    fee = max(min_fee, pct)
    if fee > amount: return 'ERR:amount-below-fee'
    return [fee, rq(conv(amount - fee))]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression fee-exhausts-amount 1', (500, '0.9', 2, 2, 10, 500), 'ERR:amount-below-fee'),
  ('partial repair guard 2', (99, '1.2', 2, 2, 5, 150), 'ERR:amount-below-fee'),
  ('control: yen payout', (10000, '151.37', 2, 0, 150, 50), [150, 14910]),
  ('control: fee rounds up', (1001, '1', 2, 2, 100, 0), [11, 990]),
  ('control: minimum fee applies', (20000, '0.3071', 2, 3, 25, 100), [100, 61113]),
  ('control: zero bps', (777, '1.0833', 2, 2, 0, 0), [0, 842])],
 [('regression fee-exhausts-amount 1', (500, '0.9', 2, 2, 10, 500), 'ERR:amount-below-fee'),
  ('partial repair guard 2', (99, '1.2', 2, 2, 5, 150), 'ERR:amount-below-fee'),
  ('control: minimum fee applies', (20000, '0.3071', 2, 3, 25, 100), [100, 61113]),
  ('control: zero bps', (777, '1.0833', 2, 2, 0, 0), [0, 842]),
  ('control: large percentage fee', (123456, '0.92', 2, 2, 250, 199), [3087, 110739]),
  ('control: invalid amount', (0, '1.1', 2, 2, 10, 0), 'ERR:input')],
 [('regression fee-exhausts-amount 1', (500, '0.9', 2, 2, 10, 500), 'ERR:amount-below-fee'),
  ('partial repair guard 2', (99, '1.2', 2, 2, 5, 150), 'ERR:amount-below-fee'),
  ('control: invalid amount', (0, '1.1', 2, 2, 10, 0), 'ERR:input'),
  ('control: yen payout', (10000, '151.37', 2, 0, 150, 50), [150, 14910]),
  ('control: fee rounds up', (1001, '1', 2, 2, 100, 0), [11, 990]),
  ('control: minimum fee applies', (20000, '0.3071', 2, 3, 25, 100), [100, 61113])],
 [('regression fee-exhausts-amount 1', (500, '0.9', 2, 2, 10, 500), 'ERR:amount-below-fee'),
  ('partial repair guard 2', (99, '1.2', 2, 2, 5, 150), 'ERR:amount-below-fee'),
  ('control: fee rounds up', (1001, '1', 2, 2, 100, 0), [11, 990]),
  ('control: minimum fee applies', (20000, '0.3071', 2, 3, 25, 100), [100, 61113]),
  ('control: zero bps', (777, '1.0833', 2, 2, 0, 0), [0, 842]),
  ('control: large percentage fee', (123456, '0.92', 2, 2, 250, 199), [3087, 110739])],
 [('regression fee-exhausts-amount 1', (500, '0.9', 2, 2, 10, 500), 'ERR:amount-below-fee'),
  ('partial repair guard 2', (99, '1.2', 2, 2, 5, 150), 'ERR:amount-below-fee'),
  ('control: zero bps', (777, '1.0833', 2, 2, 0, 0), [0, 842]),
  ('control: large percentage fee', (123456, '0.92', 2, 2, 250, 199), [3087, 110739]),
  ('control: invalid amount', (0, '1.1', 2, 2, 10, 0), 'ERR:input'),
  ('control: yen payout', (10000, '151.37', 2, 0, 150, 50), [150, 14910])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(amount, rate, src_exp, dst_exp, fee_bps, min_fee):
    if fee_bps < 0 or amount <= 0: return 'ERR:input'
    conv = lambda m: Decimal(m) * Decimal(rate) * Decimal(10) ** (dst_exp - src_exp)
    rq = lambda d: int(d.quantize(Decimal(1), rounding=ROUND_HALF_EVEN))
    pct = -(-amount * fee_bps // 10000)
    fee = max(min_fee, pct)
    if fee > amount: fee = amount
    return [fee, rq(conv(amount - fee))]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression fee-exhausts-amount 1', (500, '0.9', 2, 2, 10, 500), 'ERR:amount-below-fee'),
  ('partial repair guard 2', (99, '1.2', 2, 2, 5, 150), 'ERR:amount-below-fee'),
  ('control: yen payout', (10000, '151.37', 2, 0, 150, 50), [150, 14910]),
  ('control: fee rounds up', (1001, '1', 2, 2, 100, 0), [11, 990]),
  ('control: minimum fee applies', (20000, '0.3071', 2, 3, 25, 100), [100, 61113]),
  ('control: zero bps', (777, '1.0833', 2, 2, 0, 0), [0, 842])],
 [('regression fee-exhausts-amount 1', (500, '0.9', 2, 2, 10, 500), 'ERR:amount-below-fee'),
  ('partial repair guard 2', (99, '1.2', 2, 2, 5, 150), 'ERR:amount-below-fee'),
  ('control: minimum fee applies', (20000, '0.3071', 2, 3, 25, 100), [100, 61113]),
  ('control: zero bps', (777, '1.0833', 2, 2, 0, 0), [0, 842]),
  ('control: large percentage fee', (123456, '0.92', 2, 2, 250, 199), [3087, 110739]),
  ('control: invalid amount', (0, '1.1', 2, 2, 10, 0), 'ERR:input')],
 [('regression fee-exhausts-amount 1', (500, '0.9', 2, 2, 10, 500), 'ERR:amount-below-fee'),
  ('partial repair guard 2', (99, '1.2', 2, 2, 5, 150), 'ERR:amount-below-fee'),
  ('control: invalid amount', (0, '1.1', 2, 2, 10, 0), 'ERR:input'),
  ('control: yen payout', (10000, '151.37', 2, 0, 150, 50), [150, 14910]),
  ('control: fee rounds up', (1001, '1', 2, 2, 100, 0), [11, 990]),
  ('control: minimum fee applies', (20000, '0.3071', 2, 3, 25, 100), [100, 61113])],
 [('regression fee-exhausts-amount 1', (500, '0.9', 2, 2, 10, 500), 'ERR:amount-below-fee'),
  ('partial repair guard 2', (99, '1.2', 2, 2, 5, 150), 'ERR:amount-below-fee'),
  ('control: fee rounds up', (1001, '1', 2, 2, 100, 0), [11, 990]),
  ('control: minimum fee applies', (20000, '0.3071', 2, 3, 25, 100), [100, 61113]),
  ('control: zero bps', (777, '1.0833', 2, 2, 0, 0), [0, 842]),
  ('control: large percentage fee', (123456, '0.92', 2, 2, 250, 199), [3087, 110739])],
 [('regression fee-exhausts-amount 1', (500, '0.9', 2, 2, 10, 500), 'ERR:amount-below-fee'),
  ('partial repair guard 2', (99, '1.2', 2, 2, 5, 150), 'ERR:amount-below-fee'),
  ('control: zero bps', (777, '1.0833', 2, 2, 0, 0), [0, 842]),
  ('control: large percentage fee', (123456, '0.92', 2, 2, 250, 199), [3087, 110739]),
  ('control: invalid amount', (0, '1.1', 2, 2, 10, 0), 'ERR:input'),
  ('control: yen payout', (10000, '151.37', 2, 0, 150, 50), [150, 14910])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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 transfer entirely consumed by the fee is accepted and pays out 0.

solve(amount, rate, src_exp, dst_exp, fee_bps, min_fee): amount and min_fee are source minor units, fee_bps a non-negative integer. fee = max(min_fee, ceil(amount*fee_bps/10000)) in source minor units, deducted before conversion. A fee greater than or equal to the amount returns 'ERR:amount-below-fee'; a non-positive amount or negative bps returns 'ERR:input'. The net amount is converted exactly (net * rate * 10**(dst_exp - src_exp)) and rounded half-even. Return [fee, converted].

split: open-access


prompt:
JPY-base pairs get yen pips while forint and won pairs get four-decimal pips.

solve(pair, spot, points, notional): pair is BASEQUOTE. The pip exponent depends on the quote currency: JPY 2, HUF 2, KRW 0, otherwise 4 (pip = 10**-exp). points is a decimal string of pips (fractional pips allowed, negative for discount). forward = spot + points*pip rounded half-even to exp+1 decimals (one fractional pip). The pip value in quote currency is notional*pip rounded half-even to 2 decimals. Return [forward, pip_value] as plain strings.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(pair, spot, points, notional):
    pip_exp = {'JPY': 2, 'HUF': 2, 'KRW': 0}
    quote = pair[3:]
    pe = pip_exp.get(quote, 4)
    pip = Decimal(1).scaleb(-pe)
    fwd = Decimal(spot) + Decimal(int(Decimal(points))) * pip
    fwd = fwd.quantize(Decimal(1).scaleb(-(pe + 1)), rounding=ROUND_HALF_EVEN)
    pv = (Decimal(notional) * pip).quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
    return [format(fwd, 'f'), format(pv, 'f')]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression fractional-points 1', ('EURUSD', '1.08345', '12.5', 1000000), ['1.08470', '100.00']),
  ('regression fractional-points 2', ('USDJPY', '151.234', '-45.25', 1000000), ['150.782', '10000.00']),
  ('control: won pips', ('USDKRW', '1352.5', '3.2', 1000000), ['1355.7', '1000000.00']),
  ('control: forint', ('EURHUF', '395.12', '-0.35', 250000), ['395.116', '2500.00']),
  ('control: yen base pair', ('JPYSEK', '0.07012', '1.5', 5000000), ['0.07027', '500.00']),
  ('control: sterling', ('GBPUSD', '1.26501', '-0.75', 333333), ['1.26494', '33.33'])],
 [('regression fractional-points 1', ('USDKRW', '1352.5', '3.2', 1000000), ['1355.7', '1000000.00']),
  ('regression fractional-points 2', ('EURHUF', '395.12', '-0.35', 250000), ['395.116', '2500.00']),
  ('control: yen base pair', ('JPYSEK', '0.07012', '1.5', 5000000), ['0.07027', '500.00']),
  ('control: sterling', ('GBPUSD', '1.26501', '-0.75', 333333), ['1.26494', '33.33']),
  ('control: zero points', ('AUDNZD', '1.09876', '0', 100000), ['1.09876', '10.00']),
  ('control: euro premium', ('EURUSD', '1.08345', '12.5', 1000000), ['1.08470', '100.00'])],
 [('regression fractional-points 1', ('JPYSEK', '0.07012', '1.5', 5000000), ['0.07027', '500.00']),
  ('regression fractional-points 2', ('GBPUSD', '1.26501', '-0.75', 333333), ['1.26494', '33.33']),
  ('control: zero points', ('AUDNZD', '1.09876', '0', 100000), ['1.09876', '10.00']),
  ('control: euro premium', ('EURUSD', '1.08345', '12.5', 1000000), ['1.08470', '100.00']),
  ('control: yen discount', ('USDJPY', '151.234', '-45.25', 1000000), ['150.782', '10000.00']),
  ('control: won pips', ('USDKRW', '1352.5', '3.2', 1000000), ['1355.7', '1000000.00'])],
 [('regression fractional-points 1', ('EURHUF', '698.3982', '193.71', 1000), ['700.335', '10.00']),
  ('regression fractional-points 2', ('EURHUF', '138.28482', '-67.66', 1000), ['137.608', '10.00']),
  ('control: won pips', ('USDKRW', '1352.5', '3.2', 1000000), ['1355.7', '1000000.00']),
  ('control: forint', ('EURHUF', '395.12', '-0.35', 250000), ['395.116', '2500.00']),
  ('control: yen base pair', ('JPYSEK', '0.07012', '1.5', 5000000), ['0.07027', '500.00']),
  ('control: sterling', ('GBPUSD', '1.26501', '-0.75', 333333), ['1.26494', '33.33'])],
 [('regression fractional-points 1', ('EURHUF', '4938.658', '-58.12', 1000000), ['4938.077', '10000.00']),
  ('regression fractional-points 2', ('JPYSEK', '183.37113', '-118.52', 1000), ['183.35928', '0.10']),
  ('control: sterling', ('GBPUSD', '1.26501', '-0.75', 333333), ['1.26494', '33.33']),
  ('control: zero points', ('AUDNZD', '1.09876', '0', 100000), ['1.09876', '10.00']),
  ('control: euro premium', ('EURUSD', '1.08345', '12.5', 1000000), ['1.08470', '100.00']),
  ('control: yen discount', ('USDJPY', '151.234', '-45.25', 1000000), ['150.782', '10000.00'])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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 decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(pair, spot, points, notional):
    pip_exp = {'JPY': 2, 'HUF': 2, 'KRW': 0}
    quote = pair[3:]
    pe = pip_exp.get(quote, 4)
    pip = Decimal(1).scaleb(-pe)
    fwd = Decimal(spot) + Decimal(round(float(points))) * pip
    fwd = fwd.quantize(Decimal(1).scaleb(-(pe + 1)), rounding=ROUND_HALF_EVEN)
    pv = (Decimal(notional) * pip).quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
    return [format(fwd, 'f'), format(pv, 'f')]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression fractional-points 1', ('EURUSD', '1.08345', '12.5', 1000000), ['1.08470', '100.00']),
  ('regression fractional-points 2', ('USDJPY', '151.234', '-45.25', 1000000), ['150.782', '10000.00']),
  ('control: won pips', ('USDKRW', '1352.5', '3.2', 1000000), ['1355.7', '1000000.00']),
  ('control: forint', ('EURHUF', '395.12', '-0.35', 250000), ['395.116', '2500.00']),
  ('control: yen base pair', ('JPYSEK', '0.07012', '1.5', 5000000), ['0.07027', '500.00']),
  ('control: sterling', ('GBPUSD', '1.26501', '-0.75', 333333), ['1.26494', '33.33'])],
 [('regression fractional-points 1', ('USDKRW', '1352.5', '3.2', 1000000), ['1355.7', '1000000.00']),
  ('regression fractional-points 2', ('EURHUF', '395.12', '-0.35', 250000), ['395.116', '2500.00']),
  ('control: yen base pair', ('JPYSEK', '0.07012', '1.5', 5000000), ['0.07027', '500.00']),
  ('control: sterling', ('GBPUSD', '1.26501', '-0.75', 333333), ['1.26494', '33.33']),
  ('control: zero points', ('AUDNZD', '1.09876', '0', 100000), ['1.09876', '10.00']),
  ('control: euro premium', ('EURUSD', '1.08345', '12.5', 1000000), ['1.08470', '100.00'])],
 [('regression fractional-points 1', ('JPYSEK', '0.07012', '1.5', 5000000), ['0.07027', '500.00']),
  ('regression fractional-points 2', ('GBPUSD', '1.26501', '-0.75', 333333), ['1.26494', '33.33']),
  ('control: zero points', ('AUDNZD', '1.09876', '0', 100000), ['1.09876', '10.00']),
  ('control: euro premium', ('EURUSD', '1.08345', '12.5', 1000000), ['1.08470', '100.00']),
  ('control: yen discount', ('USDJPY', '151.234', '-45.25', 1000000), ['150.782', '10000.00']),
  ('control: won pips', ('USDKRW', '1352.5', '3.2', 1000000), ['1355.7', '1000000.00'])],
 [('regression fractional-points 1', ('EURHUF', '698.3982', '193.71', 1000), ['700.335', '10.00']),
  ('regression fractional-points 2', ('EURHUF', '138.28482', '-67.66', 1000), ['137.608', '10.00']),
  ('control: won pips', ('USDKRW', '1352.5', '3.2', 1000000), ['1355.7', '1000000.00']),
  ('control: forint', ('EURHUF', '395.12', '-0.35', 250000), ['395.116', '2500.00']),
  ('control: yen base pair', ('JPYSEK', '0.07012', '1.5', 5000000), ['0.07027', '500.00']),
  ('control: sterling', ('GBPUSD', '1.26501', '-0.75', 333333), ['1.26494', '33.33'])],
 [('regression fractional-points 1', ('EURHUF', '4938.658', '-58.12', 1000000), ['4938.077', '10000.00']),
  ('regression fractional-points 2', ('JPYSEK', '183.37113', '-118.52', 1000), ['183.35928', '0.10']),
  ('control: sterling', ('GBPUSD', '1.26501', '-0.75', 333333), ['1.26494', '33.33']),
  ('control: zero points', ('AUDNZD', '1.09876', '0', 100000), ['1.09876', '10.00']),
  ('control: euro premium', ('EURUSD', '1.08345', '12.5', 1000000), ['1.08470', '100.00']),
  ('control: yen discount', ('USDJPY', '151.234', '-45.25', 1000000), ['150.782', '10000.00'])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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 12.5-pip premium is applied as 12 pips.

solve(pair, spot, points, notional): pair is BASEQUOTE. The pip exponent depends on the quote currency: JPY 2, HUF 2, KRW 0, otherwise 4 (pip = 10**-exp). points is a decimal string of pips (fractional pips allowed, negative for discount). forward = spot + points*pip rounded half-even to exp+1 decimals (one fractional pip). The pip value in quote currency is notional*pip rounded half-even to 2 decimals. Return [forward, pip_value] as plain strings.

split: open-access


prompt:
The forward rate loses the fractional pip that the dealing screen shows.

solve(pair, spot, points, notional): pair is BASEQUOTE. The pip exponent depends on the quote currency: JPY 2, HUF 2, KRW 0, otherwise 4 (pip = 10**-exp). points is a decimal string of pips (fractional pips allowed, negative for discount). forward = spot + points*pip rounded half-even to exp+1 decimals (one fractional pip). The pip value in quote currency is notional*pip rounded half-even to 2 decimals. Return [forward, pip_value] as plain strings.

split: open-access


source:
"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(trades):
    exps = {'JPY': 0, 'KWD': 3}
    net = {}
    for pay_c, pay_a, rec_c, rec_a in trades:
        net[pay_c] = net.get(pay_c, Decimal(0)) - Decimal(pay_a)
        net[rec_c] = net.get(rec_c, Decimal(0)) + Decimal(rec_a)
    out = []
    for c in sorted(net):
        v = net[c]
        if format(v.quantize(Decimal(1).scaleb(-exps.get(c, 2))), 'f') == '0': continue
        out.append([c, format(v.quantize(Decimal(1).scaleb(-exps.get(c, 2))), 'f')])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression zero-net-omission 1', ([['USD', '10.00', 'EUR', '9.20'], ['EUR', '9.20', 'USD', '10.00']],), []),
  ('regression zero-net-omission 2', ([['USD', '108.35', 'EUR', '100.00'], ['EUR', '100.00', 'JPY', '16200']],),
   [['JPY', '16200'], ['USD', '-108.35']]),
  ('control: short amounts', ([['USD', '5', 'GBP', '4']],), [['GBP', '4.00'], ['USD', '-5.00']]),
  ('control: same currency swap', ([['KWD', '1.250', 'KWD', '1.000']],), [['KWD', '-0.250']]),
  ('control: empty', ([],), []),
  ('control: unsorted codes',
   ([['USD', '1.00', 'EUR', '0.92'], ['GBP', '0.79', 'USD', '1.00'], ['KWD', '0.307', 'CHF', '0.88']],),
   [['CHF', '0.88'], ['EUR', '0.92'], ['GBP', '-0.79'], ['KWD', '-0.307']])],
 [('regression zero-net-omission 1',
   ([['USD', '1.00', 'EUR', '0.92'], ['GBP', '0.79', 'USD', '1.00'], ['KWD', '0.307', 'CHF', '0.88']],),
   [['CHF', '0.88'], ['EUR', '0.92'], ['GBP', '-0.79'], ['KWD', '-0.307']]),
  ('regression zero-net-omission 2',
   ([['JPY', '1806', 'KWD', '4720.108'], ['USD', '3724.50', 'JPY', '222'], ['KWD', '4720.108', 'JPY', '1806']],),
   [['JPY', '222'], ['USD', '-3724.50']]),
  ('control: same currency swap', ([['KWD', '1.250', 'KWD', '1.000']],), [['KWD', '-0.250']]),
  ('control: empty', ([],), []),
  ('control: chained trades', ([['USD', '108.35', 'EUR', '100.00'], ['EUR', '100.00', 'JPY', '16200']],),
   [['JPY', '16200'], ['USD', '-108.35']]),
  ('control: short amounts', ([['USD', '5', 'GBP', '4']],), [['GBP', '4.00'], ['USD', '-5.00']])],
 [('regression zero-net-omission 1', ([['JPY', '2849', 'USD', '3944.10'], ['USD', '3944.10', 'JPY', '2849']],), []),
  ('regression zero-net-omission 2',
   ([['USD', '1062.91', 'GBP', '4208.76'], ['EUR', '468.58', 'EUR', '2562.98'], ['GBP', '4208.76', 'USD', '1062.91']],),
   [['EUR', '2094.40']]),
  ('control: chained trades', ([['USD', '108.35', 'EUR', '100.00'], ['EUR', '100.00', 'JPY', '16200']],),
   [['JPY', '16200'], ['USD', '-108.35']]),
  ('control: short amounts', ([['USD', '5', 'GBP', '4']],), [['GBP', '4.00'], ['USD', '-5.00']]),
  ('control: fully offset', ([['USD', '10.00', 'EUR', '9.20'], ['EUR', '9.20', 'USD', '10.00']],), []),
  ('control: same currency swap', ([['KWD', '1.250', 'KWD', '1.000']],), [['KWD', '-0.250']])],
 [('regression zero-net-omission 1',
   ([['EUR', '4958.34', 'JPY', '456'], ['KWD', '149.894', 'EUR', '4865.00'], ['GBP', '4322.22', 'GBP', '4150.09'],
     ['USD', '4134', 'GBP', '151.91'], ['JPY', '456', 'EUR', '4958.34']],),
   [['EUR', '4865.00'], ['GBP', '-20.22'], ['KWD', '-149.894'], ['USD', '-4134.00']]),
  ('regression zero-net-omission 2', ([['USD', '4066.17', 'EUR', '2513'], ['EUR', '2513', 'USD', '4066.17']],), []),
  ('partial repair guard 2',
   ([['JPY', '1210', 'GBP', '400.13'], ['JPY', '1882', 'EUR', '1387'], ['JPY', '133', 'KWD', '4882'],
     ['GBP', '400.13', 'JPY', '1210']],),
   [['EUR', '1387.00'], ['JPY', '-2015'], ['KWD', '4882.000']]),
  ('control: same currency swap', ([['KWD', '1.250', 'KWD', '1.000']],), [['KWD', '-0.250']]),
  ('control: empty', ([],), []),
  ('control: unsorted codes',
   ([['USD', '1.00', 'EUR', '0.92'], ['GBP', '0.79', 'USD', '1.00'], ['KWD', '0.307', 'CHF', '0.88']],),
   [['CHF', '0.88'], ['EUR', '0.92'], ['GBP', '-0.79'], ['KWD', '-0.307']]),
  ('control: chained trades', ([['USD', '108.35', 'EUR', '100.00'], ['EUR', '100.00', 'JPY', '16200']],),
   [['JPY', '16200'], ['USD', '-108.35']])],
 [('regression zero-net-omission 1',
   ([['JPY', '1210', 'GBP', '400.13'], ['JPY', '1882', 'EUR', '1387'], ['JPY', '133', 'KWD', '4882'],
     ['GBP', '400.13', 'JPY', '1210']],),
   [['EUR', '1387.00'], ['JPY', '-2015'], ['KWD', '4882.000']]),
  ('regression zero-net-omission 2',
   ([['USD', '4986.84', 'JPY', '4037'], ['EUR', '357', 'EUR', '2273.42'], ['JPY', '4037', 'USD', '4986.84']],),
   [['EUR', '1916.42']]),
  ('partial repair guard 2',
   ([['GBP', '3621.77', 'USD', '651.33'], ['GBP', '1148.32', 'EUR', '4519'], ['EUR', '1042.18', 'KWD', '4279.575'],
     ['USD', '651.33', 'GBP', '3621.77']],),
   [['EUR', '3476.82'], ['GBP', '-1148.32'], ['KWD', '4279.575']]),
  ('control: chained trades', ([['USD', '108.35', 'EUR', '100.00'], ['EUR', '100.00', 'JPY', '16200']],),
   [['JPY', '16200'], ['USD', '-108.35']]),
  ('control: short amounts', ([['USD', '5', 'GBP', '4']],), [['GBP', '4.00'], ['USD', '-5.00']]),
  ('control: fully offset', ([['USD', '10.00', 'EUR', '9.20'], ['EUR', '9.20', 'USD', '10.00']],), []),
  ('control: same currency swap', ([['KWD', '1.250', 'KWD', '1.000']],), [['KWD', '-0.250']])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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 currency that nets to zero still produces a zero payment instruction.

solve(trades): each trade is [pay_ccy, pay_amount, recv_ccy, recv_amount] from our side. Net per currency = received - paid. Return [[ccy, net], ...] sorted by currency code, omitting currencies whose net is exactly zero; nets are plain strings at the currency exponent (JPY 0, KWD 3, else 2).

split: open-access


prompt:
Currencies we receive are reported as outgoing payments.

solve(trades): each trade is [pay_ccy, pay_amount, recv_ccy, recv_amount] from our side. Net per currency = received - paid. Return [[ccy, net], ...] sorted by currency code, omitting currencies whose net is exactly zero; nets are plain strings at the currency exponent (JPY 0, KWD 3, else 2).

split: open-access


prompt:
A net of five dollars is written as '5' rather than '5.00'.

solve(trades): each trade is [pay_ccy, pay_amount, recv_ccy, recv_amount] from our side. Net per currency = received - paid. Return [[ccy, net], ...] sorted by currency code, omitting currencies whose net is exactly zero; nets are plain strings at the currency exponent (JPY 0, KWD 3, else 2).

split: open-access


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

N = 1
observations = []
def solve(text, locale, exp):
    seps = {'en': (',', '.'), 'de': ('.', ','), 'ch': ("'", '.'), 'fr': (' \u202f', ',')}
    if locale not in seps: return 'ERR:locale'
    groups, dec = seps[locale]
    dig = lambda t: t != '' and all(c in '0123456789' for c in t)
    s = text.strip()
    neg = s.startswith('-')
    if neg: s = s[1:]
    whole, _, frac = s.partition(dec)
    for g in groups[1:]: whole = whole.replace(g, groups[0])
    parts = whole.split(groups[0])
    if not all(dig(p) for p in parts) or (dec in s and not dig(frac)): return 'ERR:format'
    if len(parts) > 1 and (len(parts[0]) > 3 or any(len(p) != 3 for p in parts[1:])): return 'ERR:format'
    if frac[exp:].strip('0'): return 'ERR:precision'
    frac = frac[:exp]
    v = int(''.join(parts)) * 10 ** exp + (int(frac) if frac else 0)
    return -v if neg else v
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression fraction-padding 1', ('12.5', 'en', 3), 12500),
  ('regression fraction-padding 2', ('1.234,5', 'de', 2), 123450),
  ('partial repair guard 2', ('12.05', 'ch', 3), 12050), ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: negative below one', ('-0,50', 'de', 2), -50),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450),
  ('control: excess precision', ('12.345', 'en', 2), 'ERR:precision')],
 [('regression fraction-padding 1', ('12 345,6', 'fr', 2), 1234560),
  ('regression fraction-padding 2', ('12.05', 'ch', 3), 12050), ('partial repair guard 1', ('999.50', 'ch', 3), 999500),
  ('partial repair guard 2', ('-999,50', 'fr', 3), -999500),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450),
  ('control: excess precision', ('12.345', 'en', 2), 'ERR:precision'),
  ('control: bad grouping', ('1,23,4.00', 'en', 2), 'ERR:format'),
  ('control: dinar fraction', ('12.5', 'en', 3), 12500)],
 [('regression fraction-padding 1', ('999,1', 'fr', 2), 99910),
  ('regression fraction-padding 2', ('12,5', 'fr', 2), 1250), ('partial repair guard 1', ('-0.1', 'ch', 3), -100),
  ('partial repair guard 2', ('12345,5', 'de', 3), 12345500), ('control: dinar fraction', ('12.5', 'en', 3), 12500),
  ('control: swiss integer', ("1'000", 'ch', 0), 1000), ('control: french plain space', ('12 345,6', 'fr', 2), 1234560),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format')],
 [('regression fraction-padding 1', ("12'345.5", 'ch', 2), 1234550),
  ('regression fraction-padding 2', ('12,1', 'de', 2), 1210),
  ('partial repair guard 1', ('100000,5', 'de', 3), 100000500),
  ('partial repair guard 2', ('-999,1', 'de', 3), -999100),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format'),
  ('control: unknown locale', ('12', 'it', 2), 'ERR:locale'),
  ('control: oversized first group', ('1234,567.00', 'en', 2), 'ERR:format'),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456)],
 [('regression fraction-padding 1', ('-12.345,1', 'de', 2), -1234510),
  ('regression fraction-padding 2', ('999.50', 'ch', 3), 999500),
  ('partial repair guard 1', ('-1000,50', 'de', 3), -1000500),
  ('partial repair guard 2', ('12.345,50', 'de', 3), 12345500),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450),
  ('control: negative below one', ('-0,50', 'de', 2), -50),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450)]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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(text, locale, exp):
    seps = {'en': (',', '.'), 'de': ('.', ','), 'ch': ("'", '.'), 'fr': (' \u202f', ',')}
    if locale not in seps: return 'ERR:locale'
    groups, dec = seps[locale]
    dig = lambda t: t != '' and all(c in '0123456789' for c in t)
    s = text.strip()
    neg = s.startswith('-')
    if neg: s = s[1:]
    whole, _, frac = s.partition(dec)
    for g in groups[1:]: whole = whole.replace(g, groups[0])
    parts = whole.split(groups[0])
    if not all(dig(p) for p in parts) or (dec in s and not dig(frac)): return 'ERR:format'
    if len(parts) > 1 and (len(parts[0]) > 3 or any(len(p) != 3 for p in parts[1:])): return 'ERR:format'
    if frac[exp:].strip('0'): return 'ERR:precision'
    frac = frac[:exp].ljust(2, '0')
    v = int(''.join(parts)) * 10 ** exp + (int(frac) if frac else 0)
    return -v if neg else v
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression fraction-padding 1', ('12.5', 'en', 3), 12500),
  ('regression fraction-padding 2', ('1.234,5', 'de', 2), 123450),
  ('partial repair guard 2', ('12.05', 'ch', 3), 12050), ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: negative below one', ('-0,50', 'de', 2), -50),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450),
  ('control: excess precision', ('12.345', 'en', 2), 'ERR:precision')],
 [('regression fraction-padding 1', ('12 345,6', 'fr', 2), 1234560),
  ('regression fraction-padding 2', ('12.05', 'ch', 3), 12050), ('partial repair guard 1', ('999.50', 'ch', 3), 999500),
  ('partial repair guard 2', ('-999,50', 'fr', 3), -999500),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450),
  ('control: excess precision', ('12.345', 'en', 2), 'ERR:precision'),
  ('control: bad grouping', ('1,23,4.00', 'en', 2), 'ERR:format'),
  ('control: dinar fraction', ('12.5', 'en', 3), 12500)],
 [('regression fraction-padding 1', ('999,1', 'fr', 2), 99910),
  ('regression fraction-padding 2', ('12,5', 'fr', 2), 1250), ('partial repair guard 1', ('-0.1', 'ch', 3), -100),
  ('partial repair guard 2', ('12345,5', 'de', 3), 12345500), ('control: dinar fraction', ('12.5', 'en', 3), 12500),
  ('control: swiss integer', ("1'000", 'ch', 0), 1000), ('control: french plain space', ('12 345,6', 'fr', 2), 1234560),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format')],
 [('regression fraction-padding 1', ("12'345.5", 'ch', 2), 1234550),
  ('regression fraction-padding 2', ('12,1', 'de', 2), 1210),
  ('partial repair guard 1', ('100000,5', 'de', 3), 100000500),
  ('partial repair guard 2', ('-999,1', 'de', 3), -999100),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format'),
  ('control: unknown locale', ('12', 'it', 2), 'ERR:locale'),
  ('control: oversized first group', ('1234,567.00', 'en', 2), 'ERR:format'),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456)],
 [('regression fraction-padding 1', ('-12.345,1', 'de', 2), -1234510),
  ('regression fraction-padding 2', ('999.50', 'ch', 3), 999500),
  ('partial repair guard 1', ('-1000,50', 'de', 3), -1000500),
  ('partial repair guard 2', ('12.345,50', 'de', 3), 12345500),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450),
  ('control: negative below one', ('-0,50', 'de', 2), -50),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450)]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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:
'12.5' dollars parses as 1205 cents.

solve(text, locale, exp): parse a localized amount into integer minor units at exponent exp. Group/decimal separators: en ',' '.', de '.' ',', ch "'" '.', fr ' ' or U+202F and ','. An optional leading '-' marks a negative amount (including -0.xx). If grouping is used, the first group has 1-3 digits and every later group exactly 3. A decimal separator must be followed by digits. Fraction digits beyond exp are allowed only if they are zeros, otherwise 'ERR:precision'. Malformed text returns 'ERR:format'; an unknown locale 'ERR:locale'.

split: open-access


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

N = 1
observations = []
def solve(text, locale, exp):
    seps = {'en': (',', '.'), 'de': ('.', ','), 'ch': ("'", '.'), 'fr': (' \u202f', ',')}
    if locale not in seps: return 'ERR:locale'
    groups, dec = seps[locale]
    dig = lambda t: t != '' and all(c in '0123456789' for c in t)
    s = text.strip()
    neg = s.startswith('-')
    if neg: s = s[1:]
    whole, _, frac = s.partition(dec)
    for g in groups[1:]: whole = whole.replace(g, groups[0])
    parts = whole.split(groups[0])
    if not all(dig(p) for p in parts) or (dec in s and not dig(frac)): return 'ERR:format'
    if len(parts) > 1 and (len(parts[0]) > 3 or any(len(p) != 3 for p in parts[1:])): return 'ERR:format'
    if frac[exp:].strip('0'): return 'ERR:precision'
    frac = frac[:exp].ljust(exp, '0')
    v = (-1 if neg else 1) * int(''.join(parts)) * 10 ** exp + (int(frac) if frac else 0)
    return v
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression negative-below-one 1', ('-0,50', 'de', 2), -50),
  ('regression negative-below-one 2', ('-12.50', 'en', 2), -1250), ('partial repair guard 2', ('-0,500', 'fr', 2), -50),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450),
  ('control: excess precision', ('12.345', 'en', 2), 'ERR:precision')],
 [('regression negative-below-one 1', ('-12.05', 'en', 2), -1205),
  ('regression negative-below-one 2', ('-0,500', 'fr', 2), -50), ('partial repair guard 1', ('-0.1', 'ch', 3), -100),
  ('partial repair guard 2', ('-0,5', 'de', 2), -50),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450),
  ('control: excess precision', ('12.345', 'en', 2), 'ERR:precision'),
  ('control: bad grouping', ('1,23,4.00', 'en', 2), 'ERR:format'),
  ('control: dinar fraction', ('12.5', 'en', 3), 12500)],
 [('regression negative-below-one 1', ('-12345,500', 'de', 3), -12345500),
  ('regression negative-below-one 2', ('-12.345,1', 'de', 2), -1234510),
  ('partial repair guard 1', ('-0.1', 'en', 2), -10), ('partial repair guard 2', ('-0.1', 'en', 3), -100),
  ('control: dinar fraction', ('12.5', 'en', 3), 12500), ('control: swiss integer', ("1'000", 'ch', 0), 1000),
  ('control: french plain space', ('12 345,6', 'fr', 2), 1234560),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format')],
 [('regression negative-below-one 1', ('-999,50', 'fr', 3), -999500),
  ('regression negative-below-one 2', ('-12\u202f345,05', 'fr', 2), -1234505),
  ('partial repair guard 1', ('-0,500', 'de', 3), -500), ('partial repair guard 2', ('-0.1', 'ch', 2), -10),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format'),
  ('control: unknown locale', ('12', 'it', 2), 'ERR:locale'),
  ('control: oversized first group', ('1234,567.00', 'en', 2), 'ERR:format'),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456)],
 [('regression negative-below-one 1', ('-0.1', 'ch', 3), -100),
  ('regression negative-below-one 2', ('-1000.1', 'ch', 2), -100010),
  ('partial repair guard 1', ('-0,05', 'de', 3), -50), ('partial repair guard 2', ('-0,50', 'de', 2), -50),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450),
  ('control: excess precision', ('12.345', 'en', 2), 'ERR:precision')]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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(text, locale, exp):
    seps = {'en': (',', '.'), 'de': ('.', ','), 'ch': ("'", '.'), 'fr': (' \u202f', ',')}
    if locale not in seps: return 'ERR:locale'
    groups, dec = seps[locale]
    dig = lambda t: t != '' and all(c in '0123456789' for c in t)
    s = text.strip()
    neg = s.startswith('-')
    if neg: s = s[1:]
    whole, _, frac = s.partition(dec)
    for g in groups[1:]: whole = whole.replace(g, groups[0])
    parts = whole.split(groups[0])
    if not all(dig(p) for p in parts) or (dec in s and not dig(frac)): return 'ERR:format'
    if len(parts) > 1 and (len(parts[0]) > 3 or any(len(p) != 3 for p in parts[1:])): return 'ERR:format'
    if frac[exp:].strip('0'): return 'ERR:precision'
    frac = frac[:exp].ljust(exp, '0')
    m = int(('-' if neg else '') + ''.join(parts))
    v = m * 10 ** exp + ((-1 if m < 0 else 1) * int(frac) if frac else 0)
    return v
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression negative-below-one 1', ('-0,50', 'de', 2), -50),
  ('regression negative-below-one 2', ('-12.50', 'en', 2), -1250), ('partial repair guard 2', ('-0,500', 'fr', 2), -50),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450),
  ('control: excess precision', ('12.345', 'en', 2), 'ERR:precision')],
 [('regression negative-below-one 1', ('-12.05', 'en', 2), -1205),
  ('regression negative-below-one 2', ('-0,500', 'fr', 2), -50), ('partial repair guard 1', ('-0.1', 'ch', 3), -100),
  ('partial repair guard 2', ('-0,5', 'de', 2), -50),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450),
  ('control: excess precision', ('12.345', 'en', 2), 'ERR:precision'),
  ('control: bad grouping', ('1,23,4.00', 'en', 2), 'ERR:format'),
  ('control: dinar fraction', ('12.5', 'en', 3), 12500)],
 [('regression negative-below-one 1', ('-12345,500', 'de', 3), -12345500),
  ('regression negative-below-one 2', ('-12.345,1', 'de', 2), -1234510),
  ('partial repair guard 1', ('-0.1', 'en', 2), -10), ('partial repair guard 2', ('-0.1', 'en', 3), -100),
  ('control: dinar fraction', ('12.5', 'en', 3), 12500), ('control: swiss integer', ("1'000", 'ch', 0), 1000),
  ('control: french plain space', ('12 345,6', 'fr', 2), 1234560),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format')],
 [('regression negative-below-one 1', ('-999,50', 'fr', 3), -999500),
  ('regression negative-below-one 2', ('-12\u202f345,05', 'fr', 2), -1234505),
  ('partial repair guard 1', ('-0,500', 'de', 3), -500), ('partial repair guard 2', ('-0.1', 'ch', 2), -10),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format'),
  ('control: unknown locale', ('12', 'it', 2), 'ERR:locale'),
  ('control: oversized first group', ('1234,567.00', 'en', 2), 'ERR:format'),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456)],
 [('regression negative-below-one 1', ('-0.1', 'ch', 3), -100),
  ('regression negative-below-one 2', ('-1000.1', 'ch', 2), -100010),
  ('partial repair guard 1', ('-0,05', 'de', 3), -50), ('partial repair guard 2', ('-0,50', 'de', 2), -50),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450),
  ('control: excess precision', ('12.345', 'en', 2), 'ERR:precision')]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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:
'-12.50' parses as -1150 cents and '-0.50' as +50.

solve(text, locale, exp): parse a localized amount into integer minor units at exponent exp. Group/decimal separators: en ',' '.', de '.' ',', ch "'" '.', fr ' ' or U+202F and ','. An optional leading '-' marks a negative amount (including -0.xx). If grouping is used, the first group has 1-3 digits and every later group exactly 3. A decimal separator must be followed by digits. Fraction digits beyond exp are allowed only if they are zeros, otherwise 'ERR:precision'. Malformed text returns 'ERR:format'; an unknown locale 'ERR:locale'.

split: open-access


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

N = 1
observations = []
def solve(text, locale, exp):
    seps = {'en': (',', '.'), 'de': ('.', ','), 'ch': ("'", '.'), 'fr': (' \u202f', ',')}
    if locale not in seps: return 'ERR:locale'
    groups, dec = seps[locale]
    dig = lambda t: t != '' and all(c in '0123456789' for c in t)
    s = text.strip()
    neg = s.startswith('-')
    if neg: s = s[1:]
    whole, _, frac = s.partition(dec)
    for g in groups[1:]: whole = whole.replace(g, groups[0])
    parts = whole.split(groups[0])
    if not all(dig(p) for p in parts) or (dec in s and not dig(frac)): return 'ERR:format'
    if frac[exp:].strip('0'): return 'ERR:precision'
    frac = frac[:exp].ljust(exp, '0')
    v = int(''.join(parts)) * 10 ** exp + (int(frac) if frac else 0)
    return -v if neg else v
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression group-shape 1', ('1,23,4.00', 'en', 2), 'ERR:format'),
  ('regression group-shape 2', ('1234,567.00', 'en', 2), 'ERR:format'),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450),
  ('control: negative below one', ('-0,50', 'de', 2), -50),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450)],
 [('regression group-shape 1', ('-100 1000,1', 'fr', 3), 'ERR:format'),
  ('regression group-shape 2', ("1'1000.50", 'ch', 2), 'ERR:format'),
  ('partial repair guard 1', ('1234,567.00', 'en', 2), 'ERR:format'),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450),
  ('control: excess precision', ('12.345', 'en', 2), 'ERR:precision'),
  ('control: bad grouping', ('1,23,4.00', 'en', 2), 'ERR:format'),
  ('control: dinar fraction', ('12.5', 'en', 3), 12500)],
 [('regression group-shape 1', ('-1 1000,123', 'fr', 3), 'ERR:format'),
  ('regression group-shape 2', ('12.1345,123', 'de', 2), 'ERR:format'),
  ('partial repair guard 1', ('1234,567.00', 'en', 2), 'ERR:format'),
  ('control: dinar fraction', ('12.5', 'en', 3), 12500), ('control: swiss integer', ("1'000", 'ch', 0), 1000),
  ('control: french plain space', ('12 345,6', 'fr', 2), 1234560),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format')],
 [('regression group-shape 1', ('100,1000.1', 'en', 3), 'ERR:format'),
  ('regression group-shape 2', ('12,1345', 'en', 3), 'ERR:format'),
  ('partial repair guard 1', ('1234,567.00', 'en', 2), 'ERR:format'),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format'),
  ('control: unknown locale', ('12', 'it', 2), 'ERR:locale'),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450)],
 [('regression group-shape 1', ('100,1000.50', 'en', 2), 'ERR:format'),
  ('regression group-shape 2', ("1'1234'567.05", 'ch', 3), 'ERR:format'),
  ('partial repair guard 1', ('1234,567.00', 'en', 2), 'ERR:format'),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450),
  ('control: negative below one', ('-0,50', 'de', 2), -50),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450)]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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(text, locale, exp):
    seps = {'en': (',', '.'), 'de': ('.', ','), 'ch': ("'", '.'), 'fr': (' \u202f', ',')}
    if locale not in seps: return 'ERR:locale'
    groups, dec = seps[locale]
    dig = lambda t: t != '' and all(c in '0123456789' for c in t)
    s = text.strip()
    neg = s.startswith('-')
    if neg: s = s[1:]
    whole, _, frac = s.partition(dec)
    for g in groups[1:]: whole = whole.replace(g, groups[0])
    parts = whole.split(groups[0])
    if not all(dig(p) for p in parts) or (dec in s and not dig(frac)): return 'ERR:format'
    if len(parts) > 1 and any(len(p) != 3 for p in parts[1:]): return 'ERR:format'
    if frac[exp:].strip('0'): return 'ERR:precision'
    frac = frac[:exp].ljust(exp, '0')
    v = int(''.join(parts)) * 10 ** exp + (int(frac) if frac else 0)
    return -v if neg else v
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression group-shape 1', ('1,23,4.00', 'en', 2), 'ERR:format'),
  ('regression group-shape 2', ('1234,567.00', 'en', 2), 'ERR:format'),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450),
  ('control: negative below one', ('-0,50', 'de', 2), -50),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450)],
 [('regression group-shape 1', ('-100 1000,1', 'fr', 3), 'ERR:format'),
  ('regression group-shape 2', ("1'1000.50", 'ch', 2), 'ERR:format'),
  ('partial repair guard 1', ('1234,567.00', 'en', 2), 'ERR:format'),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450),
  ('control: excess precision', ('12.345', 'en', 2), 'ERR:precision'),
  ('control: bad grouping', ('1,23,4.00', 'en', 2), 'ERR:format'),
  ('control: dinar fraction', ('12.5', 'en', 3), 12500)],
 [('regression group-shape 1', ('-1 1000,123', 'fr', 3), 'ERR:format'),
  ('regression group-shape 2', ('12.1345,123', 'de', 2), 'ERR:format'),
  ('partial repair guard 1', ('1234,567.00', 'en', 2), 'ERR:format'),
  ('control: dinar fraction', ('12.5', 'en', 3), 12500), ('control: swiss integer', ("1'000", 'ch', 0), 1000),
  ('control: french plain space', ('12 345,6', 'fr', 2), 1234560),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format')],
 [('regression group-shape 1', ('100,1000.1', 'en', 3), 'ERR:format'),
  ('regression group-shape 2', ('12,1345', 'en', 3), 'ERR:format'),
  ('partial repair guard 1', ('1234,567.00', 'en', 2), 'ERR:format'),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format'),
  ('control: unknown locale', ('12', 'it', 2), 'ERR:locale'),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450)],
 [('regression group-shape 1', ('100,1000.50', 'en', 2), 'ERR:format'),
  ('regression group-shape 2', ("1'1234'567.05", 'ch', 3), 'ERR:format'),
  ('partial repair guard 1', ('1234,567.00', 'en', 2), 'ERR:format'),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450),
  ('control: negative below one', ('-0,50', 'de', 2), -50),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450)]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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:
'1,23,4.00' is accepted as 1234.00 although it is not a valid grouped amount.

solve(text, locale, exp): parse a localized amount into integer minor units at exponent exp. Group/decimal separators: en ',' '.', de '.' ',', ch "'" '.', fr ' ' or U+202F and ','. An optional leading '-' marks a negative amount (including -0.xx). If grouping is used, the first group has 1-3 digits and every later group exactly 3. A decimal separator must be followed by digits. Fraction digits beyond exp are allowed only if they are zeros, otherwise 'ERR:precision'. Malformed text returns 'ERR:format'; an unknown locale 'ERR:locale'.

split: open-access


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

N = 1
observations = []
def solve(text, locale, exp):
    seps = {'en': (',', '.'), 'de': ('.', ','), 'ch': ("'", '.'), 'fr': (' \u202f', ',')}
    if locale not in seps: return 'ERR:locale'
    groups, dec = seps[locale]
    dig = lambda t: t != '' and all(c in '0123456789' for c in t)
    s = text.strip()
    neg = s.startswith('-')
    if neg: s = s[1:]
    whole, _, frac = s.partition(dec)
    for g in groups[1:]: whole = whole.replace(g, groups[0])
    parts = whole.split(groups[0])
    if not all(dig(p) for p in parts) or (dec in s and not dig(frac)): return 'ERR:format'
    if len(parts) > 1 and (len(parts[0]) > 3 or any(len(p) != 3 for p in parts[1:])): return 'ERR:format'
    if len(frac) > exp: return 'ERR:precision'
    frac = frac[:exp].ljust(exp, '0')
    v = int(''.join(parts)) * 10 ** exp + (int(frac) if frac else 0)
    return -v if neg else v
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression excess-fraction-zeros 1', ('1\u202f234,500', 'fr', 2), 123450),
  ('regression excess-fraction-zeros 2', ('100000,0010', 'fr', 3), 100000001),
  ('partial repair guard 1', ('12.345', 'en', 2), 'ERR:precision'),
  ('partial repair guard 2', ('999,50', 'fr', 0), 'ERR:precision'),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450),
  ('control: negative below one', ('-0,50', 'de', 2), -50),
  ('control: bad grouping', ('1,23,4.00', 'en', 2), 'ERR:format')],
 [('regression excess-fraction-zeros 1', ('-0,500', 'fr', 2), -50),
  ('regression excess-fraction-zeros 2', ('12.345,500', 'de', 2), 1234550),
  ('partial repair guard 1', ('999.500', 'en', 0), 'ERR:precision'),
  ('partial repair guard 2', ('-1.000,0010', 'de', 0), 'ERR:precision'),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450),
  ('control: excess precision', ('12.345', 'en', 2), 'ERR:precision'),
  ('control: bad grouping', ('1,23,4.00', 'en', 2), 'ERR:format'),
  ('control: dinar fraction', ('12.5', 'en', 3), 12500)],
 [('regression excess-fraction-zeros 1', ('12345.0010', 'en', 3), 12345001),
  ('regression excess-fraction-zeros 2', ('1\u202f000,0010', 'fr', 3), 1000001),
  ('partial repair guard 1', ('999,0010', 'fr', 2), 'ERR:precision'),
  ('partial repair guard 2', ('100000.5', 'ch', 0), 'ERR:precision'),
  ('control: dinar fraction', ('12.5', 'en', 3), 12500), ('control: swiss integer', ("1'000", 'ch', 0), 1000),
  ('control: french plain space', ('12 345,6', 'fr', 2), 1234560),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format')],
 [('regression excess-fraction-zeros 1', ('-999.0010', 'ch', 3), -999001),
  ('regression excess-fraction-zeros 2', ('1.234.567,500', 'de', 2), 123456750),
  ('partial repair guard 1', ('12345.500', 'ch', 0), 'ERR:precision'),
  ('partial repair guard 2', ('-1234567,123', 'fr', 0), 'ERR:precision'),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format'),
  ('control: unknown locale', ('12', 'it', 2), 'ERR:locale'),
  ('control: oversized first group', ('1234,567.00', 'en', 2), 'ERR:format'),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456)],
 [('regression excess-fraction-zeros 1', ('0,500', 'fr', 2), 50),
  ('regression excess-fraction-zeros 2', ('1.000,500', 'de', 2), 100050),
  ('partial repair guard 1', ('999,500', 'de', 0), 'ERR:precision'),
  ('partial repair guard 2', ('12345.123', 'en', 0), 'ERR:precision'),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450),
  ('control: negative below one', ('-0,50', 'de', 2), -50),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450)]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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(text, locale, exp):
    seps = {'en': (',', '.'), 'de': ('.', ','), 'ch': ("'", '.'), 'fr': (' \u202f', ',')}
    if locale not in seps: return 'ERR:locale'
    groups, dec = seps[locale]
    dig = lambda t: t != '' and all(c in '0123456789' for c in t)
    s = text.strip()
    neg = s.startswith('-')
    if neg: s = s[1:]
    whole, _, frac = s.partition(dec)
    for g in groups[1:]: whole = whole.replace(g, groups[0])
    parts = whole.split(groups[0])
    if not all(dig(p) for p in parts) or (dec in s and not dig(frac)): return 'ERR:format'
    if len(parts) > 1 and (len(parts[0]) > 3 or any(len(p) != 3 for p in parts[1:])): return 'ERR:format'
    pass
    frac = frac[:exp].ljust(exp, '0')
    v = int(''.join(parts)) * 10 ** exp + (int(frac) if frac else 0)
    return -v if neg else v
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression excess-fraction-zeros 1', ('1\u202f234,500', 'fr', 2), 123450),
  ('regression excess-fraction-zeros 2', ('100000,0010', 'fr', 3), 100000001),
  ('partial repair guard 1', ('12.345', 'en', 2), 'ERR:precision'),
  ('partial repair guard 2', ('999,50', 'fr', 0), 'ERR:precision'),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450),
  ('control: negative below one', ('-0,50', 'de', 2), -50),
  ('control: bad grouping', ('1,23,4.00', 'en', 2), 'ERR:format')],
 [('regression excess-fraction-zeros 1', ('-0,500', 'fr', 2), -50),
  ('regression excess-fraction-zeros 2', ('12.345,500', 'de', 2), 1234550),
  ('partial repair guard 1', ('999.500', 'en', 0), 'ERR:precision'),
  ('partial repair guard 2', ('-1.000,0010', 'de', 0), 'ERR:precision'),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450),
  ('control: excess precision', ('12.345', 'en', 2), 'ERR:precision'),
  ('control: bad grouping', ('1,23,4.00', 'en', 2), 'ERR:format'),
  ('control: dinar fraction', ('12.5', 'en', 3), 12500)],
 [('regression excess-fraction-zeros 1', ('12345.0010', 'en', 3), 12345001),
  ('regression excess-fraction-zeros 2', ('1\u202f000,0010', 'fr', 3), 1000001),
  ('partial repair guard 1', ('999,0010', 'fr', 2), 'ERR:precision'),
  ('partial repair guard 2', ('100000.5', 'ch', 0), 'ERR:precision'),
  ('control: dinar fraction', ('12.5', 'en', 3), 12500), ('control: swiss integer', ("1'000", 'ch', 0), 1000),
  ('control: french plain space', ('12 345,6', 'fr', 2), 1234560),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format')],
 [('regression excess-fraction-zeros 1', ('-999.0010', 'ch', 3), -999001),
  ('regression excess-fraction-zeros 2', ('1.234.567,500', 'de', 2), 123456750),
  ('partial repair guard 1', ('12345.500', 'ch', 0), 'ERR:precision'),
  ('partial repair guard 2', ('-1234567,123', 'fr', 0), 'ERR:precision'),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format'),
  ('control: unknown locale', ('12', 'it', 2), 'ERR:locale'),
  ('control: oversized first group', ('1234,567.00', 'en', 2), 'ERR:format'),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456)],
 [('regression excess-fraction-zeros 1', ('0,500', 'fr', 2), 50),
  ('regression excess-fraction-zeros 2', ('1.000,500', 'de', 2), 100050),
  ('partial repair guard 1', ('999,500', 'de', 0), 'ERR:precision'),
  ('partial repair guard 2', ('12345.123', 'en', 0), 'ERR:precision'),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450),
  ('control: negative below one', ('-0,50', 'de', 2), -50),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450)]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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:
'1 234,500' euros is refused although the extra digit is a zero.

solve(text, locale, exp): parse a localized amount into integer minor units at exponent exp. Group/decimal separators: en ',' '.', de '.' ',', ch "'" '.', fr ' ' or U+202F and ','. An optional leading '-' marks a negative amount (including -0.xx). If grouping is used, the first group has 1-3 digits and every later group exactly 3. A decimal separator must be followed by digits. Fraction digits beyond exp are allowed only if they are zeros, otherwise 'ERR:precision'. Malformed text returns 'ERR:format'; an unknown locale 'ERR:locale'.

split: open-access


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

N = 1
observations = []
def solve(text, locale, exp):
    seps = {'en': (',', '.'), 'de': ('.', ','), 'ch': ("'", '.'), 'fr': (' ', ',')}
    if locale not in seps: return 'ERR:locale'
    groups, dec = seps[locale]
    dig = lambda t: t != '' and all(c in '0123456789' for c in t)
    s = text.strip()
    neg = s.startswith('-')
    if neg: s = s[1:]
    whole, _, frac = s.partition(dec)
    for g in groups[1:]: whole = whole.replace(g, groups[0])
    parts = whole.split(groups[0])
    if not all(dig(p) for p in parts) or (dec in s and not dig(frac)): return 'ERR:format'
    if len(parts) > 1 and (len(parts[0]) > 3 or any(len(p) != 3 for p in parts[1:])): return 'ERR:format'
    if frac[exp:].strip('0'): return 'ERR:precision'
    frac = frac[:exp].ljust(exp, '0')
    v = int(''.join(parts)) * 10 ** exp + (int(frac) if frac else 0)
    return -v if neg else v
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression narrow-space-group 1', ('1\u202f234,500', 'fr', 2), 123450),
  ('regression narrow-space-group 2', ('-12\u202f345,6', 'fr', 2), -1234560),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450),
  ('control: negative below one', ('-0,50', 'de', 2), -50),
  ('control: excess precision', ('12.345', 'en', 2), 'ERR:precision')],
 [('regression narrow-space-group 1', ('-12\u202f345,05', 'fr', 2), -1234505),
  ('regression narrow-space-group 2', ('-1\u202f234\u202f567,05', 'fr', 2), -123456705),
  ('partial repair guard 1', ('1\xa0234\xa0567,0010', 'fr', 2), 'ERR:format'),
  ('partial repair guard 2', ('1\xa0234\xa0567,5', 'fr', 3), 'ERR:format'),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450),
  ('control: excess precision', ('12.345', 'en', 2), 'ERR:precision'),
  ('control: bad grouping', ('1,23,4.00', 'en', 2), 'ERR:format'),
  ('control: dinar fraction', ('12.5', 'en', 3), 12500)],
 [('regression narrow-space-group 1', ('100\u202f000,05', 'fr', 0), 'ERR:precision'),
  ('regression narrow-space-group 2', ('1\u202f000,0010', 'fr', 3), 1000001),
  ('partial repair guard 1', ('-12\u202f345,05', 'fr', 2), -1234505),
  ('partial repair guard 2', ('-1\u202f234\u202f567,05', 'fr', 2), -123456705),
  ('control: dinar fraction', ('12.5', 'en', 3), 12500), ('control: swiss integer', ("1'000", 'ch', 0), 1000),
  ('control: french plain space', ('12 345,6', 'fr', 2), 1234560),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format')],
 [('regression narrow-space-group 1', ('1\u202f234\u202f567,500', 'fr', 2), 123456750),
  ('regression narrow-space-group 2', ('-1\u202f234\u202f567,123', 'fr', 2), 'ERR:precision'),
  ('partial repair guard 1', ('1\xa0234\xa0567,123', 'fr', 0), 'ERR:format'),
  ('partial repair guard 2', ('100\u202f000,05', 'fr', 0), 'ERR:precision'),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format'),
  ('control: unknown locale', ('12', 'it', 2), 'ERR:locale'),
  ('control: oversized first group', ('1234,567.00', 'en', 2), 'ERR:format'),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456)],
 [('regression narrow-space-group 1', ('-1\u202f000,50', 'fr', 3), -1000500),
  ('regression narrow-space-group 2', ('-1\u202f234\u202f567', 'fr', 3), -1234567000),
  ('partial repair guard 1', ('100\xa0000,50', 'fr', 2), 'ERR:format'),
  ('partial repair guard 2', ('1\u202f000,0010', 'fr', 3), 1000001),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450),
  ('control: negative below one', ('-0,50', 'de', 2), -50),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450)]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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(text, locale, exp):
    seps = {'en': (',', '.'), 'de': ('.', ','), 'ch': ("'", '.'), 'fr': (' \u00a0', ',')}
    if locale not in seps: return 'ERR:locale'
    groups, dec = seps[locale]
    dig = lambda t: t != '' and all(c in '0123456789' for c in t)
    s = text.strip()
    neg = s.startswith('-')
    if neg: s = s[1:]
    whole, _, frac = s.partition(dec)
    for g in groups[1:]: whole = whole.replace(g, groups[0])
    parts = whole.split(groups[0])
    if not all(dig(p) for p in parts) or (dec in s and not dig(frac)): return 'ERR:format'
    if len(parts) > 1 and (len(parts[0]) > 3 or any(len(p) != 3 for p in parts[1:])): return 'ERR:format'
    if frac[exp:].strip('0'): return 'ERR:precision'
    frac = frac[:exp].ljust(exp, '0')
    v = int(''.join(parts)) * 10 ** exp + (int(frac) if frac else 0)
    return -v if neg else v
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression narrow-space-group 1', ('1\u202f234,500', 'fr', 2), 123450),
  ('regression narrow-space-group 2', ('-12\u202f345,6', 'fr', 2), -1234560),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450),
  ('control: negative below one', ('-0,50', 'de', 2), -50),
  ('control: excess precision', ('12.345', 'en', 2), 'ERR:precision')],
 [('regression narrow-space-group 1', ('-12\u202f345,05', 'fr', 2), -1234505),
  ('regression narrow-space-group 2', ('-1\u202f234\u202f567,05', 'fr', 2), -123456705),
  ('partial repair guard 1', ('1\xa0234\xa0567,0010', 'fr', 2), 'ERR:format'),
  ('partial repair guard 2', ('1\xa0234\xa0567,5', 'fr', 3), 'ERR:format'),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450),
  ('control: excess precision', ('12.345', 'en', 2), 'ERR:precision'),
  ('control: bad grouping', ('1,23,4.00', 'en', 2), 'ERR:format'),
  ('control: dinar fraction', ('12.5', 'en', 3), 12500)],
 [('regression narrow-space-group 1', ('100\u202f000,05', 'fr', 0), 'ERR:precision'),
  ('regression narrow-space-group 2', ('1\u202f000,0010', 'fr', 3), 1000001),
  ('partial repair guard 1', ('-12\u202f345,05', 'fr', 2), -1234505),
  ('partial repair guard 2', ('-1\u202f234\u202f567,05', 'fr', 2), -123456705),
  ('control: dinar fraction', ('12.5', 'en', 3), 12500), ('control: swiss integer', ("1'000", 'ch', 0), 1000),
  ('control: french plain space', ('12 345,6', 'fr', 2), 1234560),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format')],
 [('regression narrow-space-group 1', ('1\u202f234\u202f567,500', 'fr', 2), 123456750),
  ('regression narrow-space-group 2', ('-1\u202f234\u202f567,123', 'fr', 2), 'ERR:precision'),
  ('partial repair guard 1', ('1\xa0234\xa0567,123', 'fr', 0), 'ERR:format'),
  ('partial repair guard 2', ('100\u202f000,05', 'fr', 0), 'ERR:precision'),
  ('control: dangling separator', ('12.', 'en', 2), 'ERR:format'),
  ('control: unknown locale', ('12', 'it', 2), 'ERR:locale'),
  ('control: oversized first group', ('1234,567.00', 'en', 2), 'ERR:format'),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456)],
 [('regression narrow-space-group 1', ('-1\u202f000,50', 'fr', 3), -1000500),
  ('regression narrow-space-group 2', ('-1\u202f234\u202f567', 'fr', 3), -1234567000),
  ('partial repair guard 1', ('100\xa0000,50', 'fr', 2), 'ERR:format'),
  ('partial repair guard 2', ('1\u202f000,0010', 'fr', 3), 1000001),
  ('control: english grouping', ('1,234.56', 'en', 2), 123456),
  ('control: german short fraction', ('1.234,5', 'de', 2), 123450),
  ('control: negative below one', ('-0,50', 'de', 2), -50),
  ('control: narrow space with trailing zero', ('1\u202f234,500', 'fr', 2), 123450)]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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:
'1 234,50' from a locale-aware formatter fails to parse.

solve(text, locale, exp): parse a localized amount into integer minor units at exponent exp. Group/decimal separators: en ',' '.', de '.' ',', ch "'" '.', fr ' ' or U+202F and ','. An optional leading '-' marks a negative amount (including -0.xx). If grouping is used, the first group has 1-3 digits and every later group exactly 3. A decimal separator must be followed by digits. Fraction digits beyond exp are allowed only if they are zeros, otherwise 'ERR:precision'. Malformed text returns 'ERR:format'; an unknown locale 'ERR:locale'.

split: open-access


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

N = 1
observations = []
def solve(minor, ccy):
    spec = {'USD': ('$', '', ',', '.', 2), 'EUR': ('', ' €', '.', ',', 2), 'JPY': ('¥', '', ',', '.', 0), 'CHF': ('CHF ', '', "'", '.', 2), 'KWD': ('KD ', '', ',', '.', 3)}
    if ccy not in spec: return 'ERR:currency'
    pre, suf, grp, dec, e = spec[ccy]
    neg = minor < 0
    major, frac = divmod(minor, 10 ** e)
    digits = str(abs(major))
    groups = []
    while len(digits) > 3:
        groups.insert(0, digits[-3:])
        digits = digits[:-3]
    groups.insert(0, digits)
    body = grp.join(groups)
    if e: body += dec + str(frac).zfill(e)
    return ('-' if neg else '') + pre + body + suf
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression negative-divmod 1', (-150, 'USD'), '-$1.50'), ('regression negative-divmod 2', (-50, 'EUR'), '-0,50 €'),
  ('partial repair guard 2', (-50, 'KWD'), '-KD 0.050'), ('control: dollars', (123450, 'USD'), '$1,234.50'),
  ('control: yen', (1234567, 'JPY'), '¥1,234,567'), ('control: franc', (12345678, 'CHF'), "CHF 123'456.78"),
  ('control: dinar', (1005, 'KWD'), 'KD 1.005')],
 [('regression negative-divmod 1', (-50, 'KWD'), '-KD 0.050'),
  ('regression negative-divmod 2', (-105, 'KWD'), '-KD 0.105'), ('partial repair guard 2', (-50, 'CHF'), '-CHF 0.50'),
  ('control: yen', (1234567, 'JPY'), '¥1,234,567'), ('control: franc', (12345678, 'CHF'), "CHF 123'456.78"),
  ('control: dinar', (1005, 'KWD'), 'KD 1.005'), ('control: unknown', (5, 'GBP'), 'ERR:currency')],
 [('regression negative-divmod 1', (-123456, 'EUR'), '-1.234,56 €'),
  ('regression negative-divmod 2', (-987654321, 'USD'), '-$9,876,543.21'),
  ('partial repair guard 1', (-5, 'CHF'), '-CHF 0.05'), ('partial repair guard 2', (-5, 'USD'), '-$0.05'),
  ('control: unknown', (5, 'GBP'), 'ERR:currency'), ('control: million euros', (100000000, 'EUR'), '1.000.000,00 €'),
  ('control: zero yen', (0, 'JPY'), '¥0'), ('control: small dollars', (105, 'USD'), '$1.05')],
 [('regression negative-divmod 1', (-99999, 'KWD'), '-KD 99.999'),
  ('regression negative-divmod 2', (-99999, 'USD'), '-$999.99'), ('partial repair guard 1', (-5, 'KWD'), '-KD 0.005'),
  ('partial repair guard 2', (-999, 'KWD'), '-KD 0.999'), ('control: small dollars', (105, 'USD'), '$1.05'),
  ('control: negative yen', (-1000, 'JPY'), '-¥1,000'), ('control: dollars', (123450, 'USD'), '$1,234.50'),
  ('control: negative dollars', (-150, 'USD'), '-$1.50')],
 [('regression negative-divmod 1', (-50, 'CHF'), '-CHF 0.50'),
  ('regression negative-divmod 2', (-105, 'EUR'), '-1,05 €'), ('partial repair guard 1', (-50, 'USD'), '-$0.50'),
  ('partial repair guard 2', (-5, 'EUR'), '-0,05 €'), ('control: negative dollars', (-150, 'USD'), '-$1.50'),
  ('control: negative euro cents', (-50, 'EUR'), '-0,50 €'), ('control: yen', (1234567, 'JPY'), '¥1,234,567'),
  ('control: franc', (12345678, 'CHF'), "CHF 123'456.78")]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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(minor, ccy):
    spec = {'USD': ('$', '', ',', '.', 2), 'EUR': ('', ' €', '.', ',', 2), 'JPY': ('¥', '', ',', '.', 0), 'CHF': ('CHF ', '', "'", '.', 2), 'KWD': ('KD ', '', ',', '.', 3)}
    if ccy not in spec: return 'ERR:currency'
    pre, suf, grp, dec, e = spec[ccy]
    major, frac = int(minor / 10 ** e), abs(minor) % 10 ** e
    neg = major < 0
    digits = str(abs(major))
    groups = []
    while len(digits) > 3:
        groups.insert(0, digits[-3:])
        digits = digits[:-3]
    groups.insert(0, digits)
    body = grp.join(groups)
    if e: body += dec + str(frac).zfill(e)
    return ('-' if neg else '') + pre + body + suf
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression negative-divmod 1', (-150, 'USD'), '-$1.50'), ('regression negative-divmod 2', (-50, 'EUR'), '-0,50 €'),
  ('partial repair guard 2', (-50, 'KWD'), '-KD 0.050'), ('control: dollars', (123450, 'USD'), '$1,234.50'),
  ('control: yen', (1234567, 'JPY'), '¥1,234,567'), ('control: franc', (12345678, 'CHF'), "CHF 123'456.78"),
  ('control: dinar', (1005, 'KWD'), 'KD 1.005')],
 [('regression negative-divmod 1', (-50, 'KWD'), '-KD 0.050'),
  ('regression negative-divmod 2', (-105, 'KWD'), '-KD 0.105'), ('partial repair guard 2', (-50, 'CHF'), '-CHF 0.50'),
  ('control: yen', (1234567, 'JPY'), '¥1,234,567'), ('control: franc', (12345678, 'CHF'), "CHF 123'456.78"),
  ('control: dinar', (1005, 'KWD'), 'KD 1.005'), ('control: unknown', (5, 'GBP'), 'ERR:currency')],
 [('regression negative-divmod 1', (-123456, 'EUR'), '-1.234,56 €'),
  ('regression negative-divmod 2', (-987654321, 'USD'), '-$9,876,543.21'),
  ('partial repair guard 1', (-5, 'CHF'), '-CHF 0.05'), ('partial repair guard 2', (-5, 'USD'), '-$0.05'),
  ('control: unknown', (5, 'GBP'), 'ERR:currency'), ('control: million euros', (100000000, 'EUR'), '1.000.000,00 €'),
  ('control: zero yen', (0, 'JPY'), '¥0'), ('control: small dollars', (105, 'USD'), '$1.05')],
 [('regression negative-divmod 1', (-99999, 'KWD'), '-KD 99.999'),
  ('regression negative-divmod 2', (-99999, 'USD'), '-$999.99'), ('partial repair guard 1', (-5, 'KWD'), '-KD 0.005'),
  ('partial repair guard 2', (-999, 'KWD'), '-KD 0.999'), ('control: small dollars', (105, 'USD'), '$1.05'),
  ('control: negative yen', (-1000, 'JPY'), '-¥1,000'), ('control: dollars', (123450, 'USD'), '$1,234.50'),
  ('control: negative dollars', (-150, 'USD'), '-$1.50')],
 [('regression negative-divmod 1', (-50, 'CHF'), '-CHF 0.50'),
  ('regression negative-divmod 2', (-105, 'EUR'), '-1,05 €'), ('partial repair guard 1', (-50, 'USD'), '-$0.50'),
  ('partial repair guard 2', (-5, 'EUR'), '-0,05 €'), ('control: negative dollars', (-150, 'USD'), '-$1.50'),
  ('control: negative euro cents', (-50, 'EUR'), '-0,50 €'), ('control: yen', (1234567, 'JPY'), '¥1,234,567'),
  ('control: franc', (12345678, 'CHF'), "CHF 123'456.78")]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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:
-150 cents renders as '$-2.50'.

solve(minor, ccy): format integer minor units. Styles: USD '$' prefix, ',' groups, '.' decimal, 2 digits; EUR ' €' suffix, '.' groups, ',' decimal, 2; JPY '¥' prefix, ',' groups, 0 digits (no decimal separator); CHF 'CHF ' prefix, "'" groups, '.', 2; KWD 'KD ' prefix, ',', '.', 3. Group the whole part in threes from the right; the fraction is zero-padded to the exponent. A negative amount places '-' before everything. Unknown codes return 'ERR:currency'.

split: open-access


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

N = 1
observations = []
def solve(minor, ccy):
    spec = {'USD': ('$', '', ',', '.', 2), 'EUR': ('', ' €', '.', ',', 2), 'JPY': ('¥', '', ',', '.', 0), 'CHF': ('CHF ', '', "'", '.', 2), 'KWD': ('KD ', '', ',', '.', 3)}
    if ccy not in spec: return 'ERR:currency'
    pre, suf, grp, dec, e = spec[ccy]
    neg = minor < 0
    major, frac = divmod(abs(minor), 10 ** e)
    digits = str(major)
    groups = []
    while len(digits) > 3:
        groups.insert(0, digits[-3:])
        digits = digits[:-3]
    groups.insert(0, digits)
    body = grp.join(groups)
    if e: body += dec + str(frac).zfill(e)
    return pre + ('-' if neg else '') + body + suf
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression sign-placement 1', (-150, 'USD'), '-$1.50'), ('regression sign-placement 2', (-1000, 'JPY'), '-¥1,000'),
  ('partial repair guard 1', (-50, 'EUR'), '-0,50 €'), ('partial repair guard 2', (-1000000, 'EUR'), '-10.000,00 €'),
  ('control: dollars', (123450, 'USD'), '$1,234.50'), ('control: yen', (1234567, 'JPY'), '¥1,234,567'),
  ('control: franc', (12345678, 'CHF'), "CHF 123'456.78"), ('control: dinar', (1005, 'KWD'), 'KD 1.005')],
 [('regression sign-placement 1', (-100000, 'USD'), '-$1,000.00'),
  ('regression sign-placement 2', (-50, 'KWD'), '-KD 0.050'),
  ('partial repair guard 1', (-123456, 'EUR'), '-1.234,56 €'), ('partial repair guard 2', (-105, 'EUR'), '-1,05 €'),
  ('control: yen', (1234567, 'JPY'), '¥1,234,567'), ('control: franc', (12345678, 'CHF'), "CHF 123'456.78"),
  ('control: dinar', (1005, 'KWD'), 'KD 1.005'), ('control: unknown', (5, 'GBP'), 'ERR:currency')],
 [('regression sign-placement 1', (-105, 'KWD'), '-KD 0.105'), ('regression sign-placement 2', (-999, 'JPY'), '-¥999'),
  ('partial repair guard 1', (-1000, 'EUR'), '-10,00 €'), ('partial repair guard 2', (-99999, 'EUR'), '-999,99 €'),
  ('control: unknown', (5, 'GBP'), 'ERR:currency'), ('control: million euros', (100000000, 'EUR'), '1.000.000,00 €'),
  ('control: zero yen', (0, 'JPY'), '¥0'), ('control: small dollars', (105, 'USD'), '$1.05')],
 [('regression sign-placement 1', (-105, 'JPY'), '-¥105'),
  ('regression sign-placement 2', (-987654321, 'USD'), '-$9,876,543.21'),
  ('partial repair guard 1', (-987654321, 'EUR'), '-9.876.543,21 €'),
  ('partial repair guard 2', (-999, 'EUR'), '-9,99 €'), ('control: small dollars', (105, 'USD'), '$1.05'),
  ('control: negative yen', (-1000, 'JPY'), '-¥1,000'), ('control: dollars', (123450, 'USD'), '$1,234.50'),
  ('control: negative dollars', (-150, 'USD'), '-$1.50')],
 [('regression sign-placement 1', (-50, 'JPY'), '-¥50'),
  ('regression sign-placement 2', (-1000000, 'CHF'), "-CHF 10'000.00"),
  ('partial repair guard 1', (-100000, 'EUR'), '-1.000,00 €'), ('partial repair guard 2', (-5, 'EUR'), '-0,05 €'),
  ('control: negative dollars', (-150, 'USD'), '-$1.50'), ('control: negative euro cents', (-50, 'EUR'), '-0,50 €'),
  ('control: yen', (1234567, 'JPY'), '¥1,234,567'), ('control: franc', (12345678, 'CHF'), "CHF 123'456.78")]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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(minor, ccy):
    spec = {'USD': ('$', '', ',', '.', 2), 'EUR': ('', ' €', '.', ',', 2), 'JPY': ('¥', '', ',', '.', 0), 'CHF': ('CHF ', '', "'", '.', 2), 'KWD': ('KD ', '', ',', '.', 3)}
    if ccy not in spec: return 'ERR:currency'
    pre, suf, grp, dec, e = spec[ccy]
    neg = minor < 0
    major, frac = divmod(abs(minor), 10 ** e)
    digits = str(major)
    groups = []
    while len(digits) > 3:
        groups.insert(0, digits[-3:])
        digits = digits[:-3]
    groups.insert(0, digits)
    body = grp.join(groups)
    if e: body += dec + str(frac).zfill(e)
    return ('-' if neg and pre else '') + pre + body + suf
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression sign-placement 1', (-150, 'USD'), '-$1.50'), ('regression sign-placement 2', (-1000, 'JPY'), '-¥1,000'),
  ('partial repair guard 1', (-50, 'EUR'), '-0,50 €'), ('partial repair guard 2', (-1000000, 'EUR'), '-10.000,00 €'),
  ('control: dollars', (123450, 'USD'), '$1,234.50'), ('control: yen', (1234567, 'JPY'), '¥1,234,567'),
  ('control: franc', (12345678, 'CHF'), "CHF 123'456.78"), ('control: dinar', (1005, 'KWD'), 'KD 1.005')],
 [('regression sign-placement 1', (-100000, 'USD'), '-$1,000.00'),
  ('regression sign-placement 2', (-50, 'KWD'), '-KD 0.050'),
  ('partial repair guard 1', (-123456, 'EUR'), '-1.234,56 €'), ('partial repair guard 2', (-105, 'EUR'), '-1,05 €'),
  ('control: yen', (1234567, 'JPY'), '¥1,234,567'), ('control: franc', (12345678, 'CHF'), "CHF 123'456.78"),
  ('control: dinar', (1005, 'KWD'), 'KD 1.005'), ('control: unknown', (5, 'GBP'), 'ERR:currency')],
 [('regression sign-placement 1', (-105, 'KWD'), '-KD 0.105'), ('regression sign-placement 2', (-999, 'JPY'), '-¥999'),
  ('partial repair guard 1', (-1000, 'EUR'), '-10,00 €'), ('partial repair guard 2', (-99999, 'EUR'), '-999,99 €'),
  ('control: unknown', (5, 'GBP'), 'ERR:currency'), ('control: million euros', (100000000, 'EUR'), '1.000.000,00 €'),
  ('control: zero yen', (0, 'JPY'), '¥0'), ('control: small dollars', (105, 'USD'), '$1.05')],
 [('regression sign-placement 1', (-105, 'JPY'), '-¥105'),
  ('regression sign-placement 2', (-987654321, 'USD'), '-$9,876,543.21'),
  ('partial repair guard 1', (-987654321, 'EUR'), '-9.876.543,21 €'),
  ('partial repair guard 2', (-999, 'EUR'), '-9,99 €'), ('control: small dollars', (105, 'USD'), '$1.05'),
  ('control: negative yen', (-1000, 'JPY'), '-¥1,000'), ('control: dollars', (123450, 'USD'), '$1,234.50'),
  ('control: negative dollars', (-150, 'USD'), '-$1.50')],
 [('regression sign-placement 1', (-50, 'JPY'), '-¥50'),
  ('regression sign-placement 2', (-1000000, 'CHF'), "-CHF 10'000.00"),
  ('partial repair guard 1', (-100000, 'EUR'), '-1.000,00 €'), ('partial repair guard 2', (-5, 'EUR'), '-0,05 €'),
  ('control: negative dollars', (-150, 'USD'), '-$1.50'), ('control: negative euro cents', (-50, 'EUR'), '-0,50 €'),
  ('control: yen', (1234567, 'JPY'), '¥1,234,567'), ('control: franc', (12345678, 'CHF'), "CHF 123'456.78")]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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:
Refunds render as '$-1.50' instead of '-$1.50'.

solve(minor, ccy): format integer minor units. Styles: USD '$' prefix, ',' groups, '.' decimal, 2 digits; EUR ' €' suffix, '.' groups, ',' decimal, 2; JPY '¥' prefix, ',' groups, 0 digits (no decimal separator); CHF 'CHF ' prefix, "'" groups, '.', 2; KWD 'KD ' prefix, ',', '.', 3. Group the whole part in threes from the right; the fraction is zero-padded to the exponent. A negative amount places '-' before everything. Unknown codes return 'ERR:currency'.

split: open-access


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

N = 1
observations = []
def solve(minor, ccy):
    spec = {'USD': ('$', '', ',', '.', 2), 'EUR': ('', ' €', '.', ',', 2), 'JPY': ('¥', '', ',', '.', 0), 'CHF': ('CHF ', '', "'", '.', 2), 'KWD': ('KD ', '', ',', '.', 3)}
    if ccy not in spec: return 'ERR:currency'
    pre, suf, grp, dec, e = spec[ccy]
    neg = minor < 0
    major, frac = divmod(abs(minor), 10 ** e)
    digits = str(major)
    groups = [digits[i:i + 3] for i in range(0, len(digits), 3)]
    body = grp.join(groups)
    if e: body += dec + str(frac).zfill(e)
    return ('-' if neg else '') + pre + body + suf
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression grouping-direction 1', (123450, 'USD'), '$1,234.50'),
  ('regression grouping-direction 2', (1234567, 'JPY'), '¥1,234,567'),
  ('partial repair guard 1', (-50, 'EUR'), '-0,50 €'), ('partial repair guard 2', (0, 'JPY'), '¥0'),
  ('control: negative dollars', (-150, 'USD'), '-$1.50'), ('control: franc', (12345678, 'CHF'), "CHF 123'456.78"),
  ('control: dinar', (1005, 'KWD'), 'KD 1.005'), ('control: unknown', (5, 'GBP'), 'ERR:currency')],
 [('regression grouping-direction 1', (100000000, 'EUR'), '1.000.000,00 €'),
  ('regression grouping-direction 2', (-1000, 'JPY'), '-¥1,000'), ('partial repair guard 1', (999, 'KWD'), 'KD 0.999'),
  ('partial repair guard 2', (0, 'CHF'), 'CHF 0.00'), ('control: yen', (1234567, 'JPY'), '¥1,234,567'),
  ('control: franc', (12345678, 'CHF'), "CHF 123'456.78"), ('control: dinar', (1005, 'KWD'), 'KD 1.005'),
  ('control: unknown', (5, 'GBP'), 'ERR:currency')],
 [('regression grouping-direction 1', (-1000000, 'EUR'), '-10.000,00 €'),
  ('regression grouping-direction 2', (987654321, 'EUR'), '9.876.543,21 €'),
  ('partial repair guard 1', (-50, 'KWD'), '-KD 0.050'), ('partial repair guard 2', (5, 'CHF'), 'CHF 0.05'),
  ('control: unknown', (5, 'GBP'), 'ERR:currency'), ('control: million euros', (100000000, 'EUR'), '1.000.000,00 €'),
  ('control: zero yen', (0, 'JPY'), '¥0'), ('control: small dollars', (105, 'USD'), '$1.05')],
 [('regression grouping-direction 1', (-100000, 'USD'), '-$1,000.00'),
  ('regression grouping-direction 2', (99999, 'JPY'), '¥99,999'),
  ('partial repair guard 1', (-105, 'KWD'), '-KD 0.105'), ('partial repair guard 2', (50, 'EUR'), '0,50 €'),
  ('control: small dollars', (105, 'USD'), '$1.05'), ('control: negative yen', (-1000, 'JPY'), '-¥1,000'),
  ('control: dollars', (123450, 'USD'), '$1,234.50'), ('control: negative dollars', (-150, 'USD'), '-$1.50')],
 [('regression grouping-direction 1', (123456, 'USD'), '$1,234.56'),
  ('regression grouping-direction 2', (-123456, 'EUR'), '-1.234,56 €'),
  ('partial repair guard 1', (0, 'EUR'), '0,00 €'), ('partial repair guard 2', (50, 'USD'), '$0.50'),
  ('control: negative dollars', (-150, 'USD'), '-$1.50'), ('control: negative euro cents', (-50, 'EUR'), '-0,50 €'),
  ('control: yen', (1234567, 'JPY'), '¥1,234,567'), ('control: franc', (12345678, 'CHF'), "CHF 123'456.78")]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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(minor, ccy):
    spec = {'USD': ('$', '', ',', '.', 2), 'EUR': ('', ' €', '.', ',', 2), 'JPY': ('¥', '', ',', '.', 0), 'CHF': ('CHF ', '', "'", '.', 2), 'KWD': ('KD ', '', ',', '.', 3)}
    if ccy not in spec: return 'ERR:currency'
    pre, suf, grp, dec, e = spec[ccy]
    neg = minor < 0
    major, frac = divmod(abs(minor), 10 ** e)
    digits = str(major)
    d = digits.zfill((len(digits) + 2) // 3 * 3)
    groups = [d[i:i + 3] for i in range(0, len(d), 3)]
    groups[0] = groups[0].lstrip('0')
    body = grp.join(groups)
    if e: body += dec + str(frac).zfill(e)
    return ('-' if neg else '') + pre + body + suf
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression grouping-direction 1', (123450, 'USD'), '$1,234.50'),
  ('regression grouping-direction 2', (1234567, 'JPY'), '¥1,234,567'),
  ('partial repair guard 1', (-50, 'EUR'), '-0,50 €'), ('partial repair guard 2', (0, 'JPY'), '¥0'),
  ('control: negative dollars', (-150, 'USD'), '-$1.50'), ('control: franc', (12345678, 'CHF'), "CHF 123'456.78"),
  ('control: dinar', (1005, 'KWD'), 'KD 1.005'), ('control: unknown', (5, 'GBP'), 'ERR:currency')],
 [('regression grouping-direction 1', (100000000, 'EUR'), '1.000.000,00 €'),
  ('regression grouping-direction 2', (-1000, 'JPY'), '-¥1,000'), ('partial repair guard 1', (999, 'KWD'), 'KD 0.999'),
  ('partial repair guard 2', (0, 'CHF'), 'CHF 0.00'), ('control: yen', (1234567, 'JPY'), '¥1,234,567'),
  ('control: franc', (12345678, 'CHF'), "CHF 123'456.78"), ('control: dinar', (1005, 'KWD'), 'KD 1.005'),
  ('control: unknown', (5, 'GBP'), 'ERR:currency')],
 [('regression grouping-direction 1', (-1000000, 'EUR'), '-10.000,00 €'),
  ('regression grouping-direction 2', (987654321, 'EUR'), '9.876.543,21 €'),
  ('partial repair guard 1', (-50, 'KWD'), '-KD 0.050'), ('partial repair guard 2', (5, 'CHF'), 'CHF 0.05'),
  ('control: unknown', (5, 'GBP'), 'ERR:currency'), ('control: million euros', (100000000, 'EUR'), '1.000.000,00 €'),
  ('control: zero yen', (0, 'JPY'), '¥0'), ('control: small dollars', (105, 'USD'), '$1.05')],
 [('regression grouping-direction 1', (-100000, 'USD'), '-$1,000.00'),
  ('regression grouping-direction 2', (99999, 'JPY'), '¥99,999'),
  ('partial repair guard 1', (-105, 'KWD'), '-KD 0.105'), ('partial repair guard 2', (50, 'EUR'), '0,50 €'),
  ('control: small dollars', (105, 'USD'), '$1.05'), ('control: negative yen', (-1000, 'JPY'), '-¥1,000'),
  ('control: dollars', (123450, 'USD'), '$1,234.50'), ('control: negative dollars', (-150, 'USD'), '-$1.50')],
 [('regression grouping-direction 1', (123456, 'USD'), '$1,234.56'),
  ('regression grouping-direction 2', (-123456, 'EUR'), '-1.234,56 €'),
  ('partial repair guard 1', (0, 'EUR'), '0,00 €'), ('partial repair guard 2', (50, 'USD'), '$0.50'),
  ('control: negative dollars', (-150, 'USD'), '-$1.50'), ('control: negative euro cents', (-50, 'EUR'), '-0,50 €'),
  ('control: yen', (1234567, 'JPY'), '¥1,234,567'), ('control: franc', (12345678, 'CHF'), "CHF 123'456.78")]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*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:
1234 dollars renders as '$123,4.00'.

solve(minor, ccy): format integer minor units. Styles: USD '$' prefix, ',' groups, '.' decimal, 2 digits; EUR ' €' suffix, '.' groups, ',' decimal, 2; JPY '¥' prefix, ',' groups, 0 digits (no decimal separator); CHF 'CHF ' prefix, "'" groups, '.', 2; KWD 'KD ' prefix, ',', '.', 3. Group the whole part in threes from the right; the fraction is zero-padded to the exponent. A negative amount places '-' before everything. Unknown codes return 'ERR:currency'.

split: open-access