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(quotes, target):
    def per_usd(c):
        if c == 'USD': return Decimal(1)
        if 'USD' + c in quotes: return Decimal(quotes['USD' + c])
        if c + 'USD' in quotes: return (1 / Decimal(quotes[c + 'USD'])).quantize(Decimal('0.0001'))
        return None
    b, q = target[:3], target[3:]
    pb, pq = per_usd(b), per_usd(q)
    if pb is None or pq is None: return 'ERR:no-quote'
    return format((pq / pb).quantize(Decimal('0.000001'), rounding=ROUND_HALF_EVEN), 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression inverse-leg-precision 1',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURJPY'),
   '164.009395'),
  ('regression inverse-leg-precision 2',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'GBPEUR'),
   '1.167513'),
  ('partial repair guard 2',
   ({'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612', 'USDCAD': '1.3577'}, 'GBPCAD'),
   '1.717490'),
  ('control: direct usd base',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDJPY'),
   '151.370000'),
  ('control: usd quote',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'JPYUSD'),
   '0.006606'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote'),
  ('control: franc aussie',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'CHFAUD'),
   '1.718443')],
 [('regression inverse-leg-precision 1',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'CHFAUD'),
   '1.718443'),
  ('regression inverse-leg-precision 2',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDEUR'),
   '0.922935'),
  ('partial repair guard 1',
   ({'USDJPY': '151.37', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612', 'USDCAD': '1.3577'}, 'GBPJPY'),
   '191.483050'),
  ('partial repair guard 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'USDEUR': '0.9231'},
    'GBPCAD'),
   '1.717490'),
  ('control: usd quote',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'JPYUSD'),
   '0.006606'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote'),
  ('control: both orientations',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418'),
  ('control: euro yen',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURJPY'),
   '164.009395')],
 [('regression inverse-leg-precision 1',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'USDCHF': '0.8801', 'AUDUSD': '0.6612', 'USDEUR': '0.9231'}, 'AUDCHF'),
   '0.581922'),
  ('regression inverse-leg-precision 2',
   ({'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610'},
    'CHFGBP'),
   '0.898209'),
  ('partial repair guard 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610'},
    'GBPJPY'),
   '191.483050'),
  ('partial repair guard 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'USDEUR': '0.9231'},
    'GBPJPY'),
   '191.483050'),
  ('control: both orientations',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418'),
  ('control: usd to euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDEUR'),
   '0.922935'),
  ('control: euro yen',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURJPY'),
   '164.009395'),
  ('control: sterling euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'GBPEUR'),
   '1.167513')],
 [('regression inverse-leg-precision 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577'},
    'EURAUD'),
   '1.638687'),
  ('regression inverse-leg-precision 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577'},
    'USDGBP'),
   '0.790514'),
  ('partial repair guard 1',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'USDCAD': '1.3577'}, 'EURJPY'),
   '164.009395'),
  ('partial repair guard 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'GBPCHF'),
   '1.113326'),
  ('control: sterling euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'GBPEUR'),
   '1.167513'),
  ('control: direct usd base',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDJPY'),
   '151.370000'),
  ('control: usd quote',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'JPYUSD'),
   '0.006606'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote')],
 [('regression inverse-leg-precision 1',
   ({'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612', 'USDEUR': '0.9231'}, 'EURGBP'), '0.856369'),
  ('regression inverse-leg-precision 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577'},
    'CADGBP'),
   '0.582245'),
  ('partial repair guard 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577'},
    'GBPJPY'),
   '191.483050'),
  ('partial repair guard 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577'},
    'EURJPY'),
   '164.009395'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote'),
  ('control: franc aussie',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'CHFAUD'),
   '1.718443'),
  ('control: both orientations',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418'),
  ('control: usd to euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDEUR'),
   '0.922935')]]
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(quotes, target):
    def per_usd(c):
        if c == 'USD': return Decimal(1)
        if 'USD' + c in quotes: return Decimal(quotes['USD' + c])
        if c + 'USD' in quotes: return (1 / Decimal(quotes[c + 'USD'])).quantize(Decimal('0.00000001'))
        return None
    b, q = target[:3], target[3:]
    pb, pq = per_usd(b), per_usd(q)
    if pb is None or pq is None: return 'ERR:no-quote'
    return format((pq / pb).quantize(Decimal('0.000001'), rounding=ROUND_HALF_EVEN), 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression inverse-leg-precision 1',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURJPY'),
   '164.009395'),
  ('regression inverse-leg-precision 2',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'GBPEUR'),
   '1.167513'),
  ('partial repair guard 2',
   ({'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612', 'USDCAD': '1.3577'}, 'GBPCAD'),
   '1.717490'),
  ('control: direct usd base',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDJPY'),
   '151.370000'),
  ('control: usd quote',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'JPYUSD'),
   '0.006606'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote'),
  ('control: franc aussie',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'CHFAUD'),
   '1.718443')],
 [('regression inverse-leg-precision 1',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'CHFAUD'),
   '1.718443'),
  ('regression inverse-leg-precision 2',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDEUR'),
   '0.922935'),
  ('partial repair guard 1',
   ({'USDJPY': '151.37', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612', 'USDCAD': '1.3577'}, 'GBPJPY'),
   '191.483050'),
  ('partial repair guard 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'USDEUR': '0.9231'},
    'GBPCAD'),
   '1.717490'),
  ('control: usd quote',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'JPYUSD'),
   '0.006606'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote'),
  ('control: both orientations',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418'),
  ('control: euro yen',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURJPY'),
   '164.009395')],
 [('regression inverse-leg-precision 1',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'USDCHF': '0.8801', 'AUDUSD': '0.6612', 'USDEUR': '0.9231'}, 'AUDCHF'),
   '0.581922'),
  ('regression inverse-leg-precision 2',
   ({'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610'},
    'CHFGBP'),
   '0.898209'),
  ('partial repair guard 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610'},
    'GBPJPY'),
   '191.483050'),
  ('partial repair guard 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'USDEUR': '0.9231'},
    'GBPJPY'),
   '191.483050'),
  ('control: both orientations',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418'),
  ('control: usd to euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDEUR'),
   '0.922935'),
  ('control: euro yen',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURJPY'),
   '164.009395'),
  ('control: sterling euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'GBPEUR'),
   '1.167513')],
 [('regression inverse-leg-precision 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577'},
    'EURAUD'),
   '1.638687'),
  ('regression inverse-leg-precision 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577'},
    'USDGBP'),
   '0.790514'),
  ('partial repair guard 1',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'USDCAD': '1.3577'}, 'EURJPY'),
   '164.009395'),
  ('partial repair guard 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'GBPCHF'),
   '1.113326'),
  ('control: sterling euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'GBPEUR'),
   '1.167513'),
  ('control: direct usd base',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDJPY'),
   '151.370000'),
  ('control: usd quote',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'JPYUSD'),
   '0.006606'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote')],
 [('regression inverse-leg-precision 1',
   ({'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612', 'USDEUR': '0.9231'}, 'EURGBP'), '0.856369'),
  ('regression inverse-leg-precision 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577'},
    'CADGBP'),
   '0.582245'),
  ('partial repair guard 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577'},
    'GBPJPY'),
   '191.483050'),
  ('partial repair guard 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577'},
    'EURJPY'),
   '164.009395'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote'),
  ('control: franc aussie',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'CHFAUD'),
   '1.718443'),
  ('control: both orientations',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418'),
  ('control: usd to euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDEUR'),
   '0.922935')]]
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:
Crosses built from EURUSD or GBPUSD drift in the fourth significant digit.

