broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    R='A23456789TJQK'
    def best(h):
        for n in range(4,0,-1):
            cands=[]
            for sub in itertools.combinations(h,n):
                if len({c[0] for c in sub})==n and len({c[1] for c in sub})==n:
                    cands.append(sorted((R.index(c[0])+1 for c in sub), reverse=True))
            if cands: return (n, min(cands))
    a,b=best(x[0]),best(x[1])
    if a[0]!=b[0]: return 1 if a[0]>b[0] else -1
    if a[1]==b[1]: return 0
    return 1 if a[1]>b[1] else -1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('four-card badugi vs three', [['Ac', '2d', '3h', '4s'], ['Ac', '2c', '3h', '4s']], 1),
  ('paired rank different suits', [['Ac', 'Ad', '3h', '4s'], ['5c', '6d', '7h', 'Ks']], -1),
  ('lower badugi wins', [['Ac', '2d', '3h', '8s'], ['Ac', '2d', '4h', '7s']], -1),
  ('equal badugis', [['Ac', '2d', '3h', '4s'], ['Ad', '2c', '3s', '4h']], 0),
  ('best three-card subset', [['Kc', '2c', '3h', '4s'], ['5c', '6c', '7h', '8s']], 1),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('king high badugi vs three', [['Kc', 'Qd', 'Jh', 'Ts'], ['Ac', '2c', '3d', '4h']], 1),
  ('lowest card trap', [['Ac', '5d', '6h', '7s'], ['2c', '3d', '4h', '8s']], 1)],
 [('four-card badugi vs three', [['Ac', '2d', '3h', '4s'], ['Ac', '2c', '3h', '4s']], 1),
  ('lower badugi wins', [['Ac', '2d', '3h', '8s'], ['Ac', '2d', '4h', '7s']], -1),
  ('best three-card subset', [['Kc', '2c', '3h', '4s'], ['5c', '6c', '7h', '8s']], 1),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('king high badugi vs three', [['Kc', 'Qd', 'Jh', 'Ts'], ['Ac', '2c', '3d', '4h']], 1),
  ('lowest card trap', [['Ac', '5d', '6h', '7s'], ['2c', '3d', '4h', '8s']], 1),
  ('one-card hands', [['Ac', '2c', '3c', '4c'], ['5d', '6d', '7d', '8d']], 1),
  ('suit pair plus rank pair', [['2c', '2d', '5c', '9h'], ['3c', '4c', '6d', 'Th']], 1)],
 [('four-card badugi vs three', [['Ac', '2d', '3h', '4s'], ['Ac', '2c', '3h', '4s']], 1),
  ('paired rank different suits', [['Ac', 'Ad', '3h', '4s'], ['5c', '6d', '7h', 'Ks']], -1),
  ('equal badugis', [['Ac', '2d', '3h', '4s'], ['Ad', '2c', '3s', '4h']], 0),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('king high badugi vs three', [['Kc', 'Qd', 'Jh', 'Ts'], ['Ac', '2c', '3d', '4h']], 1),
  ('lowest card trap', [['Ac', '5d', '6h', '7s'], ['2c', '3d', '4h', '8s']], 1),
  ('one-card hands', [['Ac', '2c', '3c', '4c'], ['5d', '6d', '7d', '8d']], 1),
  ('suit pair plus rank pair', [['2c', '2d', '5c', '9h'], ['3c', '4c', '6d', 'Th']], 1)],
 [('four-card badugi vs three', [['Ac', '2d', '3h', '4s'], ['Ac', '2c', '3h', '4s']], 1),
  ('paired rank different suits', [['Ac', 'Ad', '3h', '4s'], ['5c', '6d', '7h', 'Ks']], -1),
  ('equal badugis', [['Ac', '2d', '3h', '4s'], ['Ad', '2c', '3s', '4h']], 0),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('king high badugi vs three', [['Kc', 'Qd', 'Jh', 'Ts'], ['Ac', '2c', '3d', '4h']], 1),
  ('lowest card trap', [['Ac', '5d', '6h', '7s'], ['2c', '3d', '4h', '8s']], 1),
  ('one-card hands', [['Ac', '2c', '3c', '4c'], ['5d', '6d', '7d', '8d']], 1),
  ('suit pair plus rank pair', [['2c', '2d', '5c', '9h'], ['3c', '4c', '6d', 'Th']], 1)],
 [('lower badugi wins', [['Ac', '2d', '3h', '8s'], ['Ac', '2d', '4h', '7s']], -1),
  ('equal badugis', [['Ac', '2d', '3h', '4s'], ['Ad', '2c', '3s', '4h']], 0),
  ('best three-card subset', [['Kc', '2c', '3h', '4s'], ['5c', '6c', '7h', '8s']], 1),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('king high badugi vs three', [['Kc', 'Qd', 'Jh', 'Ts'], ['Ac', '2c', '3d', '4h']], 1),
  ('lowest card trap', [['Ac', '5d', '6h', '7s'], ['2c', '3d', '4h', '8s']], 1),
  ('one-card hands', [['Ac', '2c', '3c', '4c'], ['5d', '6d', '7d', '8d']], 1),
  ('suit pair plus rank pair', [['2c', '2d', '5c', '9h'], ['3c', '4c', '6d', 'Th']], 1)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, 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
import itertools
N = 1
observations = []
def solve(x):
    R='A23456789TJQK'
    def best(h):
        for n in range(4,0,-1):
            cands=[]
            for sub in itertools.combinations(h,n):
                if len({c[0] for c in sub})==n and len({c[1] for c in sub})==n:
                    cands.append(sorted((R.index(c[0])+1 for c in sub), reverse=True))
            if cands: return (n, min(cands))
    a,b=best(x[0]),best(x[1])
    if a[0]!=b[0]: return 1 if a[0]>b[0] else -1
    if a[1]==b[1]: return 0
    return 1 if a[1][-1]<b[1][-1] else -1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('four-card badugi vs three', [['Ac', '2d', '3h', '4s'], ['Ac', '2c', '3h', '4s']], 1),
  ('paired rank different suits', [['Ac', 'Ad', '3h', '4s'], ['5c', '6d', '7h', 'Ks']], -1),
  ('lower badugi wins', [['Ac', '2d', '3h', '8s'], ['Ac', '2d', '4h', '7s']], -1),
  ('equal badugis', [['Ac', '2d', '3h', '4s'], ['Ad', '2c', '3s', '4h']], 0),
  ('best three-card subset', [['Kc', '2c', '3h', '4s'], ['5c', '6c', '7h', '8s']], 1),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('king high badugi vs three', [['Kc', 'Qd', 'Jh', 'Ts'], ['Ac', '2c', '3d', '4h']], 1),
  ('lowest card trap', [['Ac', '5d', '6h', '7s'], ['2c', '3d', '4h', '8s']], 1)],
 [('four-card badugi vs three', [['Ac', '2d', '3h', '4s'], ['Ac', '2c', '3h', '4s']], 1),
  ('lower badugi wins', [['Ac', '2d', '3h', '8s'], ['Ac', '2d', '4h', '7s']], -1),
  ('best three-card subset', [['Kc', '2c', '3h', '4s'], ['5c', '6c', '7h', '8s']], 1),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('king high badugi vs three', [['Kc', 'Qd', 'Jh', 'Ts'], ['Ac', '2c', '3d', '4h']], 1),
  ('lowest card trap', [['Ac', '5d', '6h', '7s'], ['2c', '3d', '4h', '8s']], 1),
  ('one-card hands', [['Ac', '2c', '3c', '4c'], ['5d', '6d', '7d', '8d']], 1),
  ('suit pair plus rank pair', [['2c', '2d', '5c', '9h'], ['3c', '4c', '6d', 'Th']], 1)],
 [('four-card badugi vs three', [['Ac', '2d', '3h', '4s'], ['Ac', '2c', '3h', '4s']], 1),
  ('paired rank different suits', [['Ac', 'Ad', '3h', '4s'], ['5c', '6d', '7h', 'Ks']], -1),
  ('equal badugis', [['Ac', '2d', '3h', '4s'], ['Ad', '2c', '3s', '4h']], 0),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('king high badugi vs three', [['Kc', 'Qd', 'Jh', 'Ts'], ['Ac', '2c', '3d', '4h']], 1),
  ('lowest card trap', [['Ac', '5d', '6h', '7s'], ['2c', '3d', '4h', '8s']], 1),
  ('one-card hands', [['Ac', '2c', '3c', '4c'], ['5d', '6d', '7d', '8d']], 1),
  ('suit pair plus rank pair', [['2c', '2d', '5c', '9h'], ['3c', '4c', '6d', 'Th']], 1)],
 [('four-card badugi vs three', [['Ac', '2d', '3h', '4s'], ['Ac', '2c', '3h', '4s']], 1),
  ('paired rank different suits', [['Ac', 'Ad', '3h', '4s'], ['5c', '6d', '7h', 'Ks']], -1),
  ('equal badugis', [['Ac', '2d', '3h', '4s'], ['Ad', '2c', '3s', '4h']], 0),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('king high badugi vs three', [['Kc', 'Qd', 'Jh', 'Ts'], ['Ac', '2c', '3d', '4h']], 1),
  ('lowest card trap', [['Ac', '5d', '6h', '7s'], ['2c', '3d', '4h', '8s']], 1),
  ('one-card hands', [['Ac', '2c', '3c', '4c'], ['5d', '6d', '7d', '8d']], 1),
  ('suit pair plus rank pair', [['2c', '2d', '5c', '9h'], ['3c', '4c', '6d', 'Th']], 1)],
 [('lower badugi wins', [['Ac', '2d', '3h', '8s'], ['Ac', '2d', '4h', '7s']], -1),
  ('equal badugis', [['Ac', '2d', '3h', '4s'], ['Ad', '2c', '3s', '4h']], 0),
  ('best three-card subset', [['Kc', '2c', '3h', '4s'], ['5c', '6c', '7h', '8s']], 1),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('king high badugi vs three', [['Kc', 'Qd', 'Jh', 'Ts'], ['Ac', '2c', '3d', '4h']], 1),
  ('lowest card trap', [['Ac', '5d', '6h', '7s'], ['2c', '3d', '4h', '8s']], 1),
  ('one-card hands', [['Ac', '2c', '3c', '4c'], ['5d', '6d', '7d', '8d']], 1),
  ('suit pair plus rank pair', [['2c', '2d', '5c', '9h'], ['3c', '4c', '6d', 'Th']], 1)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A-2-3-8 beats A-2-4-7 although the eight-high badugi is the worse hand.

Input: [hand_a, hand_b], four distinct cards each. A hand's value is its best subset with all ranks distinct and all suits distinct: more cards beat fewer; among equal sizes the lower subset (compared from its highest card down, ace low = 1) wins. Return 1, -1 or 0.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    R='A23456789TJQK'
    def best(h):
        for n in range(1,5):
            cands=[]
            for sub in itertools.combinations(h,n):
                if len({c[0] for c in sub})==n and len({c[1] for c in sub})==n:
                    cands.append(sorted((R.index(c[0])+1 for c in sub), reverse=True))
            if cands: return (n, min(cands))
    a,b=best(x[0]),best(x[1])
    if a[0]!=b[0]: return 1 if a[0]>b[0] else -1
    if a[1]==b[1]: return 0
    return 1 if a[1]<b[1] else -1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('four-card badugi vs three', [['Ac', '2d', '3h', '4s'], ['Ac', '2c', '3h', '4s']], 1),
  ('paired rank different suits', [['Ac', 'Ad', '3h', '4s'], ['5c', '6d', '7h', 'Ks']], -1),
  ('lower badugi wins', [['Ac', '2d', '3h', '8s'], ['Ac', '2d', '4h', '7s']], -1),
  ('equal badugis', [['Ac', '2d', '3h', '4s'], ['Ad', '2c', '3s', '4h']], 0),
  ('best three-card subset', [['Kc', '2c', '3h', '4s'], ['5c', '6c', '7h', '8s']], 1),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('one-card hands', [['Ac', '2c', '3c', '4c'], ['5d', '6d', '7d', '8d']], 1),
  ('suit pair plus rank pair', [['2c', '2d', '5c', '9h'], ['3c', '4c', '6d', 'Th']], 1)],
 [('four-card badugi vs three', [['Ac', '2d', '3h', '4s'], ['Ac', '2c', '3h', '4s']], 1),
  ('paired rank different suits', [['Ac', 'Ad', '3h', '4s'], ['5c', '6d', '7h', 'Ks']], -1),
  ('lower badugi wins', [['Ac', '2d', '3h', '8s'], ['Ac', '2d', '4h', '7s']], -1),
  ('equal badugis', [['Ac', '2d', '3h', '4s'], ['Ad', '2c', '3s', '4h']], 0),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('king high badugi vs three', [['Kc', 'Qd', 'Jh', 'Ts'], ['Ac', '2c', '3d', '4h']], 1),
  ('lowest card trap', [['Ac', '5d', '6h', '7s'], ['2c', '3d', '4h', '8s']], 1),
  ('suit pair plus rank pair', [['2c', '2d', '5c', '9h'], ['3c', '4c', '6d', 'Th']], 1)],
 [('lower badugi wins', [['Ac', '2d', '3h', '8s'], ['Ac', '2d', '4h', '7s']], -1),
  ('equal badugis', [['Ac', '2d', '3h', '4s'], ['Ad', '2c', '3s', '4h']], 0),
  ('best three-card subset', [['Kc', '2c', '3h', '4s'], ['5c', '6c', '7h', '8s']], 1),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('king high badugi vs three', [['Kc', 'Qd', 'Jh', 'Ts'], ['Ac', '2c', '3d', '4h']], 1),
  ('lowest card trap', [['Ac', '5d', '6h', '7s'], ['2c', '3d', '4h', '8s']], 1),
  ('one-card hands', [['Ac', '2c', '3c', '4c'], ['5d', '6d', '7d', '8d']], 1),
  ('suit pair plus rank pair', [['2c', '2d', '5c', '9h'], ['3c', '4c', '6d', 'Th']], 1)],
 [('paired rank different suits', [['Ac', 'Ad', '3h', '4s'], ['5c', '6d', '7h', 'Ks']], -1),
  ('equal badugis', [['Ac', '2d', '3h', '4s'], ['Ad', '2c', '3s', '4h']], 0),
  ('best three-card subset', [['Kc', '2c', '3h', '4s'], ['5c', '6c', '7h', '8s']], 1),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('king high badugi vs three', [['Kc', 'Qd', 'Jh', 'Ts'], ['Ac', '2c', '3d', '4h']], 1),
  ('lowest card trap', [['Ac', '5d', '6h', '7s'], ['2c', '3d', '4h', '8s']], 1),
  ('one-card hands', [['Ac', '2c', '3c', '4c'], ['5d', '6d', '7d', '8d']], 1),
  ('suit pair plus rank pair', [['2c', '2d', '5c', '9h'], ['3c', '4c', '6d', 'Th']], 1)],
 [('four-card badugi vs three', [['Ac', '2d', '3h', '4s'], ['Ac', '2c', '3h', '4s']], 1),
  ('paired rank different suits', [['Ac', 'Ad', '3h', '4s'], ['5c', '6d', '7h', 'Ks']], -1),
  ('lower badugi wins', [['Ac', '2d', '3h', '8s'], ['Ac', '2d', '4h', '7s']], -1),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('king high badugi vs three', [['Kc', 'Qd', 'Jh', 'Ts'], ['Ac', '2c', '3d', '4h']], 1),
  ('lowest card trap', [['Ac', '5d', '6h', '7s'], ['2c', '3d', '4h', '8s']], 1),
  ('one-card hands', [['Ac', '2c', '3c', '4c'], ['5d', '6d', '7d', '8d']], 1),
  ('suit pair plus rank pair', [['2c', '2d', '5c', '9h'], ['3c', '4c', '6d', 'Th']], 1)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, 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
import itertools
N = 1
observations = []
def solve(x):
    R='A23456789TJQK'
    def best(h):
        for n in range(3,0,-1):
            cands=[]
            for sub in itertools.combinations(h,n):
                if len({c[0] for c in sub})==n and len({c[1] for c in sub})==n:
                    cands.append(sorted((R.index(c[0])+1 for c in sub), reverse=True))
            if cands: return (n, min(cands))
    a,b=best(x[0]),best(x[1])
    if a[0]!=b[0]: return 1 if a[0]>b[0] else -1
    if a[1]==b[1]: return 0
    return 1 if a[1]<b[1] else -1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('four-card badugi vs three', [['Ac', '2d', '3h', '4s'], ['Ac', '2c', '3h', '4s']], 1),
  ('paired rank different suits', [['Ac', 'Ad', '3h', '4s'], ['5c', '6d', '7h', 'Ks']], -1),
  ('lower badugi wins', [['Ac', '2d', '3h', '8s'], ['Ac', '2d', '4h', '7s']], -1),
  ('equal badugis', [['Ac', '2d', '3h', '4s'], ['Ad', '2c', '3s', '4h']], 0),
  ('best three-card subset', [['Kc', '2c', '3h', '4s'], ['5c', '6c', '7h', '8s']], 1),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('one-card hands', [['Ac', '2c', '3c', '4c'], ['5d', '6d', '7d', '8d']], 1),
  ('suit pair plus rank pair', [['2c', '2d', '5c', '9h'], ['3c', '4c', '6d', 'Th']], 1)],
 [('four-card badugi vs three', [['Ac', '2d', '3h', '4s'], ['Ac', '2c', '3h', '4s']], 1),
  ('paired rank different suits', [['Ac', 'Ad', '3h', '4s'], ['5c', '6d', '7h', 'Ks']], -1),
  ('lower badugi wins', [['Ac', '2d', '3h', '8s'], ['Ac', '2d', '4h', '7s']], -1),
  ('equal badugis', [['Ac', '2d', '3h', '4s'], ['Ad', '2c', '3s', '4h']], 0),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('king high badugi vs three', [['Kc', 'Qd', 'Jh', 'Ts'], ['Ac', '2c', '3d', '4h']], 1),
  ('lowest card trap', [['Ac', '5d', '6h', '7s'], ['2c', '3d', '4h', '8s']], 1),
  ('suit pair plus rank pair', [['2c', '2d', '5c', '9h'], ['3c', '4c', '6d', 'Th']], 1)],
 [('lower badugi wins', [['Ac', '2d', '3h', '8s'], ['Ac', '2d', '4h', '7s']], -1),
  ('equal badugis', [['Ac', '2d', '3h', '4s'], ['Ad', '2c', '3s', '4h']], 0),
  ('best three-card subset', [['Kc', '2c', '3h', '4s'], ['5c', '6c', '7h', '8s']], 1),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('king high badugi vs three', [['Kc', 'Qd', 'Jh', 'Ts'], ['Ac', '2c', '3d', '4h']], 1),
  ('lowest card trap', [['Ac', '5d', '6h', '7s'], ['2c', '3d', '4h', '8s']], 1),
  ('one-card hands', [['Ac', '2c', '3c', '4c'], ['5d', '6d', '7d', '8d']], 1),
  ('suit pair plus rank pair', [['2c', '2d', '5c', '9h'], ['3c', '4c', '6d', 'Th']], 1)],
 [('paired rank different suits', [['Ac', 'Ad', '3h', '4s'], ['5c', '6d', '7h', 'Ks']], -1),
  ('equal badugis', [['Ac', '2d', '3h', '4s'], ['Ad', '2c', '3s', '4h']], 0),
  ('best three-card subset', [['Kc', '2c', '3h', '4s'], ['5c', '6c', '7h', '8s']], 1),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('king high badugi vs three', [['Kc', 'Qd', 'Jh', 'Ts'], ['Ac', '2c', '3d', '4h']], 1),
  ('lowest card trap', [['Ac', '5d', '6h', '7s'], ['2c', '3d', '4h', '8s']], 1),
  ('one-card hands', [['Ac', '2c', '3c', '4c'], ['5d', '6d', '7d', '8d']], 1),
  ('suit pair plus rank pair', [['2c', '2d', '5c', '9h'], ['3c', '4c', '6d', 'Th']], 1)],
 [('four-card badugi vs three', [['Ac', '2d', '3h', '4s'], ['Ac', '2c', '3h', '4s']], 1),
  ('paired rank different suits', [['Ac', 'Ad', '3h', '4s'], ['5c', '6d', '7h', 'Ks']], -1),
  ('lower badugi wins', [['Ac', '2d', '3h', '8s'], ['Ac', '2d', '4h', '7s']], -1),
  ('two-card hands', [['Ac', '2c', '3c', 'Kd'], ['4h', '5h', '6h', '7s']], -1),
  ('king high badugi vs three', [['Kc', 'Qd', 'Jh', 'Ts'], ['Ac', '2c', '3d', '4h']], 1),
  ('lowest card trap', [['Ac', '5d', '6h', '7s'], ['2c', '3d', '4h', '8s']], 1),
  ('one-card hands', [['Ac', '2c', '3c', '4c'], ['5d', '6d', '7d', '8d']], 1),
  ('suit pair plus rank pair', [['2c', '2d', '5c', '9h'], ['3c', '4c', '6d', 'Th']], 1)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, 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:
Every hand evaluates as a one-card hand, so comparisons depend only on the lowest card.

Input: [hand_a, hand_b], four distinct cards each. A hand's value is its best subset with all ranks distinct and all suits distinct: more cards beat fewer; among equal sizes the lower subset (compared from its highest card down, ace low = 1) wins. Return 1, -1 or 0.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import collections
import itertools
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key5(h):
        vals=sorted((R.index(c[0])+2 for c in h), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (vals[0]-vals[4]==4 or vals==[14,5,4,3,2])
        top=5 if vals==[14,5,4,3,2] else vals[0]
        if straight: return (8 if flush else 4, [top])
        if flush: return (5, vals)
        return ({(4,1):7,(3,2):6,(3,1,1):3,(2,2,1):2,(2,1,1,1):1}.get(tuple(shape),0), order)
    hole=x['hole']; board=x['board']
    best=max(key5(c) for c in itertools.combinations(hole+board,5))
    for n in range(2,-1,-1):
        for hc in itertools.combinations(hole,n):
            for bc in itertools.combinations(board,5-n):
                if key5(hc+bc)==best: return n
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('board straight plays', {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('one card kicker', {'board': ['9h', '9d', '7c', '6s', '2h'], 'hole': ['Ac', '3d']}, 1),
  ('hole ranks duplicate board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['9c', 'Ts']}, 0),
  ('second hole card redundant', {'board': ['Kh', 'Kd', '9c', '7s', '5h'], 'hole': ['9d', '7d']},
   1),
  ('wheel with both', {'board': ['9h', '9d', '5c', '4s', '2h'], 'hole': ['Ac', '3d']}, 2),
  ('both cards pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['Kc', 'Qd']}, 2),
  ('pocket pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['8c', '8d']}, 2),
  ('same category better kicker', {'board': ['Ah', 'Ad', '9c', '7s', '5h'], 'hole': ['Jc', '2d']},
   1)],
 [('hole ranks duplicate board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['9c', 'Ts']}, 0),
  ('second hole card redundant', {'board': ['Kh', 'Kd', '9c', '7s', '5h'], 'hole': ['9d', '7d']},
   1),
  ('pocket pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['8c', '8d']}, 2),
  ('low kicker does not play', {'board': ['Ah', 'Kd', '9c', '7s', '5h'], 'hole': ['2c', '3d']}, 0),
  ('same category better kicker', {'board': ['Ah', 'Ad', '9c', '7s', '5h'], 'hole': ['Jc', '2d']},
   1),
  ('flush with one card', {'board': ['3h', '7h', '9h', 'Jh', 'Kd'], 'hole': ['Ah', '2c']}, 1),
  ('improved board flush', {'board': ['4h', '7h', '9h', 'Jh', 'Kh'], 'hole': ['Ah', '3d']}, 1),
  ('quads on board kicker', {'board': ['9h', '9d', '9c', '9s', 'Kh'], 'hole': ['Ac', '2d']}, 1)],
 [('board straight plays', {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('one card kicker', {'board': ['9h', '9d', '7c', '6s', '2h'], 'hole': ['Ac', '3d']}, 1),
  ('hole ranks duplicate board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['9c', 'Ts']}, 0),
  ('second hole card redundant', {'board': ['Kh', 'Kd', '9c', '7s', '5h'], 'hole': ['9d', '7d']},
   1),
  ('low kicker does not play', {'board': ['Ah', 'Kd', '9c', '7s', '5h'], 'hole': ['2c', '3d']}, 0),
  ('board flush plays', {'board': ['4h', '7h', '9h', 'Jh', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('improved board flush', {'board': ['4h', '7h', '9h', 'Jh', 'Kh'], 'hole': ['Ah', '3d']}, 1),
  ('quads on board kicker', {'board': ['9h', '9d', '9c', '9s', 'Kh'], 'hole': ['Ac', '2d']}, 1)],
 [('board straight plays', {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('one card kicker', {'board': ['9h', '9d', '7c', '6s', '2h'], 'hole': ['Ac', '3d']}, 1),
  ('hole ranks duplicate board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['9c', 'Ts']}, 0),
  ('second hole card redundant', {'board': ['Kh', 'Kd', '9c', '7s', '5h'], 'hole': ['9d', '7d']},
   1),
  ('wheel with both', {'board': ['9h', '9d', '5c', '4s', '2h'], 'hole': ['Ac', '3d']}, 2),
  ('both cards pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['Kc', 'Qd']}, 2),
  ('low kicker does not play', {'board': ['Ah', 'Kd', '9c', '7s', '5h'], 'hole': ['2c', '3d']}, 0),
  ('board flush plays', {'board': ['4h', '7h', '9h', 'Jh', 'Kh'], 'hole': ['2c', '3d']}, 0)],
 [('board straight plays', {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('one card kicker', {'board': ['9h', '9d', '7c', '6s', '2h'], 'hole': ['Ac', '3d']}, 1),
  ('hole ranks duplicate board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['9c', 'Ts']}, 0),
  ('second hole card redundant', {'board': ['Kh', 'Kd', '9c', '7s', '5h'], 'hole': ['9d', '7d']},
   1),
  ('wheel with both', {'board': ['9h', '9d', '5c', '4s', '2h'], 'hole': ['Ac', '3d']}, 2),
  ('both cards pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['Kc', 'Qd']}, 2),
  ('pocket pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['8c', '8d']}, 2),
  ('board flush plays', {'board': ['4h', '7h', '9h', 'Jh', 'Kh'], 'hole': ['2c', '3d']}, 0)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, 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
import collections
import itertools
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key5(h):
        vals=sorted((R.index(c[0])+2 for c in h), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (vals[0]-vals[4]==4 or vals==[14,5,4,3,2])
        top=5 if vals==[14,5,4,3,2] else vals[0]
        if straight: return (8 if flush else 4, [top])
        if flush: return (5, vals)
        return ({(4,1):7,(3,2):6,(3,1,1):3,(2,2,1):2,(2,1,1,1):1}.get(tuple(shape),0), order)
    hole=x['hole']; board=x['board']
    best=max(key5(c) for c in itertools.combinations(hole+board,5))
    for n in range(1,3):
        for hc in itertools.combinations(hole,n):
            for bc in itertools.combinations(board,5-n):
                if key5(hc+bc)==best: return n
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('board straight plays', {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('one card kicker', {'board': ['9h', '9d', '7c', '6s', '2h'], 'hole': ['Ac', '3d']}, 1),
  ('hole ranks duplicate board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['9c', 'Ts']}, 0),
  ('second hole card redundant', {'board': ['Kh', 'Kd', '9c', '7s', '5h'], 'hole': ['9d', '7d']},
   1),
  ('wheel with both', {'board': ['9h', '9d', '5c', '4s', '2h'], 'hole': ['Ac', '3d']}, 2),
  ('both cards pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['Kc', 'Qd']}, 2),
  ('pocket pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['8c', '8d']}, 2),
  ('same category better kicker', {'board': ['Ah', 'Ad', '9c', '7s', '5h'], 'hole': ['Jc', '2d']},
   1)],
 [('hole ranks duplicate board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['9c', 'Ts']}, 0),
  ('second hole card redundant', {'board': ['Kh', 'Kd', '9c', '7s', '5h'], 'hole': ['9d', '7d']},
   1),
  ('pocket pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['8c', '8d']}, 2),
  ('low kicker does not play', {'board': ['Ah', 'Kd', '9c', '7s', '5h'], 'hole': ['2c', '3d']}, 0),
  ('same category better kicker', {'board': ['Ah', 'Ad', '9c', '7s', '5h'], 'hole': ['Jc', '2d']},
   1),
  ('flush with one card', {'board': ['3h', '7h', '9h', 'Jh', 'Kd'], 'hole': ['Ah', '2c']}, 1),
  ('improved board flush', {'board': ['4h', '7h', '9h', 'Jh', 'Kh'], 'hole': ['Ah', '3d']}, 1),
  ('quads on board kicker', {'board': ['9h', '9d', '9c', '9s', 'Kh'], 'hole': ['Ac', '2d']}, 1)],
 [('board straight plays', {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('one card kicker', {'board': ['9h', '9d', '7c', '6s', '2h'], 'hole': ['Ac', '3d']}, 1),
  ('hole ranks duplicate board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['9c', 'Ts']}, 0),
  ('second hole card redundant', {'board': ['Kh', 'Kd', '9c', '7s', '5h'], 'hole': ['9d', '7d']},
   1),
  ('low kicker does not play', {'board': ['Ah', 'Kd', '9c', '7s', '5h'], 'hole': ['2c', '3d']}, 0),
  ('board flush plays', {'board': ['4h', '7h', '9h', 'Jh', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('improved board flush', {'board': ['4h', '7h', '9h', 'Jh', 'Kh'], 'hole': ['Ah', '3d']}, 1),
  ('quads on board kicker', {'board': ['9h', '9d', '9c', '9s', 'Kh'], 'hole': ['Ac', '2d']}, 1)],
 [('board straight plays', {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('one card kicker', {'board': ['9h', '9d', '7c', '6s', '2h'], 'hole': ['Ac', '3d']}, 1),
  ('hole ranks duplicate board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['9c', 'Ts']}, 0),
  ('second hole card redundant', {'board': ['Kh', 'Kd', '9c', '7s', '5h'], 'hole': ['9d', '7d']},
   1),
  ('wheel with both', {'board': ['9h', '9d', '5c', '4s', '2h'], 'hole': ['Ac', '3d']}, 2),
  ('both cards pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['Kc', 'Qd']}, 2),
  ('low kicker does not play', {'board': ['Ah', 'Kd', '9c', '7s', '5h'], 'hole': ['2c', '3d']}, 0),
  ('board flush plays', {'board': ['4h', '7h', '9h', 'Jh', 'Kh'], 'hole': ['2c', '3d']}, 0)],
 [('board straight plays', {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('one card kicker', {'board': ['9h', '9d', '7c', '6s', '2h'], 'hole': ['Ac', '3d']}, 1),
  ('hole ranks duplicate board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['9c', 'Ts']}, 0),
  ('second hole card redundant', {'board': ['Kh', 'Kd', '9c', '7s', '5h'], 'hole': ['9d', '7d']},
   1),
  ('wheel with both', {'board': ['9h', '9d', '5c', '4s', '2h'], 'hole': ['Ac', '3d']}, 2),
  ('both cards pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['Kc', 'Qd']}, 2),
  ('pocket pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['8c', '8d']}, 2),
  ('board flush plays', {'board': ['4h', '7h', '9h', 'Jh', 'Kh'], 'hole': ['2c', '3d']}, 0)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, 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 the board plays, the hand is annotated as using both hole cards.

Input: {"hole": two cards, "board": five cards}. Return the minimum number of hole cards (0, 1 or 2) needed to make the player's best possible five-card hand; 0 means the board plays.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import collections
import itertools
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key5(h):
        vals=sorted((R.index(c[0])+2 for c in h), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (vals[0]-vals[4]==4 or vals==[14,5,4,3,2])
        top=5 if vals==[14,5,4,3,2] else vals[0]
        if straight: return (8 if flush else 4, [top])
        if flush: return (5, vals)
        return ({(4,1):7,(3,2):6,(3,1,1):3,(2,2,1):2,(2,1,1,1):1}.get(tuple(shape),0), order)
    hole=x['hole']; board=x['board']
    best=max(key5(c) for c in itertools.combinations(hole+board,5))
    for n in range(3):
        for hc in itertools.combinations(hole,n):
            for bc in itertools.combinations(board,5-n):
                if key5(hc+bc)[0]==best[0]: return n
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('board straight plays', {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('one card kicker', {'board': ['9h', '9d', '7c', '6s', '2h'], 'hole': ['Ac', '3d']}, 1),
  ('hole ranks duplicate board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['9c', 'Ts']}, 0),
  ('second hole card redundant', {'board': ['Kh', 'Kd', '9c', '7s', '5h'], 'hole': ['9d', '7d']},
   1),
  ('wheel with both', {'board': ['9h', '9d', '5c', '4s', '2h'], 'hole': ['Ac', '3d']}, 2),
  ('both cards pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['Kc', 'Qd']}, 2),
  ('pocket pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['8c', '8d']}, 2),
  ('same category better kicker', {'board': ['Ah', 'Ad', '9c', '7s', '5h'], 'hole': ['Jc', '2d']},
   1)],
 [('wheel with both', {'board': ['9h', '9d', '5c', '4s', '2h'], 'hole': ['Ac', '3d']}, 2),
  ('both cards pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['Kc', 'Qd']}, 2),
  ('pocket pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['8c', '8d']}, 2),
  ('low kicker does not play', {'board': ['Ah', 'Kd', '9c', '7s', '5h'], 'hole': ['2c', '3d']}, 0),
  ('same category better kicker', {'board': ['Ah', 'Ad', '9c', '7s', '5h'], 'hole': ['Jc', '2d']},
   1),
  ('flush with one card', {'board': ['3h', '7h', '9h', 'Jh', 'Kd'], 'hole': ['Ah', '2c']}, 1),
  ('improved board flush', {'board': ['4h', '7h', '9h', 'Jh', 'Kh'], 'hole': ['Ah', '3d']}, 1),
  ('quads on board kicker', {'board': ['9h', '9d', '9c', '9s', 'Kh'], 'hole': ['Ac', '2d']}, 1)],
 [('board straight plays', {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('one card kicker', {'board': ['9h', '9d', '7c', '6s', '2h'], 'hole': ['Ac', '3d']}, 1),
  ('low kicker does not play', {'board': ['Ah', 'Kd', '9c', '7s', '5h'], 'hole': ['2c', '3d']}, 0),
  ('same category better kicker', {'board': ['Ah', 'Ad', '9c', '7s', '5h'], 'hole': ['Jc', '2d']},
   1),
  ('flush with one card', {'board': ['3h', '7h', '9h', 'Jh', 'Kd'], 'hole': ['Ah', '2c']}, 1),
  ('board flush plays', {'board': ['4h', '7h', '9h', 'Jh', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('improved board flush', {'board': ['4h', '7h', '9h', 'Jh', 'Kh'], 'hole': ['Ah', '3d']}, 1),
  ('quads on board kicker', {'board': ['9h', '9d', '9c', '9s', 'Kh'], 'hole': ['Ac', '2d']}, 1)],
 [('board straight plays', {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('one card kicker', {'board': ['9h', '9d', '7c', '6s', '2h'], 'hole': ['Ac', '3d']}, 1),
  ('hole ranks duplicate board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['9c', 'Ts']}, 0),
  ('second hole card redundant', {'board': ['Kh', 'Kd', '9c', '7s', '5h'], 'hole': ['9d', '7d']},
   1),
  ('wheel with both', {'board': ['9h', '9d', '5c', '4s', '2h'], 'hole': ['Ac', '3d']}, 2),
  ('same category better kicker', {'board': ['Ah', 'Ad', '9c', '7s', '5h'], 'hole': ['Jc', '2d']},
   1),
  ('improved board flush', {'board': ['4h', '7h', '9h', 'Jh', 'Kh'], 'hole': ['Ah', '3d']}, 1),
  ('quads on board kicker', {'board': ['9h', '9d', '9c', '9s', 'Kh'], 'hole': ['Ac', '2d']}, 1)],
 [('board straight plays', {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('one card kicker', {'board': ['9h', '9d', '7c', '6s', '2h'], 'hole': ['Ac', '3d']}, 1),
  ('hole ranks duplicate board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['9c', 'Ts']}, 0),
  ('second hole card redundant', {'board': ['Kh', 'Kd', '9c', '7s', '5h'], 'hole': ['9d', '7d']},
   1),
  ('wheel with both', {'board': ['9h', '9d', '5c', '4s', '2h'], 'hole': ['Ac', '3d']}, 2),
  ('both cards pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['Kc', 'Qd']}, 2),
  ('same category better kicker', {'board': ['Ah', 'Ad', '9c', '7s', '5h'], 'hole': ['Jc', '2d']},
   1),
  ('quads on board kicker', {'board': ['9h', '9d', '9c', '9s', 'Kh'], 'hole': ['Ac', '2d']}, 1)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, 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
import collections
import itertools
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key5(h):
        vals=sorted((R.index(c[0])+2 for c in h), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (vals[0]-vals[4]==4 or vals==[14,5,4,3,2])
        top=5 if vals==[14,5,4,3,2] else vals[0]
        if straight: return (8 if flush else 4, [top])
        if flush: return (5, vals)
        return ({(4,1):7,(3,2):6,(3,1,1):3,(2,2,1):2,(2,1,1,1):1}.get(tuple(shape),0), order)
    hole=x['hole']; board=x['board']
    best=max(key5(c) for c in itertools.combinations(hole+board,5))
    for n in range(3):
        for hc in itertools.combinations(hole,n):
            for bc in itertools.combinations(board,5-n):
                if key5(hc+bc)[0]==best[0] and key5(hc+bc)[1][0]==best[1][0]: return n
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('board straight plays', {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('one card kicker', {'board': ['9h', '9d', '7c', '6s', '2h'], 'hole': ['Ac', '3d']}, 1),
  ('hole ranks duplicate board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['9c', 'Ts']}, 0),
  ('second hole card redundant', {'board': ['Kh', 'Kd', '9c', '7s', '5h'], 'hole': ['9d', '7d']},
   1),
  ('wheel with both', {'board': ['9h', '9d', '5c', '4s', '2h'], 'hole': ['Ac', '3d']}, 2),
  ('both cards pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['Kc', 'Qd']}, 2),
  ('pocket pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['8c', '8d']}, 2),
  ('same category better kicker', {'board': ['Ah', 'Ad', '9c', '7s', '5h'], 'hole': ['Jc', '2d']},
   1)],
 [('wheel with both', {'board': ['9h', '9d', '5c', '4s', '2h'], 'hole': ['Ac', '3d']}, 2),
  ('both cards pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['Kc', 'Qd']}, 2),
  ('pocket pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['8c', '8d']}, 2),
  ('low kicker does not play', {'board': ['Ah', 'Kd', '9c', '7s', '5h'], 'hole': ['2c', '3d']}, 0),
  ('same category better kicker', {'board': ['Ah', 'Ad', '9c', '7s', '5h'], 'hole': ['Jc', '2d']},
   1),
  ('flush with one card', {'board': ['3h', '7h', '9h', 'Jh', 'Kd'], 'hole': ['Ah', '2c']}, 1),
  ('improved board flush', {'board': ['4h', '7h', '9h', 'Jh', 'Kh'], 'hole': ['Ah', '3d']}, 1),
  ('quads on board kicker', {'board': ['9h', '9d', '9c', '9s', 'Kh'], 'hole': ['Ac', '2d']}, 1)],
 [('board straight plays', {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('one card kicker', {'board': ['9h', '9d', '7c', '6s', '2h'], 'hole': ['Ac', '3d']}, 1),
  ('low kicker does not play', {'board': ['Ah', 'Kd', '9c', '7s', '5h'], 'hole': ['2c', '3d']}, 0),
  ('same category better kicker', {'board': ['Ah', 'Ad', '9c', '7s', '5h'], 'hole': ['Jc', '2d']},
   1),
  ('flush with one card', {'board': ['3h', '7h', '9h', 'Jh', 'Kd'], 'hole': ['Ah', '2c']}, 1),
  ('board flush plays', {'board': ['4h', '7h', '9h', 'Jh', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('improved board flush', {'board': ['4h', '7h', '9h', 'Jh', 'Kh'], 'hole': ['Ah', '3d']}, 1),
  ('quads on board kicker', {'board': ['9h', '9d', '9c', '9s', 'Kh'], 'hole': ['Ac', '2d']}, 1)],
 [('board straight plays', {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('one card kicker', {'board': ['9h', '9d', '7c', '6s', '2h'], 'hole': ['Ac', '3d']}, 1),
  ('hole ranks duplicate board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['9c', 'Ts']}, 0),
  ('second hole card redundant', {'board': ['Kh', 'Kd', '9c', '7s', '5h'], 'hole': ['9d', '7d']},
   1),
  ('wheel with both', {'board': ['9h', '9d', '5c', '4s', '2h'], 'hole': ['Ac', '3d']}, 2),
  ('same category better kicker', {'board': ['Ah', 'Ad', '9c', '7s', '5h'], 'hole': ['Jc', '2d']},
   1),
  ('improved board flush', {'board': ['4h', '7h', '9h', 'Jh', 'Kh'], 'hole': ['Ah', '3d']}, 1),
  ('quads on board kicker', {'board': ['9h', '9d', '9c', '9s', 'Kh'], 'hole': ['Ac', '2d']}, 1)],
 [('board straight plays', {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '3d']}, 0),
  ('one card kicker', {'board': ['9h', '9d', '7c', '6s', '2h'], 'hole': ['Ac', '3d']}, 1),
  ('hole ranks duplicate board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['9c', 'Ts']}, 0),
  ('second hole card redundant', {'board': ['Kh', 'Kd', '9c', '7s', '5h'], 'hole': ['9d', '7d']},
   1),
  ('wheel with both', {'board': ['9h', '9d', '5c', '4s', '2h'], 'hole': ['Ac', '3d']}, 2),
  ('both cards pair', {'board': ['Kh', 'Qs', '5c', '4s', '2h'], 'hole': ['Kc', 'Qd']}, 2),
  ('same category better kicker', {'board': ['Ah', 'Ad', '9c', '7s', '5h'], 'hole': ['Jc', '2d']},
   1),
  ('quads on board kicker', {'board': ['9h', '9d', '9c', '9s', 'Kh'], 'hole': ['Ac', '2d']}, 1)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, 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 player whose ace kicker matters is told the board plays.

Input: {"hole": two cards, "board": five cards}. Return the minimum number of hole cards (0, 1 or 2) needed to make the player's best possible five-card hand; 0 means the board plays.

split: open-access


prompt:
A knight on h3 is offered a2 and a4, which wrap around the board edge.

Input: {"board": {square: piece}, "from": square of a knight}. Squares are indexed 0..63 with a1=0, h1=7, a8=56. Return the sorted list of pseudo-legal knight destinations: on the board, not wrapping across the a/h file edge, and not occupied by a piece of the knight's colour.

split: open-access


prompt:
A knight on c7 is offered a ninth-rank square named "a9".

Input: {"board": {square: piece}, "from": square of a knight}. Squares are indexed 0..63 with a1=0, h1=7, a8=56. Return the sorted list of pseudo-legal knight destinations: on the board, not wrapping across the a/h file edge, and not occupied by a piece of the knight's colour.

split: open-access


prompt:
The knight may land on a friendly bishop but not capture an enemy pawn.

Input: {"board": {square: piece}, "from": square of a knight}. Squares are indexed 0..63 with a1=0, h1=7, a8=56. Return the sorted list of pseudo-legal knight destinations: on the board, not wrapping across the a/h file edge, and not occupied by a piece of the knight's colour.

split: open-access


prompt:
A knight is offered the square two ranks straight below it.

Input: {"board": {square: piece}, "from": square of a knight}. Squares are indexed 0..63 with a1=0, h1=7, a8=56. Return the sorted list of pseudo-legal knight destinations: on the board, not wrapping across the a/h file edge, and not occupied by a piece of the knight's colour.

split: open-access


prompt:
Every knight target is reported one rank too high.

Input: {"board": {square: piece}, "from": square of a knight}. Squares are indexed 0..63 with a1=0, h1=7, a8=56. Return the sorted list of pseudo-legal knight destinations: on the board, not wrapping across the a/h file edge, and not occupied by a piece of the knight's colour.

split: open-access


prompt:
A rook facing an enemy pawn is offered the squares behind it, including the enemy king square.

Input: {"board", "from": square of a rook, bishop or queen}. Return the sorted pseudo-legal destinations: walk each ray until the edge; an empty square is added, an enemy piece is added and ends the ray, a friendly piece ends the ray without being added.

split: open-access


prompt:
A rook on a1 is offered "i1" and "a9".

Input: {"board", "from": square of a rook, bishop or queen}. Return the sorted pseudo-legal destinations: walk each ray until the edge; an empty square is added, an enemy piece is added and ends the ray, a friendly piece ends the ray without being added.

split: open-access


prompt:
A queen is never offered diagonal moves.

Input: {"board", "from": square of a rook, bishop or queen}. Return the sorted pseudo-legal destinations: walk each ray until the edge; an empty square is added, an enemy piece is added and ends the ray, a friendly piece ends the ray without being added.

split: open-access


prompt:
A bishop on f5 is not offered e4, d3 or the capture on c2, and some targets repeat.

Input: {"board", "from": square of a rook, bishop or queen}. Return the sorted pseudo-legal destinations: walk each ray until the edge; an empty square is added, an enemy piece is added and ends the ray, a friendly piece ends the ray without being added.

split: open-access


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

N = 1
observations = []
def solve(x):
    b=x['board']; sq=x['from']; p=b[sq]; white=p=='P'
    f,r=ord(sq[0])-97,int(sq[1])-1
    d=1 if white else -1
    start=1 if white else 6
    last=7 if white else 0
    def at(ff,rr): return chr(97+ff)+str(rr+1)
    out=[]
    if 0<=r+d<8 and at(f,r+d) not in b:
        out.append(at(f,r+d))
    if r==start and at(f,r+2*d) not in b: out.append(at(f,r+2*d))
    for df in (-1,1):
        ff=f+df
        if not 0<=ff<8 or not 0<=r+d<8: continue
        t=at(ff,r+d); occ=b.get(t)
        if (occ and occ.isupper()!=white) or t==x.get('ep'): out.append(t)
    res=[]
    for t in out:
        if int(t[1])-1==last: res+=[t+c for c in 'qrbn']
        else: res.append(t)
    return sorted(res)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black blocked by own', {'board': {'a6': 'P', 'b6': 'p', 'b7': 'p'}, 'ep': None, 'from': 'b7'},
   ['a6'])],
 [('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('en passant target', {'board': {'d5': 'p', 'e5': 'P'}, 'ep': 'd6', 'from': 'e5'}, ['d6', 'e6']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5']),
  ('black blocked by own', {'board': {'a6': 'P', 'b6': 'p', 'b7': 'p'}, 'ep': None, 'from': 'b7'},
   ['a6'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('en passant target', {'board': {'d5': 'p', 'e5': 'P'}, 'ep': 'd6', 'from': 'e5'}, ['d6', 'e6']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5']),
  ('white third rank', {'board': {'g3': 'P'}, 'ep': None, 'from': 'g3'}, ['g4']),
  ('black blocked by own', {'board': {'a6': 'P', 'b6': 'p', 'b7': 'p'}, 'ep': None, 'from': 'b7'},
   ['a6'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black blocked by own', {'board': {'a6': 'P', 'b6': 'p', 'b7': 'p'}, 'ep': None, 'from': 'b7'},
   ['a6'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black blocked by own', {'board': {'a6': 'P', 'b6': 'p', 'b7': 'p'}, 'ep': None, 'from': 'b7'},
   ['a6'])]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    b=x['board']; sq=x['from']; p=b[sq]; white=p=='P'
    f,r=ord(sq[0])-97,int(sq[1])-1
    d=1 if white else -1
    start=1 if white else 6
    last=7 if white else 0
    def at(ff,rr): return chr(97+ff)+str(rr+1)
    out=[]
    if 0<=r+d<8 and at(f,r+d) not in b:
        out.append(at(f,r+d))
        if r==start: out.append(at(f,r+2*d))
    for df in (-1,1):
        ff=f+df
        if not 0<=ff<8 or not 0<=r+d<8: continue
        t=at(ff,r+d); occ=b.get(t)
        if (occ and occ.isupper()!=white) or t==x.get('ep'): out.append(t)
    res=[]
    for t in out:
        if int(t[1])-1==last: res+=[t+c for c in 'qrbn']
        else: res.append(t)
    return sorted(res)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black blocked by own', {'board': {'a6': 'P', 'b6': 'p', 'b7': 'p'}, 'ep': None, 'from': 'b7'},
   ['a6'])],
 [('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('en passant target', {'board': {'d5': 'p', 'e5': 'P'}, 'ep': 'd6', 'from': 'e5'}, ['d6', 'e6']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5']),
  ('black blocked by own', {'board': {'a6': 'P', 'b6': 'p', 'b7': 'p'}, 'ep': None, 'from': 'b7'},
   ['a6'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('en passant target', {'board': {'d5': 'p', 'e5': 'P'}, 'ep': 'd6', 'from': 'e5'}, ['d6', 'e6']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5']),
  ('white third rank', {'board': {'g3': 'P'}, 'ep': None, 'from': 'g3'}, ['g4']),
  ('black blocked by own', {'board': {'a6': 'P', 'b6': 'p', 'b7': 'p'}, 'ep': None, 'from': 'b7'},
   ['a6'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black blocked by own', {'board': {'a6': 'P', 'b6': 'p', 'b7': 'p'}, 'ep': None, 'from': 'b7'},
   ['a6'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black blocked by own', {'board': {'a6': 'P', 'b6': 'p', 'b7': 'p'}, 'ep': None, 'from': 'b7'},
   ['a6'])]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, 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 pawn on e2 with a knight on e3 is offered e4.

Input: {"board", "from": square of a pawn, "ep": en passant target square or null}. Return sorted pseudo-legal destinations: one step forward if empty; two steps from the starting rank if both squares are empty; diagonal captures of enemy pieces or onto the ep square. A destination on the last rank is expanded into four entries suffixed q, r, b, n.

split: open-access


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

N = 1
observations = []
def solve(x):
    b=x['board']; sq=x['from']; p=b[sq]; white=p=='P'
    f,r=ord(sq[0])-97,int(sq[1])-1
    d=1 if white else -1
    start=1
    last=7 if white else 0
    def at(ff,rr): return chr(97+ff)+str(rr+1)
    out=[]
    if 0<=r+d<8 and at(f,r+d) not in b:
        out.append(at(f,r+d))
        if r==start and at(f,r+2*d) not in b: out.append(at(f,r+2*d))
    for df in (-1,1):
        ff=f+df
        if not 0<=ff<8 or not 0<=r+d<8: continue
        t=at(ff,r+d); occ=b.get(t)
        if (occ and occ.isupper()!=white) or t==x.get('ep'): out.append(t)
    res=[]
    for t in out:
        if int(t[1])-1==last: res+=[t+c for c in 'qrbn']
        else: res.append(t)
    return sorted(res)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5'])],
 [('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('en passant target', {'board': {'d5': 'p', 'e5': 'P'}, 'ep': 'd6', 'from': 'e5'}, ['d6', 'e6']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5']),
  ('white third rank', {'board': {'g3': 'P'}, 'ep': None, 'from': 'g3'}, ['g4'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('en passant target', {'board': {'d5': 'p', 'e5': 'P'}, 'ep': 'd6', 'from': 'e5'}, ['d6', 'e6']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5']),
  ('white third rank', {'board': {'g3': 'P'}, 'ep': None, 'from': 'g3'}, ['g4']),
  ('black blocked by own', {'board': {'a6': 'P', 'b6': 'p', 'b7': 'p'}, 'ep': None, 'from': 'b7'},
   ['a6'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5'])]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    b=x['board']; sq=x['from']; p=b[sq]; white=p=='P'
    f,r=ord(sq[0])-97,int(sq[1])-1
    d=1 if white else -1
    start=1 if white else 5
    last=7 if white else 0
    def at(ff,rr): return chr(97+ff)+str(rr+1)
    out=[]
    if 0<=r+d<8 and at(f,r+d) not in b:
        out.append(at(f,r+d))
        if r==start and at(f,r+2*d) not in b: out.append(at(f,r+2*d))
    for df in (-1,1):
        ff=f+df
        if not 0<=ff<8 or not 0<=r+d<8: continue
        t=at(ff,r+d); occ=b.get(t)
        if (occ and occ.isupper()!=white) or t==x.get('ep'): out.append(t)
    res=[]
    for t in out:
        if int(t[1])-1==last: res+=[t+c for c in 'qrbn']
        else: res.append(t)
    return sorted(res)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5'])],
 [('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('en passant target', {'board': {'d5': 'p', 'e5': 'P'}, 'ep': 'd6', 'from': 'e5'}, ['d6', 'e6']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5']),
  ('white third rank', {'board': {'g3': 'P'}, 'ep': None, 'from': 'g3'}, ['g4'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('en passant target', {'board': {'d5': 'p', 'e5': 'P'}, 'ep': 'd6', 'from': 'e5'}, ['d6', 'e6']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5']),
  ('white third rank', {'board': {'g3': 'P'}, 'ep': None, 'from': 'g3'}, ['g4']),
  ('black blocked by own', {'board': {'a6': 'P', 'b6': 'p', 'b7': 'p'}, 'ep': None, 'from': 'b7'},
   ['a6'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5'])]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, 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 black pawn on d7 is offered only d6.

Input: {"board", "from": square of a pawn, "ep": en passant target square or null}. Return sorted pseudo-legal destinations: one step forward if empty; two steps from the starting rank if both squares are empty; diagonal captures of enemy pieces or onto the ep square. A destination on the last rank is expanded into four entries suffixed q, r, b, n.

split: open-access


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

N = 1
observations = []
def solve(x):
    b=x['board']; sq=x['from']; p=b[sq]; white=p=='P'
    f,r=ord(sq[0])-97,int(sq[1])-1
    d=1 if white else -1
    start=1 if white else 6
    last=7 if white else 0
    def at(ff,rr): return chr(97+ff)+str(rr+1)
    out=[]
    if 0<=r+d<8 and at(f,r+d) not in b:
        out.append(at(f,r+d))
        if r==start and at(f,r+2*d) not in b: out.append(at(f,r+2*d))
    for df in (-1,1):
        ff=f+df
        if not 0<=ff<8 or not 0<=r+d<8: continue
        t=at(ff,r+d); occ=b.get(t)
        if (occ) or t==x.get('ep'): out.append(t)
    res=[]
    for t in out:
        if int(t[1])-1==last: res+=[t+c for c in 'qrbn']
        else: res.append(t)
    return sorted(res)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r'])],
 [('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('en passant target', {'board': {'d5': 'p', 'e5': 'P'}, 'ep': 'd6', 'from': 'e5'}, ['d6', 'e6']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5']),
  ('white third rank', {'board': {'g3': 'P'}, 'ep': None, 'from': 'g3'}, ['g4'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5']),
  ('white third rank', {'board': {'g3': 'P'}, 'ep': None, 'from': 'g3'}, ['g4']),
  ('black blocked by own', {'board': {'a6': 'P', 'b6': 'p', 'b7': 'p'}, 'ep': None, 'from': 'b7'},
   ['a6'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r'])]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    b=x['board']; sq=x['from']; p=b[sq]; white=p=='P'
    f,r=ord(sq[0])-97,int(sq[1])-1
    d=1 if white else -1
    start=1 if white else 6
    last=7 if white else 0
    def at(ff,rr): return chr(97+ff)+str(rr+1)
    out=[]
    if 0<=r+d<8 and at(f,r+d) not in b:
        out.append(at(f,r+d))
        if r==start and at(f,r+2*d) not in b: out.append(at(f,r+2*d))
    for df in (-1,1):
        ff=f+df
        if not 0<=ff<8 or not 0<=r+d<8: continue
        t=at(ff,r+d); occ=b.get(t)
        if (occ and occ.isupper()) or t==x.get('ep'): out.append(t)
    res=[]
    for t in out:
        if int(t[1])-1==last: res+=[t+c for c in 'qrbn']
        else: res.append(t)
    return sorted(res)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r'])],
 [('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('en passant target', {'board': {'d5': 'p', 'e5': 'P'}, 'ep': 'd6', 'from': 'e5'}, ['d6', 'e6']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5']),
  ('white third rank', {'board': {'g3': 'P'}, 'ep': None, 'from': 'g3'}, ['g4'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5']),
  ('white third rank', {'board': {'g3': 'P'}, 'ep': None, 'from': 'g3'}, ['g4']),
  ('black blocked by own', {'board': {'a6': 'P', 'b6': 'p', 'b7': 'p'}, 'ep': None, 'from': 'b7'},
   ['a6'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r'])]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, 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 white pawn on d4 may capture the white bishop on e5.

Input: {"board", "from": square of a pawn, "ep": en passant target square or null}. Return sorted pseudo-legal destinations: one step forward if empty; two steps from the starting rank if both squares are empty; diagonal captures of enemy pieces or onto the ep square. A destination on the last rank is expanded into four entries suffixed q, r, b, n.

split: open-access


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

N = 1
observations = []
def solve(x):
    b=x['board']; sq=x['from']; p=b[sq]; white=p=='P'
    f,r=ord(sq[0])-97,int(sq[1])-1
    d=1 if white else -1
    start=1 if white else 6
    last=7 if white else 0
    def at(ff,rr): return chr(97+ff)+str(rr+1)
    out=[]
    if 0<=r+d<8 and at(f,r+d) not in b:
        out.append(at(f,r+d))
        if r==start and at(f,r+2*d) not in b: out.append(at(f,r+2*d))
    for df in (-1,1):
        ff=f+df
        if not 0<=ff<8 or not 0<=r+d<8: continue
        t=at(ff,r+d); occ=b.get(t)
        if (occ and occ.isupper()!=white) or t==x.get('ep'): out.append(t)
    res=[]
    for t in out:
        if int(t[1])==last: res+=[t+c for c in 'qrbn']
        else: res.append(t)
    return sorted(res)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r'])],
 [('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('en passant target', {'board': {'d5': 'p', 'e5': 'P'}, 'ep': 'd6', 'from': 'e5'}, ['d6', 'e6']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5']),
  ('white third rank', {'board': {'g3': 'P'}, 'ep': None, 'from': 'g3'}, ['g4'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('en passant target', {'board': {'d5': 'p', 'e5': 'P'}, 'ep': 'd6', 'from': 'e5'}, ['d6', 'e6']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5']),
  ('white third rank', {'board': {'g3': 'P'}, 'ep': None, 'from': 'g3'}, ['g4']),
  ('black blocked by own', {'board': {'a6': 'P', 'b6': 'p', 'b7': 'p'}, 'ep': None, 'from': 'b7'},
   ['a6'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('black blocked by own', {'board': {'a6': 'P', 'b6': 'p', 'b7': 'p'}, 'ep': None, 'from': 'b7'},
   ['a6'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r'])]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    b=x['board']; sq=x['from']; p=b[sq]; white=p=='P'
    f,r=ord(sq[0])-97,int(sq[1])-1
    d=1 if white else -1
    start=1 if white else 6
    last=7 if white else 0
    def at(ff,rr): return chr(97+ff)+str(rr+1)
    out=[]
    if 0<=r+d<8 and at(f,r+d) not in b:
        out.append(at(f,r+d))
        if r==start and at(f,r+2*d) not in b: out.append(at(f,r+2*d))
    for df in (-1,1):
        ff=f+df
        if not 0<=ff<8 or not 0<=r+d<8: continue
        t=at(ff,r+d); occ=b.get(t)
        if (occ and occ.isupper()!=white) or t==x.get('ep'): out.append(t)
    res=[]
    for t in out:
        if int(t[1])-1==7: res+=[t+c for c in 'qrbn']
        else: res.append(t)
    return sorted(res)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r'])],
 [('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('en passant target', {'board': {'d5': 'p', 'e5': 'P'}, 'ep': 'd6', 'from': 'e5'}, ['d6', 'e6']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5']),
  ('white third rank', {'board': {'g3': 'P'}, 'ep': None, 'from': 'g3'}, ['g4'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('en passant target', {'board': {'d5': 'p', 'e5': 'P'}, 'ep': 'd6', 'from': 'e5'}, ['d6', 'e6']),
  ('black on sixth rank', {'board': {'a6': 'p'}, 'ep': None, 'from': 'a6'}, ['a5']),
  ('white third rank', {'board': {'g3': 'P'}, 'ep': None, 'from': 'g3'}, ['g4']),
  ('black blocked by own', {'board': {'a6': 'P', 'b6': 'p', 'b7': 'p'}, 'ep': None, 'from': 'b7'},
   ['a6'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r']),
  ('black blocked by own', {'board': {'a6': 'P', 'b6': 'p', 'b7': 'p'}, 'ep': None, 'from': 'b7'},
   ['a6'])],
 [('white double push', {'board': {'e2': 'P'}, 'ep': None, 'from': 'e2'}, ['e3', 'e4']),
  ('black double push', {'board': {'d7': 'p'}, 'ep': None, 'from': 'd7'}, ['d5', 'd6']),
  ('blocked jump', {'board': {'e2': 'P', 'e3': 'n'}, 'ep': None, 'from': 'e2'}, []),
  ('far square blocked', {'board': {'c5': 'P', 'c7': 'p'}, 'ep': None, 'from': 'c7'}, ['c6']),
  ('captures both colours', {'board': {'c5': 'p', 'd4': 'P', 'e5': 'B'}, 'ep': None, 'from': 'd4'},
   ['c5', 'd5']),
  ('black captures',
   {'board': {'e5': 'P', 'f5': 'P', 'f6': 'p', 'g5': 'n'}, 'ep': None, 'from': 'f6'}, ['e5']),
  ('white promotion', {'board': {'a8': 'r', 'b7': 'P'}, 'ep': None, 'from': 'b7'},
   ['a8b', 'a8n', 'a8q', 'a8r', 'b8b', 'b8n', 'b8q', 'b8r']),
  ('black promotion', {'board': {'h2': 'p'}, 'ep': None, 'from': 'h2'},
   ['h1b', 'h1n', 'h1q', 'h1r'])]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, 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 white pawn arriving on the seventh rank is expanded into promotion moves, while the eighth rank is not.

Input: {"board", "from": square of a pawn, "ep": en passant target square or null}. Return sorted pseudo-legal destinations: one step forward if empty; two steps from the starting rank if both squares are empty; diagonal captures of enemy pieces or onto the ep square. A destination on the last rank is expanded into four entries suffixed q, r, b, n.

split: open-access