solve(quotes, target): quotes maps six-letter pairs to rates (QUOTE units per BASE unit). For currency c, units per USD are: 1 for USD; quotes['USD'+c] if present (authoritative when both orientations exist); else 1/quotes[c+'USD']; else unknown. The target BBBQQQ rate = (QQQ per USD)/(BBB per USD), rounded half-even to 6 decimals and returned as a string; an unknown leg returns 'ERR:no-quote'.

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(quotes, target):
    def per_usd(c):
        pass
        if 'USD' + c in quotes: return Decimal(quotes['USD' + c])
        if c + 'USD' in quotes: return 1 / Decimal(quotes[c + 'USD'])
        return None
    b, q = target[:3], target[3:]
    pb, pq = per_usd(b), per_usd(q)
    if pb is None or pq is None: return 'ERR:no-quote'
    return format((pq / pb).quantize(Decimal('0.000001'), rounding=ROUND_HALF_EVEN), 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression usd-leg 1',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDJPY'),
   '151.370000'),
  ('regression usd-leg 2',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'JPYUSD'),
   '0.006606'),
  ('partial repair guard 2',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDEUR'),
   '0.922935'),
  ('control: euro yen',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURJPY'),
   '164.009395'),
  ('control: sterling euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'GBPEUR'),
   '1.167513'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote'),
  ('control: franc aussie',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'CHFAUD'),
   '1.718443')],
 [('regression usd-leg 1',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDEUR'),
   '0.922935'),
  ('regression usd-leg 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577'},
    'USDGBP'),
   '0.790514'),
  ('partial repair guard 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'USDEUR': '0.9231'},
    'USDCAD'),
   '1.357700'),
  ('control: usd quote',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'JPYUSD'),
   '0.006606'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote'),
  ('control: franc aussie',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'CHFAUD'),
   '1.718443'),
  ('control: both orientations',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418')],
 [('regression usd-leg 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'USDEUR': '0.9231'},
    'USDCAD'),
   '1.357700'),
  ('regression usd-leg 2',
   ({'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610',
     'USDEUR': '0.9231'},
    'EURUSD'),
   '1.083306'),
  ('partial repair guard 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'USDEUR': '0.9231'},
    'USDCHF'),
   '0.880100'),
  ('partial repair guard 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'JPYUSD': '0.006610',
     'USDEUR': '0.9231'},
    'USDGBP'),
   '0.790514'),
  ('control: both orientations',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418'),
  ('control: usd to euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDEUR'),
   '0.922935'),
  ('control: euro yen',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURJPY'),
   '164.009395'),
  ('control: sterling euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'GBPEUR'),
   '1.167513')],
 [('regression usd-leg 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'USDEUR': '0.9231'},
    'USDCHF'),
   '0.880100'),
  ('regression usd-leg 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610'},
    'EURUSD'),
   '1.083500'),
  ('partial repair guard 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577'},
    'USDCAD'),
   '1.357700'),
  ('partial repair guard 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'USDEUR': '0.9231'},
    'USDEUR'),
   '0.923100'),
  ('control: sterling euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'GBPEUR'),
   '1.167513'),
  ('control: direct usd base',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDJPY'),
   '151.370000'),
  ('control: usd quote',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'JPYUSD'),
   '0.006606'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote')],
 [('regression usd-leg 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610'},
    'CADUSD'),
   '0.736540'),
  ('regression usd-leg 2',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'CHFUSD'),
   '1.136235'),
  ('partial repair guard 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610'},
    'USDCHF'),
   '0.880100'),
  ('partial repair guard 2',
   ({'USDJPY': '151.37',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610'},
    'USDJPY'),
   '151.370000'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote'),
  ('control: franc aussie',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'CHFAUD'),
   '1.718443'),
  ('control: both orientations',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418'),
  ('control: usd to euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDEUR'),
   '0.922935')]]
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(quotes, target):
    def per_usd(c):
        if c == 'USD' and c == q: return Decimal(1)
        if 'USD' + c in quotes: return Decimal(quotes['USD' + c])
        if c + 'USD' in quotes: return 1 / Decimal(quotes[c + 'USD'])
        return None
    b, q = target[:3], target[3:]
    pb, pq = per_usd(b), per_usd(q)
    if pb is None or pq is None: return 'ERR:no-quote'
    return format((pq / pb).quantize(Decimal('0.000001'), rounding=ROUND_HALF_EVEN), 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression usd-leg 1',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDJPY'),
   '151.370000'),
  ('regression usd-leg 2',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'JPYUSD'),
   '0.006606'),
  ('partial repair guard 2',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDEUR'),
   '0.922935'),
  ('control: euro yen',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURJPY'),
   '164.009395'),
  ('control: sterling euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'GBPEUR'),
   '1.167513'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote'),
  ('control: franc aussie',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'CHFAUD'),
   '1.718443')],
 [('regression usd-leg 1',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDEUR'),
   '0.922935'),
  ('regression usd-leg 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577'},
    'USDGBP'),
   '0.790514'),
  ('partial repair guard 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'USDEUR': '0.9231'},
    'USDCAD'),
   '1.357700'),
  ('control: usd quote',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'JPYUSD'),
   '0.006606'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote'),
  ('control: franc aussie',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'CHFAUD'),
   '1.718443'),
  ('control: both orientations',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418')],
 [('regression usd-leg 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'USDEUR': '0.9231'},
    'USDCAD'),
   '1.357700'),
  ('regression usd-leg 2',
   ({'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610',
     'USDEUR': '0.9231'},
    'EURUSD'),
   '1.083306'),
  ('partial repair guard 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'USDEUR': '0.9231'},
    'USDCHF'),
   '0.880100'),
  ('partial repair guard 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'JPYUSD': '0.006610',
     'USDEUR': '0.9231'},
    'USDGBP'),
   '0.790514'),
  ('control: both orientations',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418'),
  ('control: usd to euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDEUR'),
   '0.922935'),
  ('control: euro yen',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURJPY'),
   '164.009395'),
  ('control: sterling euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'GBPEUR'),
   '1.167513')],
 [('regression usd-leg 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'USDEUR': '0.9231'},
    'USDCHF'),
   '0.880100'),
  ('regression usd-leg 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610'},
    'EURUSD'),
   '1.083500'),
  ('partial repair guard 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577'},
    'USDCAD'),
   '1.357700'),
  ('partial repair guard 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'USDEUR': '0.9231'},
    'USDEUR'),
   '0.923100'),
  ('control: sterling euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'GBPEUR'),
   '1.167513'),
  ('control: direct usd base',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDJPY'),
   '151.370000'),
  ('control: usd quote',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'JPYUSD'),
   '0.006606'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote')],
 [('regression usd-leg 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610'},
    'CADUSD'),
   '0.736540'),
  ('regression usd-leg 2',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'CHFUSD'),
   '1.136235'),
  ('partial repair guard 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610'},
    'USDCHF'),
   '0.880100'),
  ('partial repair guard 2',
   ({'USDJPY': '151.37',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610'},
    'USDJPY'),
   '151.370000'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote'),
  ('control: franc aussie',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'CHFAUD'),
   '1.718443'),
  ('control: both orientations',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418'),
  ('control: usd to euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDEUR'),
   '0.922935')]]
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:
USDJPY and JPYUSD targets fail with ERR:no-quote.

solve(quotes, target): quotes maps six-letter pairs to rates (QUOTE units per BASE unit). For currency c, units per USD are: 1 for USD; quotes['USD'+c] if present (authoritative when both orientations exist); else 1/quotes[c+'USD']; else unknown. The target BBBQQQ rate = (QQQ per USD)/(BBB per USD), rounded half-even to 6 decimals and returned as a string; an unknown leg returns 'ERR:no-quote'.

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(quotes, target):
    def per_usd(c):
        if c == 'USD': return Decimal(1)
        if c + 'USD' in quotes: return 1 / Decimal(quotes[c + 'USD'])
        if 'USD' + c in quotes: return Decimal(quotes['USD' + c])
        return None
    b, q = target[:3], target[3:]
    pb, pq = per_usd(b), per_usd(q)
    if pb is None or pq is None: return 'ERR:no-quote'
    return format((pq / pb).quantize(Decimal('0.000001'), rounding=ROUND_HALF_EVEN), 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression orientation-precedence 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418'),
  ('regression orientation-precedence 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'JPYUSD': '0.006610'},
    'EURJPY'),
   '164.009395'),
  ('control: euro yen',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURJPY'),
   '164.009395'),
  ('control: sterling euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'GBPEUR'),
   '1.167513'),
  ('control: direct usd base',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDJPY'),
   '151.370000'),
  ('control: usd quote',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'JPYUSD'),
   '0.006606')],
 [('regression orientation-precedence 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610',
     'USDEUR': '0.9231'},
    'JPYCAD'),
   '0.008969'),
  ('regression orientation-precedence 2',
   ({'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610',
     'USDEUR': '0.9231'},
    'EURUSD'),
   '1.083306'),
  ('control: usd quote',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'JPYUSD'),
   '0.006606'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote'),
  ('control: franc aussie',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'CHFAUD'),
   '1.718443'),
  ('control: both orientations',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418')],
 [('regression orientation-precedence 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610',
     'USDEUR': '0.9231'},
    'GBPEUR'),
   '1.167722'),
  ('regression orientation-precedence 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610',
     'USDEUR': '0.9231'},
    'JPYGBP'),
   '0.005222'),
  ('control: both orientations',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418'),
  ('control: usd to euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDEUR'),
   '0.922935'),
  ('control: euro yen',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURJPY'),
   '164.009395'),
  ('control: sterling euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'GBPEUR'),
   '1.167513')],
 [('regression orientation-precedence 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610'},
    'CADJPY'),
   '111.490020'),
  ('regression orientation-precedence 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'USDEUR': '0.9231'},
    'USDEUR'),
   '0.923100'),
  ('control: sterling euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'GBPEUR'),
   '1.167513'),
  ('control: direct usd base',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDJPY'),
   '151.370000'),
  ('control: usd quote',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'JPYUSD'),
   '0.006606'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote')],
 [('regression orientation-precedence 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610'},
    'JPYAUD'),
   '0.009991'),
  ('regression orientation-precedence 2',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'AUDUSD': '0.6612', 'USDCAD': '1.3577', 'JPYUSD': '0.006610'}, 'JPYUSD'),
   '0.006606'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote'),
  ('control: franc aussie',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'CHFAUD'),
   '1.718443'),
  ('control: both orientations',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418'),
  ('control: usd to euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDEUR'),
   '0.922935')]]
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(quotes, target):
    def per_usd(c):
        if c == 'USD': return Decimal(1)
        if 'USD' + c in quotes and c + 'USD' in quotes: return (Decimal(quotes['USD' + c]) + 1 / Decimal(quotes[c + 'USD'])) / 2
        if 'USD' + c in quotes: return Decimal(quotes['USD' + c])
        if c + 'USD' in quotes: return 1 / Decimal(quotes[c + 'USD'])
        return None
    b, q = target[:3], target[3:]
    pb, pq = per_usd(b), per_usd(q)
    if pb is None or pq is None: return 'ERR:no-quote'
    return format((pq / pb).quantize(Decimal('0.000001'), rounding=ROUND_HALF_EVEN), 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression orientation-precedence 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418'),
  ('regression orientation-precedence 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'JPYUSD': '0.006610'},
    'EURJPY'),
   '164.009395'),
  ('control: euro yen',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURJPY'),
   '164.009395'),
  ('control: sterling euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'GBPEUR'),
   '1.167513'),
  ('control: direct usd base',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDJPY'),
   '151.370000'),
  ('control: usd quote',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'JPYUSD'),
   '0.006606')],
 [('regression orientation-precedence 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610',
     'USDEUR': '0.9231'},
    'JPYCAD'),
   '0.008969'),
  ('regression orientation-precedence 2',
   ({'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610',
     'USDEUR': '0.9231'},
    'EURUSD'),
   '1.083306'),
  ('control: usd quote',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'JPYUSD'),
   '0.006606'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote'),
  ('control: franc aussie',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'CHFAUD'),
   '1.718443'),
  ('control: both orientations',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418')],
 [('regression orientation-precedence 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610',
     'USDEUR': '0.9231'},
    'GBPEUR'),
   '1.167722'),
  ('regression orientation-precedence 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610',
     'USDEUR': '0.9231'},
    'JPYGBP'),
   '0.005222'),
  ('control: both orientations',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418'),
  ('control: usd to euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDEUR'),
   '0.922935'),
  ('control: euro yen',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURJPY'),
   '164.009395'),
  ('control: sterling euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'GBPEUR'),
   '1.167513')],
 [('regression orientation-precedence 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610'},
    'CADJPY'),
   '111.490020'),
  ('regression orientation-precedence 2',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'USDEUR': '0.9231'},
    'USDEUR'),
   '0.923100'),
  ('control: sterling euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'GBPEUR'),
   '1.167513'),
  ('control: direct usd base',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDJPY'),
   '151.370000'),
  ('control: usd quote',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'JPYUSD'),
   '0.006606'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote')],
 [('regression orientation-precedence 1',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDCAD': '1.3577',
     'JPYUSD': '0.006610'},
    'JPYAUD'),
   '0.009991'),
  ('regression orientation-precedence 2',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'AUDUSD': '0.6612', 'USDCAD': '1.3577', 'JPYUSD': '0.006610'}, 'JPYUSD'),
   '0.006606'),
  ('control: missing leg',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'EURSEK'),
   'ERR:no-quote'),
  ('control: franc aussie',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'CHFAUD'),
   '1.718443'),
  ('control: both orientations',
   ({'USDJPY': '151.37',
     'EURUSD': '1.0835',
     'GBPUSD': '1.2650',
     'USDCHF': '0.8801',
     'AUDUSD': '0.6612',
     'USDEUR': '0.9231'},
    'EURCHF'),
   '0.953418'),
  ('control: usd to euro',
   ({'USDJPY': '151.37', 'EURUSD': '1.0835', 'GBPUSD': '1.2650', 'USDCHF': '0.8801', 'AUDUSD': '0.6612'}, 'USDEUR'),
   '0.922935')]]
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:
When both USDEUR and EURUSD are present, crosses use the inverse of EURUSD.

solve(quotes, target): quotes maps six-letter pairs to rates (QUOTE units per BASE unit). For currency c, units per USD are: 1 for USD; quotes['USD'+c] if present (authoritative when both orientations exist); else 1/quotes[c+'USD']; else unknown. The target BBBQQQ rate = (QQQ per USD)/(BBB per USD), rounded half-even to 6 decimals and returned as a string; an unknown leg returns 'ERR:no-quote'.

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(home_minor, rate, note, fee_minor):
    r = Decimal(rate)
    home = Decimal(home_minor) / 100
    units = (home * r / note).to_integral_value(rounding=ROUND_HALF_EVEN)
    foreign = int(units) * note
    if foreign == 0: return 'ERR:below-min-note'
    charged = int((Decimal(foreign) / r * 100).to_integral_value(rounding=ROUND_CEILING)) + fee_minor
    return [foreign, charged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression note-rounding 1', (1000, '0.92', 5, 0), [5, 544]),
  ('regression note-rounding 2', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801])],
 [('regression note-rounding 1', (130189, '821.097', 5, 0), [1068975, 130189]),
  ('regression note-rounding 2', (97345, '30.034', 10, 0), [29230, 97324]),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319])],
 [('regression note-rounding 1', (190855, '53583.55', 5, 500), [102266880, 191355]),
  ('regression note-rounding 2', (42899, '157086.46', 10000, 500), [67380000, 43394]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170])],
 [('regression note-rounding 1', (86470, '264.5122', 10000, 500), [220000, 83672]),
  ('regression note-rounding 2', (2489, '60494.94', 10, 0), [1505710, 2489]),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319])],
 [('regression note-rounding 1', (16458, '4444.030', 20, 0), [731380, 16458]),
  ('regression note-rounding 2', (100634, '12628.590', 10000, 250), [12700000, 100816]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170])]]
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(home_minor, rate, note, fee_minor):
    r = Decimal(rate)
    home = Decimal(home_minor) / 100
    units = (home * r / note).to_integral_value(rounding=ROUND_HALF_DOWN)
    foreign = int(units) * note
    if foreign == 0: return 'ERR:below-min-note'
    charged = int((Decimal(foreign) / r * 100).to_integral_value(rounding=ROUND_CEILING)) + fee_minor
    return [foreign, charged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression note-rounding 1', (1000, '0.92', 5, 0), [5, 544]),
  ('regression note-rounding 2', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801])],
 [('regression note-rounding 1', (130189, '821.097', 5, 0), [1068975, 130189]),
  ('regression note-rounding 2', (97345, '30.034', 10, 0), [29230, 97324]),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319])],
 [('regression note-rounding 1', (190855, '53583.55', 5, 500), [102266880, 191355]),
  ('regression note-rounding 2', (42899, '157086.46', 10000, 500), [67380000, 43394]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170])],
 [('regression note-rounding 1', (86470, '264.5122', 10000, 500), [220000, 83672]),
  ('regression note-rounding 2', (2489, '60494.94', 10, 0), [1505710, 2489]),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319])],
 [('regression note-rounding 1', (16458, '4444.030', 20, 0), [731380, 16458]),
  ('regression note-rounding 2', (100634, '12628.590', 10000, 250), [12700000, 100816]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170])]]
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:
The ATM dispenses more foreign currency than the customer requested.

solve(home_minor, rate, note, fee_minor): a request of home_minor home cents at rate foreign major units per home major unit is dispensed as the largest multiple of the smallest note not exceeding the converted amount (floor). If nothing can be dispensed return 'ERR:below-min-note'. The customer is charged the dispensed foreign amount converted back at the same rate, rounded UP to a home cent, plus fee_minor. Return [foreign_dispensed, charged_minor].

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(home_minor, rate, note, fee_minor):
    r = Decimal(rate)
    home = Decimal(home_minor) / 100
    units = (home * r / note).to_integral_value(rounding=ROUND_FLOOR)
    foreign = int(units) * note
    if foreign == 0: return 'ERR:below-min-note'
    charged = home_minor + fee_minor
    return [foreign, charged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression charge-basis 1', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('regression charge-basis 2', (1000, '0.92', 5, 0), [5, 544]),
  ('partial repair guard 2', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801])],
 [('regression charge-basis 1', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('regression charge-basis 2', (7777, '0.7893', 10, 199), [60, 7801]),
  ('partial repair guard 2', (20395, '717.2790', 20, 199), [146280, 20593]),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note')],
 [('regression charge-basis 1', (20395, '717.2790', 20, 199), [146280, 20593]),
  ('regression charge-basis 2', (97345, '30.034', 10, 0), [29230, 97324]),
  ('partial repair guard 1', (85223, '170817.58', 5, 500), [145575865, 85723]),
  ('partial repair guard 2', (127362, '68153.76', 10, 500), [86801990, 127862]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170])],
 [('regression charge-basis 1', (42899, '157086.46', 10000, 500), [67380000, 43394]),
  ('regression charge-basis 2', (86470, '264.5122', 10000, 500), [220000, 83672]),
  ('partial repair guard 1', (190855, '53583.55', 5, 500), [102266880, 191355]),
  ('partial repair guard 2', (13032, '1289.013', 20, 199), [167980, 13231]),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319])],
 [('regression charge-basis 1', (128997, '1606.6071', 1000, 250), [2072000, 129218]),
  ('regression charge-basis 2', (100634, '12628.590', 10000, 250), [12700000, 100816]),
  ('partial repair guard 1', (42899, '157086.46', 10000, 500), [67380000, 43394]),
  ('partial repair guard 2', (8787, '197046.01', 10, 250), [17314430, 9037]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170])]]
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(home_minor, rate, note, fee_minor):
    r = Decimal(rate)
    home = Decimal(home_minor) / 100
    units = (home * r / note).to_integral_value(rounding=ROUND_FLOOR)
    foreign = int(units) * note
    if foreign == 0: return 'ERR:below-min-note'
    charged = int((Decimal(foreign) / r * 100).to_integral_value(rounding=ROUND_CEILING))
    return [foreign, charged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression charge-basis 1', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('regression charge-basis 2', (1000, '0.92', 5, 0), [5, 544]),
  ('partial repair guard 2', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801])],
 [('regression charge-basis 1', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('regression charge-basis 2', (7777, '0.7893', 10, 199), [60, 7801]),
  ('partial repair guard 2', (20395, '717.2790', 20, 199), [146280, 20593]),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note')],
 [('regression charge-basis 1', (20395, '717.2790', 20, 199), [146280, 20593]),
  ('regression charge-basis 2', (97345, '30.034', 10, 0), [29230, 97324]),
  ('partial repair guard 1', (85223, '170817.58', 5, 500), [145575865, 85723]),
  ('partial repair guard 2', (127362, '68153.76', 10, 500), [86801990, 127862]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170])],
 [('regression charge-basis 1', (42899, '157086.46', 10000, 500), [67380000, 43394]),
  ('regression charge-basis 2', (86470, '264.5122', 10000, 500), [220000, 83672]),
  ('partial repair guard 1', (190855, '53583.55', 5, 500), [102266880, 191355]),
  ('partial repair guard 2', (13032, '1289.013', 20, 199), [167980, 13231]),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319])],
 [('regression charge-basis 1', (128997, '1606.6071', 1000, 250), [2072000, 129218]),
  ('regression charge-basis 2', (100634, '12628.590', 10000, 250), [12700000, 100816]),
  ('partial repair guard 1', (42899, '157086.46', 10000, 500), [67380000, 43394]),
  ('partial repair guard 2', (8787, '197046.01', 10, 250), [17314430, 9037]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170])]]
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:
Requesting 200.00 but receiving 30,000 yen charges 200.00 plus the fee.

solve(home_minor, rate, note, fee_minor): a request of home_minor home cents at rate foreign major units per home major unit is dispensed as the largest multiple of the smallest note not exceeding the converted amount (floor). If nothing can be dispensed return 'ERR:below-min-note'. The customer is charged the dispensed foreign amount converted back at the same rate, rounded UP to a home cent, plus fee_minor. Return [foreign_dispensed, charged_minor].

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(home_minor, rate, note, fee_minor):
    r = Decimal(rate)
    home = Decimal(home_minor) / 100
    units = (home * r / note).to_integral_value(rounding=ROUND_FLOOR)
    foreign = int(units) * note
    if foreign == 0: return 'ERR:below-min-note'
    charged = int((Decimal(foreign) / r * 100).to_integral_value(rounding=ROUND_HALF_EVEN)) + fee_minor
    return [foreign, charged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression charge-rounding 1', (1000, '0.92', 5, 0), [5, 544]),
  ('regression charge-rounding 2', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('partial repair guard 1', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801])],
 [('regression charge-rounding 1', (97345, '30.034', 10, 0), [29230, 97324]),
  ('regression charge-rounding 2', (128997, '1606.6071', 1000, 250), [2072000, 129218]),
  ('partial repair guard 1', (10870, '0.92', 10, 300), [100, 11170]),
  ('partial repair guard 2', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note')],
 [('regression charge-rounding 1', (100634, '12628.590', 10000, 250), [12700000, 100816]),
  ('regression charge-rounding 2', (51281, '1711.2188', 1000, 250), [877000, 51501]),
  ('partial repair guard 1', (7777, '0.7893', 10, 199), [60, 7801]),
  ('partial repair guard 2', (20395, '717.2790', 20, 199), [146280, 20593]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170])],
 [('regression charge-rounding 1', (48730, '311.732', 10000, 250), [150000, 48369]),
  ('regression charge-rounding 2', (197227, '597.2986', 5, 199), [1178030, 197426]),
  ('partial repair guard 1', (130189, '821.097', 5, 0), [1068975, 130189]),
  ('partial repair guard 2', (85223, '170817.58', 5, 500), [145575865, 85723]),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319])],
 [('regression charge-rounding 1', (79885, '2964.227', 50, 199), [2367950, 80084]),
  ('regression charge-rounding 2', (10316, '108100.20', 1000, 250), [11151000, 10566]),
  ('partial repair guard 1', (97345, '30.034', 10, 0), [29230, 97324]),
  ('partial repair guard 2', (127362, '68153.76', 10, 500), [86801990, 127862]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170])]]
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(home_minor, rate, note, fee_minor):
    r = Decimal(rate)
    home = Decimal(home_minor) / 100
    units = (home * r / note).to_integral_value(rounding=ROUND_FLOOR)
    foreign = int(units) * note
    if foreign == 0: return 'ERR:below-min-note'
    charged = int((Decimal(foreign) / r * 100).to_integral_value(rounding=ROUND_FLOOR)) + fee_minor
    return [foreign, charged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression charge-rounding 1', (1000, '0.92', 5, 0), [5, 544]),
  ('regression charge-rounding 2', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('partial repair guard 1', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801])],
 [('regression charge-rounding 1', (97345, '30.034', 10, 0), [29230, 97324]),
  ('regression charge-rounding 2', (128997, '1606.6071', 1000, 250), [2072000, 129218]),
  ('partial repair guard 1', (10870, '0.92', 10, 300), [100, 11170]),
  ('partial repair guard 2', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note')],
 [('regression charge-rounding 1', (100634, '12628.590', 10000, 250), [12700000, 100816]),
  ('regression charge-rounding 2', (51281, '1711.2188', 1000, 250), [877000, 51501]),
  ('partial repair guard 1', (7777, '0.7893', 10, 199), [60, 7801]),
  ('partial repair guard 2', (20395, '717.2790', 20, 199), [146280, 20593]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170])],
 [('regression charge-rounding 1', (48730, '311.732', 10000, 250), [150000, 48369]),
  ('regression charge-rounding 2', (197227, '597.2986', 5, 199), [1178030, 197426]),
  ('partial repair guard 1', (130189, '821.097', 5, 0), [1068975, 130189]),
  ('partial repair guard 2', (85223, '170817.58', 5, 500), [145575865, 85723]),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319])],
 [('regression charge-rounding 1', (79885, '2964.227', 50, 199), [2367950, 80084]),
  ('regression charge-rounding 2', (10316, '108100.20', 1000, 250), [11151000, 10566]),
  ('partial repair guard 1', (97345, '30.034', 10, 0), [29230, 97324]),
  ('partial repair guard 2', (127362, '68153.76', 10, 500), [86801990, 127862]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: below note', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170])]]
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:
The bank absorbs up to half a cent per withdrawal.

solve(home_minor, rate, note, fee_minor): a request of home_minor home cents at rate foreign major units per home major unit is dispensed as the largest multiple of the smallest note not exceeding the converted amount (floor). If nothing can be dispensed return 'ERR:below-min-note'. The customer is charged the dispensed foreign amount converted back at the same rate, rounded UP to a home cent, plus fee_minor. Return [foreign_dispensed, charged_minor].

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(home_minor, rate, note, fee_minor):
    r = Decimal(rate)
    home = Decimal(home_minor) / 100
    units = (home * r / note).to_integral_value(rounding=ROUND_FLOOR)
    foreign = int(units) * note
    pass
    charged = int((Decimal(foreign) / r * 100).to_integral_value(rounding=ROUND_CEILING)) + fee_minor
    return [foreign, charged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression zero-dispense 1', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('regression zero-dispense 2', (100, '0.7893', 10, 199), 'ERR:below-min-note'),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816])],
 [('regression zero-dispense 1', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('regression zero-dispense 2', (100, '0.7893', 10, 199), 'ERR:below-min-note'),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319])],
 [('regression zero-dispense 1', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('regression zero-dispense 2', (100, '0.7893', 10, 199), 'ERR:below-min-note'),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816])],
 [('regression zero-dispense 1', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('regression zero-dispense 2', (100, '0.7893', 10, 199), 'ERR:below-min-note'),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319])],
 [('regression zero-dispense 1', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('regression zero-dispense 2', (100, '0.7893', 10, 199), 'ERR:below-min-note'),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816])]]
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(home_minor, rate, note, fee_minor):
    r = Decimal(rate)
    home = Decimal(home_minor) / 100
    units = (home * r / note).to_integral_value(rounding=ROUND_FLOOR)
    foreign = int(units) * note
    if foreign == 0: return [0, 0]
    charged = int((Decimal(foreign) / r * 100).to_integral_value(rounding=ROUND_CEILING)) + fee_minor
    return [foreign, charged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression zero-dispense 1', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('regression zero-dispense 2', (100, '0.7893', 10, 199), 'ERR:below-min-note'),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816])],
 [('regression zero-dispense 1', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('regression zero-dispense 2', (100, '0.7893', 10, 199), 'ERR:below-min-note'),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319])],
 [('regression zero-dispense 1', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('regression zero-dispense 2', (100, '0.7893', 10, 199), 'ERR:below-min-note'),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816])],
 [('regression zero-dispense 1', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('regression zero-dispense 2', (100, '0.7893', 10, 199), 'ERR:below-min-note'),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816]),
  ('control: sterling tens', (7777, '0.7893', 10, 199), [60, 7801]),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319])],
 [('regression zero-dispense 1', (500, '0.92', 5, 250), 'ERR:below-min-note'),
  ('regression zero-dispense 2', (100, '0.7893', 10, 199), 'ERR:below-min-note'),
  ('control: yen notes', (20000, '151.37', 1000, 500), [30000, 20319]),
  ('control: euro fives', (1000, '0.92', 5, 0), [5, 544]),
  ('control: exact multiple', (10870, '0.92', 10, 300), [100, 11170]),
  ('control: big notes', (100000, '1352.5', 10000, 0), [1350000, 99816])]]
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:
The customer pays the ATM fee for a withdrawal that dispensed nothing.

solve(home_minor, rate, note, fee_minor): a request of home_minor home cents at rate foreign major units per home major unit is dispensed as the largest multiple of the smallest note not exceeding the converted amount (floor). If nothing can be dispensed return 'ERR:below-min-note'. The customer is charged the dispensed foreign amount converted back at the same rate, rounded UP to a home cent, plus fee_minor. Return [foreign_dispensed, charged_minor].

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(price, rate, ccy):
    raw = Decimal(price) * Decimal(rate)
    if ccy == 'JPY':
        c = (raw / 10).to_integral_value(rounding=ROUND_CEILING) * 10 - 2
        if c < raw: c += 10
        return format(c, 'f')
    c = raw.to_integral_value(rounding=ROUND_CEILING) - Decimal('0.01')
    return format(c, 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression whole-unit-boundary 1', ('12.00', '1', 'EUR'), '12.99'),
  ('regression whole-unit-boundary 2', ('12.995', '1', 'EUR'), '13.99'),
  ('partial repair guard 2', ('11.994', '1', 'USD'), '12.99'),
  ('control: already charm', ('11.99', '1', 'EUR'), '11.99'), ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248'),
  ('control: yen exact ending', ('1238', '1', 'JPY'), '1238')],
 [('regression whole-unit-boundary 1', ('11.994', '1', 'USD'), '12.99'),
  ('regression whole-unit-boundary 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('partial repair guard 2', ('1671.9996', '1', 'USD'), '1672.99'),
  ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248'),
  ('control: yen exact ending', ('1238', '1', 'JPY'), '1238'),
  ('control: converted euro', ('10.00', '0.92', 'EUR'), '9.99')],
 [('regression whole-unit-boundary 1', ('1671.9996', '1', 'USD'), '1672.99'),
  ('regression whole-unit-boundary 2', ('2820.995', '1', 'USD'), '2821.99'),
  ('partial repair guard 2', ('2931.999', '1', 'EUR'), '2932.99'),
  ('control: converted euro', ('10.00', '0.92', 'EUR'), '9.99'),
  ('control: just above charm', ('11.994', '1', 'USD'), '12.99'),
  ('control: sub-cent above', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: yen converted', ('9.99', '151.37', 'JPY'), '1518')],
 [('regression whole-unit-boundary 1', ('2931.999', '1', 'EUR'), '2932.99'),
  ('regression whole-unit-boundary 2', ('1682.999', '1', 'GBP'), '1683.99'),
  ('partial repair guard 2', ('2543.999', '1', 'USD'), '2544.99'),
  ('control: yen converted', ('9.99', '151.37', 'JPY'), '1518'),
  ('control: whole number', ('12.00', '1', 'EUR'), '12.99'), ('control: already charm', ('11.99', '1', 'EUR'), '11.99'),
  ('control: above charm', ('12.995', '1', 'EUR'), '13.99')],
 [('regression whole-unit-boundary 1', ('2543.999', '1', 'USD'), '2544.99'),
  ('regression whole-unit-boundary 2', ('2655.9996', '1', 'GBP'), '2656.99'),
  ('partial repair guard 2', ('1127.995', '1', 'USD'), '1128.99'),
  ('control: above charm', ('12.995', '1', 'EUR'), '13.99'), ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248'),
  ('control: yen exact ending', ('1238', '1', 'JPY'), '1238')]]
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(price, rate, ccy):
    raw = Decimal(price) * Decimal(rate)
    if ccy == 'JPY':
        c = (raw / 10).to_integral_value(rounding=ROUND_CEILING) * 10 - 2
        if c < raw: c += 10
        return format(c, 'f')
    c = raw.to_integral_value(rounding=ROUND_CEILING) - Decimal('0.01')
    if raw == raw.to_integral_value(): c += 1
    return format(c, 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression whole-unit-boundary 1', ('12.00', '1', 'EUR'), '12.99'),
  ('regression whole-unit-boundary 2', ('12.995', '1', 'EUR'), '13.99'),
  ('partial repair guard 2', ('11.994', '1', 'USD'), '12.99'),
  ('control: already charm', ('11.99', '1', 'EUR'), '11.99'), ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248'),
  ('control: yen exact ending', ('1238', '1', 'JPY'), '1238')],
 [('regression whole-unit-boundary 1', ('11.994', '1', 'USD'), '12.99'),
  ('regression whole-unit-boundary 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('partial repair guard 2', ('1671.9996', '1', 'USD'), '1672.99'),
  ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248'),
  ('control: yen exact ending', ('1238', '1', 'JPY'), '1238'),
  ('control: converted euro', ('10.00', '0.92', 'EUR'), '9.99')],
 [('regression whole-unit-boundary 1', ('1671.9996', '1', 'USD'), '1672.99'),
  ('regression whole-unit-boundary 2', ('2820.995', '1', 'USD'), '2821.99'),
  ('partial repair guard 2', ('2931.999', '1', 'EUR'), '2932.99'),
  ('control: converted euro', ('10.00', '0.92', 'EUR'), '9.99'),
  ('control: just above charm', ('11.994', '1', 'USD'), '12.99'),
  ('control: sub-cent above', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: yen converted', ('9.99', '151.37', 'JPY'), '1518')],
 [('regression whole-unit-boundary 1', ('2931.999', '1', 'EUR'), '2932.99'),
  ('regression whole-unit-boundary 2', ('1682.999', '1', 'GBP'), '1683.99'),
  ('partial repair guard 2', ('2543.999', '1', 'USD'), '2544.99'),
  ('control: yen converted', ('9.99', '151.37', 'JPY'), '1518'),
  ('control: whole number', ('12.00', '1', 'EUR'), '12.99'), ('control: already charm', ('11.99', '1', 'EUR'), '11.99'),
  ('control: above charm', ('12.995', '1', 'EUR'), '13.99')],
 [('regression whole-unit-boundary 1', ('2543.999', '1', 'USD'), '2544.99'),
  ('regression whole-unit-boundary 2', ('2655.9996', '1', 'GBP'), '2656.99'),
  ('partial repair guard 2', ('1127.995', '1', 'USD'), '1128.99'),
  ('control: above charm', ('12.995', '1', 'EUR'), '13.99'), ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248'),
  ('control: yen exact ending', ('1238', '1', 'JPY'), '1238')]]
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 converted price of exactly 12.00 is listed at 11.99, below the converted value.

solve(price, rate, ccy): a price list converted at rate is re-priced to the smallest charm price not below the exact converted value raw = price*rate. For JPY, charm prices end in 8 (…8 yen, i.e. 10k-2). For other currencies, charm prices end in .99. Return the charm price as a plain string.

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(price, rate, ccy):
    raw = Decimal(price) * Decimal(rate)
    if ccy == 'JPY':
        c = (raw / 10).to_integral_value(rounding=ROUND_CEILING) * 10 - 2
        if c < raw: c += 10
        return format(c, 'f')
    c = raw.to_integral_value(rounding=ROUND_FLOOR) + Decimal('0.99')
    if c <= raw: c += 1
    return format(c, 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression exact-charm-kept 1', ('11.99', '1', 'EUR'), '11.99'),
  ('regression exact-charm-kept 2', ('132.99', '1', 'GBP'), '132.99'),
  ('partial repair guard 1', ('11.994', '1', 'USD'), '12.99'),
  ('partial repair guard 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: whole number', ('12.00', '1', 'EUR'), '12.99'), ('control: above charm', ('12.995', '1', 'EUR'), '13.99'),
  ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248')],
 [('regression exact-charm-kept 1', ('2759.99', '1', 'USD'), '2759.99'),
  ('regression exact-charm-kept 2', ('2699.99', '1', 'GBP'), '2699.99'),
  ('partial repair guard 1', ('11.994', '1', 'USD'), '12.99'),
  ('partial repair guard 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248'),
  ('control: yen exact ending', ('1238', '1', 'JPY'), '1238'),
  ('control: converted euro', ('10.00', '0.92', 'EUR'), '9.99')],
 [('regression exact-charm-kept 1', ('2772.99', '1', 'EUR'), '2772.99'),
  ('regression exact-charm-kept 2', ('632.99', '1', 'USD'), '632.99'),
  ('partial repair guard 1', ('11.994', '1', 'USD'), '12.99'),
  ('partial repair guard 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: converted euro', ('10.00', '0.92', 'EUR'), '9.99'),
  ('control: yen converted', ('9.99', '151.37', 'JPY'), '1518'),
  ('control: whole number', ('12.00', '1', 'EUR'), '12.99'),
  ('control: already charm', ('11.99', '1', 'EUR'), '11.99')],
 [('regression exact-charm-kept 1', ('1442.99', '1', 'USD'), '1442.99'),
  ('regression exact-charm-kept 2', ('1492.99', '1', 'EUR'), '1492.99'),
  ('partial repair guard 1', ('11.994', '1', 'USD'), '12.99'),
  ('partial repair guard 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: yen converted', ('9.99', '151.37', 'JPY'), '1518'),
  ('control: whole number', ('12.00', '1', 'EUR'), '12.99'), ('control: already charm', ('11.99', '1', 'EUR'), '11.99'),
  ('control: above charm', ('12.995', '1', 'EUR'), '13.99')],
 [('regression exact-charm-kept 1', ('1302.99', '1', 'USD'), '1302.99'),
  ('regression exact-charm-kept 2', ('788.99', '1', 'GBP'), '788.99'),
  ('partial repair guard 1', ('11.994', '1', 'USD'), '12.99'),
  ('partial repair guard 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: above charm', ('12.995', '1', 'EUR'), '13.99'), ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248'),
  ('control: yen exact ending', ('1238', '1', 'JPY'), '1238')]]
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(price, rate, ccy):
    raw = Decimal(price) * Decimal(rate)
    if ccy == 'JPY':
        c = (raw / 10).to_integral_value(rounding=ROUND_CEILING) * 10 - 2
        if c < raw: c += 10
        return format(c, 'f')
    c = raw.to_integral_value(rounding=ROUND_FLOOR) + Decimal('0.99')
    if c < raw.quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN): c += 1
    return format(c, 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression exact-charm-kept 1', ('11.99', '1', 'EUR'), '11.99'),
  ('regression exact-charm-kept 2', ('132.99', '1', 'GBP'), '132.99'),
  ('partial repair guard 1', ('11.994', '1', 'USD'), '12.99'),
  ('partial repair guard 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: whole number', ('12.00', '1', 'EUR'), '12.99'), ('control: above charm', ('12.995', '1', 'EUR'), '13.99'),
  ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248')],
 [('regression exact-charm-kept 1', ('2759.99', '1', 'USD'), '2759.99'),
  ('regression exact-charm-kept 2', ('2699.99', '1', 'GBP'), '2699.99'),
  ('partial repair guard 1', ('11.994', '1', 'USD'), '12.99'),
  ('partial repair guard 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248'),
  ('control: yen exact ending', ('1238', '1', 'JPY'), '1238'),
  ('control: converted euro', ('10.00', '0.92', 'EUR'), '9.99')],
 [('regression exact-charm-kept 1', ('2772.99', '1', 'EUR'), '2772.99'),
  ('regression exact-charm-kept 2', ('632.99', '1', 'USD'), '632.99'),
  ('partial repair guard 1', ('11.994', '1', 'USD'), '12.99'),
  ('partial repair guard 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: converted euro', ('10.00', '0.92', 'EUR'), '9.99'),
  ('control: yen converted', ('9.99', '151.37', 'JPY'), '1518'),
  ('control: whole number', ('12.00', '1', 'EUR'), '12.99'),
  ('control: already charm', ('11.99', '1', 'EUR'), '11.99')],
 [('regression exact-charm-kept 1', ('1442.99', '1', 'USD'), '1442.99'),
  ('regression exact-charm-kept 2', ('1492.99', '1', 'EUR'), '1492.99'),
  ('partial repair guard 1', ('11.994', '1', 'USD'), '12.99'),
  ('partial repair guard 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: yen converted', ('9.99', '151.37', 'JPY'), '1518'),
  ('control: whole number', ('12.00', '1', 'EUR'), '12.99'), ('control: already charm', ('11.99', '1', 'EUR'), '11.99'),
  ('control: above charm', ('12.995', '1', 'EUR'), '13.99')],
 [('regression exact-charm-kept 1', ('1302.99', '1', 'USD'), '1302.99'),
  ('regression exact-charm-kept 2', ('788.99', '1', 'GBP'), '788.99'),
  ('partial repair guard 1', ('11.994', '1', 'USD'), '12.99'),
  ('partial repair guard 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: above charm', ('12.995', '1', 'EUR'), '13.99'), ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248'),
  ('control: yen exact ending', ('1238', '1', 'JPY'), '1238')]]
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:
11.99 converts to 12.99 even though 11.99 is already a valid charm price.

solve(price, rate, ccy): a price list converted at rate is re-priced to the smallest charm price not below the exact converted value raw = price*rate. For JPY, charm prices end in 8 (…8 yen, i.e. 10k-2). For other currencies, charm prices end in .99. Return the charm price as a plain string.

split: open-access