broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import collections
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key(h):
        vals=[R.index(c[0])+2 for c in h]
        cnt=collections.Counter(vals)
        groups=sorted(cnt.items(), key=lambda kv:(kv[1],kv[0]), reverse=True)
        ranks=[v for v,n in groups]
        shape=[n for v,n in groups]
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (max(vals)-min(vals)==4 or sorted(vals)==[2,3,4,5,14])
        if straight:
            ranks=[5] if sorted(vals)==[2,3,4,5,14] else [max(vals)]
        if straight and flush: cat=8
        elif shape==[4,1]: cat=7
        elif shape==[3,2]: cat=6
        elif flush: cat=5
        elif straight: cat=4
        elif shape==[3,1,1]: cat=3
        elif shape==[2,2,1]: cat=2
        elif shape==[2,1,1,1]: cat=1
        else: cat=0
        return (cat, ranks)
    a,b=key(x[0]),key(x[1])
    return 1 if a>=b else -1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('wheel vs six-high straight', [['Ah', '2d', '3c', '4s', '5h'], ['2h', '3d', '4c', '5s', '6h']],
   -1),
  ('six-high vs wheel', [['2c', '3h', '4d', '5c', '6s'], ['As', '2c', '3d', '4h', '5d']], 1),
  ('pair of twos vs ace high kickers',
   [['2h', '2d', 'Kc', 'Qs', 'Jh'], ['3h', '3d', '4c', '5s', '7h']], -1),
  ('full house trips first', [['3h', '3d', '3c', 'As', 'Ah'], ['Kh', 'Kd', '2c', '2s', '2h']], 1),
  ('identical ranks different suits',
   [['Ah', 'Kd', '9c', '7s', '4h'], ['As', 'Kc', '9d', '7h', '4d']], 0),
  ('split straights', [['9h', 'Td', 'Jc', 'Qs', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 0),
  ('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('straight loses to flush', [['9s', 'Tc', 'Jd', 'Qh', 'Kd'], ['2c', '5c', '8c', 'Tc', 'Qc']],
   -1)],
 [('full house trips first', [['3h', '3d', '3c', 'As', 'Ah'], ['Kh', 'Kd', '2c', '2s', '2h']], 1),
  ('identical ranks different suits',
   [['Ah', 'Kd', '9c', '7s', '4h'], ['As', 'Kc', '9d', '7h', '4d']], 0),
  ('split straights', [['9h', 'Td', 'Jc', 'Qs', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 0),
  ('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('straight loses to flush', [['9s', 'Tc', 'Jd', 'Qh', 'Kd'], ['2c', '5c', '8c', 'Tc', 'Qc']], -1),
  ('paired five-card span', [['5h', '5d', '6c', '7s', '9h'], ['Ah', 'Kd', 'Qc', '8s', '4h']], 1),
  ('paired span vs two pair', [['5h', '5d', '6c', '7s', '9h'], ['3h', '3d', '2c', '2s', 'Kh']], -1),
  ('two pair vs paired span', [['Jh', 'Jd', '2c', '2s', 'Kh'], ['8h', '8d', '6c', '7s', '9h']], 1)],
 [('identical ranks different suits',
   [['Ah', 'Kd', '9c', '7s', '4h'], ['As', 'Kc', '9d', '7h', '4d']], 0),
  ('split straights', [['9h', 'Td', 'Jc', 'Qs', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 0),
  ('paired five-card span', [['5h', '5d', '6c', '7s', '9h'], ['Ah', 'Kd', 'Qc', '8s', '4h']], 1),
  ('paired span vs two pair', [['5h', '5d', '6c', '7s', '9h'], ['3h', '3d', '2c', '2s', 'Kh']], -1),
  ('two pair vs paired span', [['Jh', 'Jd', '2c', '2s', 'Kh'], ['8h', '8d', '6c', '7s', '9h']], 1),
  ('two pair high pair first', [['Kh', 'Kd', '3c', '3s', '9h'], ['Qh', 'Qd', 'Jc', 'Js', '2h']], 1),
  ('kicker decides pair', [['Qh', 'Qd', 'Ac', '4s', '2h'], ['Qs', 'Qc', 'Kc', '9s', '8h']], 1),
  ('trips vs two pair', [['7h', '7d', '7c', '2s', '3h'], ['Ah', 'Ad', 'Kc', 'Ks', '2h']], 1)],
 [('identical ranks different suits',
   [['Ah', 'Kd', '9c', '7s', '4h'], ['As', 'Kc', '9d', '7h', '4d']], 0),
  ('split straights', [['9h', 'Td', 'Jc', 'Qs', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 0),
  ('two pair high pair first', [['Kh', 'Kd', '3c', '3s', '9h'], ['Qh', 'Qd', 'Jc', 'Js', '2h']], 1),
  ('kicker decides pair', [['Qh', 'Qd', 'Ac', '4s', '2h'], ['Qs', 'Qc', 'Kc', '9s', '8h']], 1),
  ('trips vs two pair', [['7h', '7d', '7c', '2s', '3h'], ['Ah', 'Ad', 'Kc', 'Ks', '2h']], 1),
  ('quads vs full house', [['4h', '4d', '4c', '4s', '2h'], ['Ah', 'Ad', 'Ac', 'Ks', 'Kh']], 1),
  ('high card ace vs king', [['Ah', '9d', '7c', '4s', '2h'], ['Kh', 'Qd', 'Jc', '9s', '7h']], 1),
  ('broadway vs wheel', [['Th', 'Jd', 'Qc', 'Ks', 'Ah'], ['As', '2c', '3d', '4h', '5d']], 1)],
 [('wheel vs six-high straight', [['Ah', '2d', '3c', '4s', '5h'], ['2h', '3d', '4c', '5s', '6h']],
   -1),
  ('six-high vs wheel', [['2c', '3h', '4d', '5c', '6s'], ['As', '2c', '3d', '4h', '5d']], 1),
  ('pair of twos vs ace high kickers',
   [['2h', '2d', 'Kc', 'Qs', 'Jh'], ['3h', '3d', '4c', '5s', '7h']], -1),
  ('identical ranks different suits',
   [['Ah', 'Kd', '9c', '7s', '4h'], ['As', 'Kc', '9d', '7h', '4d']], 0),
  ('split straights', [['9h', 'Td', 'Jc', 'Qs', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 0),
  ('quads vs full house', [['4h', '4d', '4c', '4s', '2h'], ['Ah', 'Ad', 'Ac', 'Ks', 'Kh']], 1),
  ('high card ace vs king', [['Ah', '9d', '7c', '4s', '2h'], ['Kh', 'Qd', 'Jc', '9s', '7h']], 1),
  ('broadway vs wheel', [['Th', 'Jd', 'Qc', 'Ks', 'Ah'], ['As', '2c', '3d', '4h', '5d']], 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
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key(h):
        vals=[R.index(c[0])+2 for c in h]
        cnt=collections.Counter(vals)
        groups=sorted(cnt.items(), key=lambda kv:(kv[1],kv[0]), reverse=True)
        ranks=[v for v,n in groups]
        shape=[n for v,n in groups]
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (max(vals)-min(vals)==4 or sorted(vals)==[2,3,4,5,14])
        if straight:
            ranks=[5] if sorted(vals)==[2,3,4,5,14] else [max(vals)]
        if straight and flush: cat=8
        elif shape==[4,1]: cat=7
        elif shape==[3,2]: cat=6
        elif flush: cat=5
        elif straight: cat=4
        elif shape==[3,1,1]: cat=3
        elif shape==[2,2,1]: cat=2
        elif shape==[2,1,1,1]: cat=1
        else: cat=0
        return (cat, ranks)
    a,b=key(x[0]),key(x[1])
    return (a>b)-(a<=b)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('wheel vs six-high straight', [['Ah', '2d', '3c', '4s', '5h'], ['2h', '3d', '4c', '5s', '6h']],
   -1),
  ('six-high vs wheel', [['2c', '3h', '4d', '5c', '6s'], ['As', '2c', '3d', '4h', '5d']], 1),
  ('pair of twos vs ace high kickers',
   [['2h', '2d', 'Kc', 'Qs', 'Jh'], ['3h', '3d', '4c', '5s', '7h']], -1),
  ('full house trips first', [['3h', '3d', '3c', 'As', 'Ah'], ['Kh', 'Kd', '2c', '2s', '2h']], 1),
  ('identical ranks different suits',
   [['Ah', 'Kd', '9c', '7s', '4h'], ['As', 'Kc', '9d', '7h', '4d']], 0),
  ('split straights', [['9h', 'Td', 'Jc', 'Qs', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 0),
  ('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('straight loses to flush', [['9s', 'Tc', 'Jd', 'Qh', 'Kd'], ['2c', '5c', '8c', 'Tc', 'Qc']],
   -1)],
 [('full house trips first', [['3h', '3d', '3c', 'As', 'Ah'], ['Kh', 'Kd', '2c', '2s', '2h']], 1),
  ('identical ranks different suits',
   [['Ah', 'Kd', '9c', '7s', '4h'], ['As', 'Kc', '9d', '7h', '4d']], 0),
  ('split straights', [['9h', 'Td', 'Jc', 'Qs', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 0),
  ('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('straight loses to flush', [['9s', 'Tc', 'Jd', 'Qh', 'Kd'], ['2c', '5c', '8c', 'Tc', 'Qc']], -1),
  ('paired five-card span', [['5h', '5d', '6c', '7s', '9h'], ['Ah', 'Kd', 'Qc', '8s', '4h']], 1),
  ('paired span vs two pair', [['5h', '5d', '6c', '7s', '9h'], ['3h', '3d', '2c', '2s', 'Kh']], -1),
  ('two pair vs paired span', [['Jh', 'Jd', '2c', '2s', 'Kh'], ['8h', '8d', '6c', '7s', '9h']], 1)],
 [('identical ranks different suits',
   [['Ah', 'Kd', '9c', '7s', '4h'], ['As', 'Kc', '9d', '7h', '4d']], 0),
  ('split straights', [['9h', 'Td', 'Jc', 'Qs', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 0),
  ('paired five-card span', [['5h', '5d', '6c', '7s', '9h'], ['Ah', 'Kd', 'Qc', '8s', '4h']], 1),
  ('paired span vs two pair', [['5h', '5d', '6c', '7s', '9h'], ['3h', '3d', '2c', '2s', 'Kh']], -1),
  ('two pair vs paired span', [['Jh', 'Jd', '2c', '2s', 'Kh'], ['8h', '8d', '6c', '7s', '9h']], 1),
  ('two pair high pair first', [['Kh', 'Kd', '3c', '3s', '9h'], ['Qh', 'Qd', 'Jc', 'Js', '2h']], 1),
  ('kicker decides pair', [['Qh', 'Qd', 'Ac', '4s', '2h'], ['Qs', 'Qc', 'Kc', '9s', '8h']], 1),
  ('trips vs two pair', [['7h', '7d', '7c', '2s', '3h'], ['Ah', 'Ad', 'Kc', 'Ks', '2h']], 1)],
 [('identical ranks different suits',
   [['Ah', 'Kd', '9c', '7s', '4h'], ['As', 'Kc', '9d', '7h', '4d']], 0),
  ('split straights', [['9h', 'Td', 'Jc', 'Qs', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 0),
  ('two pair high pair first', [['Kh', 'Kd', '3c', '3s', '9h'], ['Qh', 'Qd', 'Jc', 'Js', '2h']], 1),
  ('kicker decides pair', [['Qh', 'Qd', 'Ac', '4s', '2h'], ['Qs', 'Qc', 'Kc', '9s', '8h']], 1),
  ('trips vs two pair', [['7h', '7d', '7c', '2s', '3h'], ['Ah', 'Ad', 'Kc', 'Ks', '2h']], 1),
  ('quads vs full house', [['4h', '4d', '4c', '4s', '2h'], ['Ah', 'Ad', 'Ac', 'Ks', 'Kh']], 1),
  ('high card ace vs king', [['Ah', '9d', '7c', '4s', '2h'], ['Kh', 'Qd', 'Jc', '9s', '7h']], 1),
  ('broadway vs wheel', [['Th', 'Jd', 'Qc', 'Ks', 'Ah'], ['As', '2c', '3d', '4h', '5d']], 1)],
 [('wheel vs six-high straight', [['Ah', '2d', '3c', '4s', '5h'], ['2h', '3d', '4c', '5s', '6h']],
   -1),
  ('six-high vs wheel', [['2c', '3h', '4d', '5c', '6s'], ['As', '2c', '3d', '4h', '5d']], 1),
  ('pair of twos vs ace high kickers',
   [['2h', '2d', 'Kc', 'Qs', 'Jh'], ['3h', '3d', '4c', '5s', '7h']], -1),
  ('identical ranks different suits',
   [['Ah', 'Kd', '9c', '7s', '4h'], ['As', 'Kc', '9d', '7h', '4d']], 0),
  ('split straights', [['9h', 'Td', 'Jc', 'Qs', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 0),
  ('quads vs full house', [['4h', '4d', '4c', '4s', '2h'], ['Ah', 'Ad', 'Ac', 'Ks', 'Kh']], 1),
  ('high card ace vs king', [['Ah', '9d', '7c', '4s', '2h'], ['Kh', 'Qd', 'Jc', '9s', '7h']], 1),
  ('broadway vs wheel', [['Th', 'Jd', 'Qc', 'Ks', 'Ah'], ['As', '2c', '3d', '4h', '5d']], 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:
Two identical straights in different suits are not split; hand_a is paid the whole pot.

Input: [hand_a, hand_b], each five distinct cards "Rs" (ranks 23456789TJQKA, suits cdhs). Return 1 if hand_a wins, -1 if hand_b wins, 0 for a split. Categories rank in the standard order; within a category compare rank groups by (group size, rank) descending; a wheel straight is five-high; suits never break ties.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import collections
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key(h):
        vals=[R.index(c[0])+2 for c in h]
        cnt=collections.Counter(vals)
        groups=sorted(cnt.items(), key=lambda kv:(kv[1],kv[0]), reverse=True)
        ranks=[v for v,n in groups]
        shape=[n for v,n in groups]
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (max(vals)-min(vals)==4 or sorted(vals)==[2,3,4,5,14])
        if straight:
            ranks=[5] if sorted(vals)==[2,3,4,5,14] else [max(vals)]
        if straight and flush: cat=8
        elif shape==[4,1]: cat=7
        elif shape==[3,2]: cat=6
        elif straight: cat=5
        elif flush: cat=4
        elif shape==[3,1,1]: cat=3
        elif shape==[2,2,1]: cat=2
        elif shape==[2,1,1,1]: cat=1
        else: cat=0
        return (cat, ranks)
    a,b=key(x[0]),key(x[1])
    return (a>b)-(a<b)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('wheel vs six-high straight', [['Ah', '2d', '3c', '4s', '5h'], ['2h', '3d', '4c', '5s', '6h']],
   -1),
  ('six-high vs wheel', [['2c', '3h', '4d', '5c', '6s'], ['As', '2c', '3d', '4h', '5d']], 1),
  ('pair of twos vs ace high kickers',
   [['2h', '2d', 'Kc', 'Qs', 'Jh'], ['3h', '3d', '4c', '5s', '7h']], -1),
  ('full house trips first', [['3h', '3d', '3c', 'As', 'Ah'], ['Kh', 'Kd', '2c', '2s', '2h']], 1),
  ('identical ranks different suits',
   [['Ah', 'Kd', '9c', '7s', '4h'], ['As', 'Kc', '9d', '7h', '4d']], 0),
  ('split straights', [['9h', 'Td', 'Jc', 'Qs', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 0),
  ('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('straight loses to flush', [['9s', 'Tc', 'Jd', 'Qh', 'Kd'], ['2c', '5c', '8c', 'Tc', 'Qc']],
   -1)],
 [('full house trips first', [['3h', '3d', '3c', 'As', 'Ah'], ['Kh', 'Kd', '2c', '2s', '2h']], 1),
  ('identical ranks different suits',
   [['Ah', 'Kd', '9c', '7s', '4h'], ['As', 'Kc', '9d', '7h', '4d']], 0),
  ('split straights', [['9h', 'Td', 'Jc', 'Qs', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 0),
  ('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('straight loses to flush', [['9s', 'Tc', 'Jd', 'Qh', 'Kd'], ['2c', '5c', '8c', 'Tc', 'Qc']], -1),
  ('paired five-card span', [['5h', '5d', '6c', '7s', '9h'], ['Ah', 'Kd', 'Qc', '8s', '4h']], 1),
  ('paired span vs two pair', [['5h', '5d', '6c', '7s', '9h'], ['3h', '3d', '2c', '2s', 'Kh']], -1),
  ('two pair vs paired span', [['Jh', 'Jd', '2c', '2s', 'Kh'], ['8h', '8d', '6c', '7s', '9h']], 1)],
 [('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('straight loses to flush', [['9s', 'Tc', 'Jd', 'Qh', 'Kd'], ['2c', '5c', '8c', 'Tc', 'Qc']], -1),
  ('paired five-card span', [['5h', '5d', '6c', '7s', '9h'], ['Ah', 'Kd', 'Qc', '8s', '4h']], 1),
  ('paired span vs two pair', [['5h', '5d', '6c', '7s', '9h'], ['3h', '3d', '2c', '2s', 'Kh']], -1),
  ('two pair vs paired span', [['Jh', 'Jd', '2c', '2s', 'Kh'], ['8h', '8d', '6c', '7s', '9h']], 1),
  ('two pair high pair first', [['Kh', 'Kd', '3c', '3s', '9h'], ['Qh', 'Qd', 'Jc', 'Js', '2h']], 1),
  ('kicker decides pair', [['Qh', 'Qd', 'Ac', '4s', '2h'], ['Qs', 'Qc', 'Kc', '9s', '8h']], 1),
  ('trips vs two pair', [['7h', '7d', '7c', '2s', '3h'], ['Ah', 'Ad', 'Kc', 'Ks', '2h']], 1)],
 [('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('straight loses to flush', [['9s', 'Tc', 'Jd', 'Qh', 'Kd'], ['2c', '5c', '8c', 'Tc', 'Qc']], -1),
  ('two pair high pair first', [['Kh', 'Kd', '3c', '3s', '9h'], ['Qh', 'Qd', 'Jc', 'Js', '2h']], 1),
  ('kicker decides pair', [['Qh', 'Qd', 'Ac', '4s', '2h'], ['Qs', 'Qc', 'Kc', '9s', '8h']], 1),
  ('trips vs two pair', [['7h', '7d', '7c', '2s', '3h'], ['Ah', 'Ad', 'Kc', 'Ks', '2h']], 1),
  ('quads vs full house', [['4h', '4d', '4c', '4s', '2h'], ['Ah', 'Ad', 'Ac', 'Ks', 'Kh']], 1),
  ('high card ace vs king', [['Ah', '9d', '7c', '4s', '2h'], ['Kh', 'Qd', 'Jc', '9s', '7h']], 1),
  ('broadway vs wheel', [['Th', 'Jd', 'Qc', 'Ks', 'Ah'], ['As', '2c', '3d', '4h', '5d']], 1)],
 [('wheel vs six-high straight', [['Ah', '2d', '3c', '4s', '5h'], ['2h', '3d', '4c', '5s', '6h']],
   -1),
  ('six-high vs wheel', [['2c', '3h', '4d', '5c', '6s'], ['As', '2c', '3d', '4h', '5d']], 1),
  ('pair of twos vs ace high kickers',
   [['2h', '2d', 'Kc', 'Qs', 'Jh'], ['3h', '3d', '4c', '5s', '7h']], -1),
  ('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('straight loses to flush', [['9s', 'Tc', 'Jd', 'Qh', 'Kd'], ['2c', '5c', '8c', 'Tc', 'Qc']], -1),
  ('quads vs full house', [['4h', '4d', '4c', '4s', '2h'], ['Ah', 'Ad', 'Ac', 'Ks', 'Kh']], 1),
  ('high card ace vs king', [['Ah', '9d', '7c', '4s', '2h'], ['Kh', 'Qd', 'Jc', '9s', '7h']], 1),
  ('broadway vs wheel', [['Th', 'Jd', 'Qc', 'Ks', 'Ah'], ['As', '2c', '3d', '4h', '5d']], 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 collections
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key(h):
        vals=[R.index(c[0])+2 for c in h]
        cnt=collections.Counter(vals)
        groups=sorted(cnt.items(), key=lambda kv:(kv[1],kv[0]), reverse=True)
        ranks=[v for v,n in groups]
        shape=[n for v,n in groups]
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (max(vals)-min(vals)==4 or sorted(vals)==[2,3,4,5,14])
        if straight:
            ranks=[5] if sorted(vals)==[2,3,4,5,14] else [max(vals)]
        if straight and flush: cat=8
        elif shape==[4,1]: cat=7
        elif shape==[3,2]: cat=6
        elif flush: cat=4
        elif straight: cat=4
        elif shape==[3,1,1]: cat=3
        elif shape==[2,2,1]: cat=2
        elif shape==[2,1,1,1]: cat=1
        else: cat=0
        return (cat, ranks)
    a,b=key(x[0]),key(x[1])
    return (a>b)-(a<b)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('wheel vs six-high straight', [['Ah', '2d', '3c', '4s', '5h'], ['2h', '3d', '4c', '5s', '6h']],
   -1),
  ('six-high vs wheel', [['2c', '3h', '4d', '5c', '6s'], ['As', '2c', '3d', '4h', '5d']], 1),
  ('pair of twos vs ace high kickers',
   [['2h', '2d', 'Kc', 'Qs', 'Jh'], ['3h', '3d', '4c', '5s', '7h']], -1),
  ('full house trips first', [['3h', '3d', '3c', 'As', 'Ah'], ['Kh', 'Kd', '2c', '2s', '2h']], 1),
  ('identical ranks different suits',
   [['Ah', 'Kd', '9c', '7s', '4h'], ['As', 'Kc', '9d', '7h', '4d']], 0),
  ('split straights', [['9h', 'Td', 'Jc', 'Qs', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 0),
  ('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('straight loses to flush', [['9s', 'Tc', 'Jd', 'Qh', 'Kd'], ['2c', '5c', '8c', 'Tc', 'Qc']],
   -1)],
 [('full house trips first', [['3h', '3d', '3c', 'As', 'Ah'], ['Kh', 'Kd', '2c', '2s', '2h']], 1),
  ('identical ranks different suits',
   [['Ah', 'Kd', '9c', '7s', '4h'], ['As', 'Kc', '9d', '7h', '4d']], 0),
  ('split straights', [['9h', 'Td', 'Jc', 'Qs', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 0),
  ('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('straight loses to flush', [['9s', 'Tc', 'Jd', 'Qh', 'Kd'], ['2c', '5c', '8c', 'Tc', 'Qc']], -1),
  ('paired five-card span', [['5h', '5d', '6c', '7s', '9h'], ['Ah', 'Kd', 'Qc', '8s', '4h']], 1),
  ('paired span vs two pair', [['5h', '5d', '6c', '7s', '9h'], ['3h', '3d', '2c', '2s', 'Kh']], -1),
  ('two pair vs paired span', [['Jh', 'Jd', '2c', '2s', 'Kh'], ['8h', '8d', '6c', '7s', '9h']], 1)],
 [('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('straight loses to flush', [['9s', 'Tc', 'Jd', 'Qh', 'Kd'], ['2c', '5c', '8c', 'Tc', 'Qc']], -1),
  ('paired five-card span', [['5h', '5d', '6c', '7s', '9h'], ['Ah', 'Kd', 'Qc', '8s', '4h']], 1),
  ('paired span vs two pair', [['5h', '5d', '6c', '7s', '9h'], ['3h', '3d', '2c', '2s', 'Kh']], -1),
  ('two pair vs paired span', [['Jh', 'Jd', '2c', '2s', 'Kh'], ['8h', '8d', '6c', '7s', '9h']], 1),
  ('two pair high pair first', [['Kh', 'Kd', '3c', '3s', '9h'], ['Qh', 'Qd', 'Jc', 'Js', '2h']], 1),
  ('kicker decides pair', [['Qh', 'Qd', 'Ac', '4s', '2h'], ['Qs', 'Qc', 'Kc', '9s', '8h']], 1),
  ('trips vs two pair', [['7h', '7d', '7c', '2s', '3h'], ['Ah', 'Ad', 'Kc', 'Ks', '2h']], 1)],
 [('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('straight loses to flush', [['9s', 'Tc', 'Jd', 'Qh', 'Kd'], ['2c', '5c', '8c', 'Tc', 'Qc']], -1),
  ('two pair high pair first', [['Kh', 'Kd', '3c', '3s', '9h'], ['Qh', 'Qd', 'Jc', 'Js', '2h']], 1),
  ('kicker decides pair', [['Qh', 'Qd', 'Ac', '4s', '2h'], ['Qs', 'Qc', 'Kc', '9s', '8h']], 1),
  ('trips vs two pair', [['7h', '7d', '7c', '2s', '3h'], ['Ah', 'Ad', 'Kc', 'Ks', '2h']], 1),
  ('quads vs full house', [['4h', '4d', '4c', '4s', '2h'], ['Ah', 'Ad', 'Ac', 'Ks', 'Kh']], 1),
  ('high card ace vs king', [['Ah', '9d', '7c', '4s', '2h'], ['Kh', 'Qd', 'Jc', '9s', '7h']], 1),
  ('broadway vs wheel', [['Th', 'Jd', 'Qc', 'Ks', 'Ah'], ['As', '2c', '3d', '4h', '5d']], 1)],
 [('wheel vs six-high straight', [['Ah', '2d', '3c', '4s', '5h'], ['2h', '3d', '4c', '5s', '6h']],
   -1),
  ('six-high vs wheel', [['2c', '3h', '4d', '5c', '6s'], ['As', '2c', '3d', '4h', '5d']], 1),
  ('pair of twos vs ace high kickers',
   [['2h', '2d', 'Kc', 'Qs', 'Jh'], ['3h', '3d', '4c', '5s', '7h']], -1),
  ('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('straight loses to flush', [['9s', 'Tc', 'Jd', 'Qh', 'Kd'], ['2c', '5c', '8c', 'Tc', 'Qc']], -1),
  ('quads vs full house', [['4h', '4d', '4c', '4s', '2h'], ['Ah', 'Ad', 'Ac', 'Ks', 'Kh']], 1),
  ('high card ace vs king', [['Ah', '9d', '7c', '4s', '2h'], ['Kh', 'Qd', 'Jc', '9s', '7h']], 1),
  ('broadway vs wheel', [['Th', 'Jd', 'Qc', 'Ks', 'Ah'], ['As', '2c', '3d', '4h', '5d']], 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 king-high straight beats a king-high flush.

Input: [hand_a, hand_b], each five distinct cards "Rs" (ranks 23456789TJQKA, suits cdhs). Return 1 if hand_a wins, -1 if hand_b wins, 0 for a split. Categories rank in the standard order; within a category compare rank groups by (group size, rank) descending; a wheel straight is five-high; suits never break ties.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import collections
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key(h):
        vals=[R.index(c[0])+2 for c in h]
        cnt=collections.Counter(vals)
        groups=sorted(cnt.items(), key=lambda kv:(kv[1],kv[0]), reverse=True)
        ranks=[v for v,n in groups]
        shape=[n for v,n in groups]
        flush=len({c[1] for c in h})==1
        straight=len(cnt)>=4 and (max(vals)-min(vals)==4 or sorted(vals)==[2,3,4,5,14])
        if straight:
            ranks=[5] if sorted(vals)==[2,3,4,5,14] else [max(vals)]
        if straight and flush: cat=8
        elif shape==[4,1]: cat=7
        elif shape==[3,2]: cat=6
        elif flush: cat=5
        elif straight: cat=4
        elif shape==[3,1,1]: cat=3
        elif shape==[2,2,1]: cat=2
        elif shape==[2,1,1,1]: cat=1
        else: cat=0
        return (cat, ranks)
    a,b=key(x[0]),key(x[1])
    return (a>b)-(a<b)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('wheel vs six-high straight', [['Ah', '2d', '3c', '4s', '5h'], ['2h', '3d', '4c', '5s', '6h']],
   -1),
  ('six-high vs wheel', [['2c', '3h', '4d', '5c', '6s'], ['As', '2c', '3d', '4h', '5d']], 1),
  ('pair of twos vs ace high kickers',
   [['2h', '2d', 'Kc', 'Qs', 'Jh'], ['3h', '3d', '4c', '5s', '7h']], -1),
  ('full house trips first', [['3h', '3d', '3c', 'As', 'Ah'], ['Kh', 'Kd', '2c', '2s', '2h']], 1),
  ('identical ranks different suits',
   [['Ah', 'Kd', '9c', '7s', '4h'], ['As', 'Kc', '9d', '7h', '4d']], 0),
  ('split straights', [['9h', 'Td', 'Jc', 'Qs', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 0),
  ('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('paired span vs two pair', [['5h', '5d', '6c', '7s', '9h'], ['3h', '3d', '2c', '2s', 'Kh']],
   -1)],
 [('full house trips first', [['3h', '3d', '3c', 'As', 'Ah'], ['Kh', 'Kd', '2c', '2s', '2h']], 1),
  ('identical ranks different suits',
   [['Ah', 'Kd', '9c', '7s', '4h'], ['As', 'Kc', '9d', '7h', '4d']], 0),
  ('split straights', [['9h', 'Td', 'Jc', 'Qs', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 0),
  ('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('straight loses to flush', [['9s', 'Tc', 'Jd', 'Qh', 'Kd'], ['2c', '5c', '8c', 'Tc', 'Qc']], -1),
  ('paired five-card span', [['5h', '5d', '6c', '7s', '9h'], ['Ah', 'Kd', 'Qc', '8s', '4h']], 1),
  ('paired span vs two pair', [['5h', '5d', '6c', '7s', '9h'], ['3h', '3d', '2c', '2s', 'Kh']], -1),
  ('two pair vs paired span', [['Jh', 'Jd', '2c', '2s', 'Kh'], ['8h', '8d', '6c', '7s', '9h']], 1)],
 [('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('straight loses to flush', [['9s', 'Tc', 'Jd', 'Qh', 'Kd'], ['2c', '5c', '8c', 'Tc', 'Qc']], -1),
  ('paired five-card span', [['5h', '5d', '6c', '7s', '9h'], ['Ah', 'Kd', 'Qc', '8s', '4h']], 1),
  ('paired span vs two pair', [['5h', '5d', '6c', '7s', '9h'], ['3h', '3d', '2c', '2s', 'Kh']], -1),
  ('two pair vs paired span', [['Jh', 'Jd', '2c', '2s', 'Kh'], ['8h', '8d', '6c', '7s', '9h']], 1),
  ('two pair high pair first', [['Kh', 'Kd', '3c', '3s', '9h'], ['Qh', 'Qd', 'Jc', 'Js', '2h']], 1),
  ('kicker decides pair', [['Qh', 'Qd', 'Ac', '4s', '2h'], ['Qs', 'Qc', 'Kc', '9s', '8h']], 1),
  ('trips vs two pair', [['7h', '7d', '7c', '2s', '3h'], ['Ah', 'Ad', 'Kc', 'Ks', '2h']], 1)],
 [('paired span vs two pair', [['5h', '5d', '6c', '7s', '9h'], ['3h', '3d', '2c', '2s', 'Kh']], -1),
  ('two pair vs paired span', [['Jh', 'Jd', '2c', '2s', 'Kh'], ['8h', '8d', '6c', '7s', '9h']], 1),
  ('two pair high pair first', [['Kh', 'Kd', '3c', '3s', '9h'], ['Qh', 'Qd', 'Jc', 'Js', '2h']], 1),
  ('kicker decides pair', [['Qh', 'Qd', 'Ac', '4s', '2h'], ['Qs', 'Qc', 'Kc', '9s', '8h']], 1),
  ('trips vs two pair', [['7h', '7d', '7c', '2s', '3h'], ['Ah', 'Ad', 'Kc', 'Ks', '2h']], 1),
  ('quads vs full house', [['4h', '4d', '4c', '4s', '2h'], ['Ah', 'Ad', 'Ac', 'Ks', 'Kh']], 1),
  ('high card ace vs king', [['Ah', '9d', '7c', '4s', '2h'], ['Kh', 'Qd', 'Jc', '9s', '7h']], 1),
  ('broadway vs wheel', [['Th', 'Jd', 'Qc', 'Ks', 'Ah'], ['As', '2c', '3d', '4h', '5d']], 1)],
 [('wheel vs six-high straight', [['Ah', '2d', '3c', '4s', '5h'], ['2h', '3d', '4c', '5s', '6h']],
   -1),
  ('six-high vs wheel', [['2c', '3h', '4d', '5c', '6s'], ['As', '2c', '3d', '4h', '5d']], 1),
  ('pair of twos vs ace high kickers',
   [['2h', '2d', 'Kc', 'Qs', 'Jh'], ['3h', '3d', '4c', '5s', '7h']], -1),
  ('paired span vs two pair', [['5h', '5d', '6c', '7s', '9h'], ['3h', '3d', '2c', '2s', 'Kh']], -1),
  ('trips vs two pair', [['7h', '7d', '7c', '2s', '3h'], ['Ah', 'Ad', 'Kc', 'Ks', '2h']], 1),
  ('quads vs full house', [['4h', '4d', '4c', '4s', '2h'], ['Ah', 'Ad', 'Ac', 'Ks', 'Kh']], 1),
  ('high card ace vs king', [['Ah', '9d', '7c', '4s', '2h'], ['Kh', 'Qd', 'Jc', '9s', '7h']], 1),
  ('broadway vs wheel', [['Th', 'Jd', 'Qc', 'Ks', 'Ah'], ['As', '2c', '3d', '4h', '5d']], 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
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key(h):
        vals=[R.index(c[0])+2 for c in h]
        cnt=collections.Counter(vals)
        groups=sorted(cnt.items(), key=lambda kv:(kv[1],kv[0]), reverse=True)
        ranks=[v for v,n in groups]
        shape=[n for v,n in groups]
        flush=len({c[1] for c in h})==1
        straight=len(vals)==5 and (max(vals)-min(vals)==4 or sorted(vals)==[2,3,4,5,14])
        if straight:
            ranks=[5] if sorted(vals)==[2,3,4,5,14] else [max(vals)]
        if straight and flush: cat=8
        elif shape==[4,1]: cat=7
        elif shape==[3,2]: cat=6
        elif flush: cat=5
        elif straight: cat=4
        elif shape==[3,1,1]: cat=3
        elif shape==[2,2,1]: cat=2
        elif shape==[2,1,1,1]: cat=1
        else: cat=0
        return (cat, ranks)
    a,b=key(x[0]),key(x[1])
    return (a>b)-(a<b)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('wheel vs six-high straight', [['Ah', '2d', '3c', '4s', '5h'], ['2h', '3d', '4c', '5s', '6h']],
   -1),
  ('six-high vs wheel', [['2c', '3h', '4d', '5c', '6s'], ['As', '2c', '3d', '4h', '5d']], 1),
  ('pair of twos vs ace high kickers',
   [['2h', '2d', 'Kc', 'Qs', 'Jh'], ['3h', '3d', '4c', '5s', '7h']], -1),
  ('full house trips first', [['3h', '3d', '3c', 'As', 'Ah'], ['Kh', 'Kd', '2c', '2s', '2h']], 1),
  ('identical ranks different suits',
   [['Ah', 'Kd', '9c', '7s', '4h'], ['As', 'Kc', '9d', '7h', '4d']], 0),
  ('split straights', [['9h', 'Td', 'Jc', 'Qs', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 0),
  ('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('paired span vs two pair', [['5h', '5d', '6c', '7s', '9h'], ['3h', '3d', '2c', '2s', 'Kh']],
   -1)],
 [('full house trips first', [['3h', '3d', '3c', 'As', 'Ah'], ['Kh', 'Kd', '2c', '2s', '2h']], 1),
  ('identical ranks different suits',
   [['Ah', 'Kd', '9c', '7s', '4h'], ['As', 'Kc', '9d', '7h', '4d']], 0),
  ('split straights', [['9h', 'Td', 'Jc', 'Qs', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 0),
  ('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('straight loses to flush', [['9s', 'Tc', 'Jd', 'Qh', 'Kd'], ['2c', '5c', '8c', 'Tc', 'Qc']], -1),
  ('paired five-card span', [['5h', '5d', '6c', '7s', '9h'], ['Ah', 'Kd', 'Qc', '8s', '4h']], 1),
  ('paired span vs two pair', [['5h', '5d', '6c', '7s', '9h'], ['3h', '3d', '2c', '2s', 'Kh']], -1),
  ('two pair vs paired span', [['Jh', 'Jd', '2c', '2s', 'Kh'], ['8h', '8d', '6c', '7s', '9h']], 1)],
 [('flush beats straight', [['2h', '7h', '9h', 'Jh', 'Kh'], ['9s', 'Tc', 'Jd', 'Qh', 'Kd']], 1),
  ('straight loses to flush', [['9s', 'Tc', 'Jd', 'Qh', 'Kd'], ['2c', '5c', '8c', 'Tc', 'Qc']], -1),
  ('paired five-card span', [['5h', '5d', '6c', '7s', '9h'], ['Ah', 'Kd', 'Qc', '8s', '4h']], 1),
  ('paired span vs two pair', [['5h', '5d', '6c', '7s', '9h'], ['3h', '3d', '2c', '2s', 'Kh']], -1),
  ('two pair vs paired span', [['Jh', 'Jd', '2c', '2s', 'Kh'], ['8h', '8d', '6c', '7s', '9h']], 1),
  ('two pair high pair first', [['Kh', 'Kd', '3c', '3s', '9h'], ['Qh', 'Qd', 'Jc', 'Js', '2h']], 1),
  ('kicker decides pair', [['Qh', 'Qd', 'Ac', '4s', '2h'], ['Qs', 'Qc', 'Kc', '9s', '8h']], 1),
  ('trips vs two pair', [['7h', '7d', '7c', '2s', '3h'], ['Ah', 'Ad', 'Kc', 'Ks', '2h']], 1)],
 [('paired span vs two pair', [['5h', '5d', '6c', '7s', '9h'], ['3h', '3d', '2c', '2s', 'Kh']], -1),
  ('two pair vs paired span', [['Jh', 'Jd', '2c', '2s', 'Kh'], ['8h', '8d', '6c', '7s', '9h']], 1),
  ('two pair high pair first', [['Kh', 'Kd', '3c', '3s', '9h'], ['Qh', 'Qd', 'Jc', 'Js', '2h']], 1),
  ('kicker decides pair', [['Qh', 'Qd', 'Ac', '4s', '2h'], ['Qs', 'Qc', 'Kc', '9s', '8h']], 1),
  ('trips vs two pair', [['7h', '7d', '7c', '2s', '3h'], ['Ah', 'Ad', 'Kc', 'Ks', '2h']], 1),
  ('quads vs full house', [['4h', '4d', '4c', '4s', '2h'], ['Ah', 'Ad', 'Ac', 'Ks', 'Kh']], 1),
  ('high card ace vs king', [['Ah', '9d', '7c', '4s', '2h'], ['Kh', 'Qd', 'Jc', '9s', '7h']], 1),
  ('broadway vs wheel', [['Th', 'Jd', 'Qc', 'Ks', 'Ah'], ['As', '2c', '3d', '4h', '5d']], 1)],
 [('wheel vs six-high straight', [['Ah', '2d', '3c', '4s', '5h'], ['2h', '3d', '4c', '5s', '6h']],
   -1),
  ('six-high vs wheel', [['2c', '3h', '4d', '5c', '6s'], ['As', '2c', '3d', '4h', '5d']], 1),
  ('pair of twos vs ace high kickers',
   [['2h', '2d', 'Kc', 'Qs', 'Jh'], ['3h', '3d', '4c', '5s', '7h']], -1),
  ('paired span vs two pair', [['5h', '5d', '6c', '7s', '9h'], ['3h', '3d', '2c', '2s', 'Kh']], -1),
  ('trips vs two pair', [['7h', '7d', '7c', '2s', '3h'], ['Ah', 'Ad', 'Kc', 'Ks', '2h']], 1),
  ('quads vs full house', [['4h', '4d', '4c', '4s', '2h'], ['Ah', 'Ad', 'Ac', 'Ks', 'Kh']], 1),
  ('high card ace vs king', [['Ah', '9d', '7c', '4s', '2h'], ['Kh', 'Qd', 'Jc', '9s', '7h']], 1),
  ('broadway vs wheel', [['Th', 'Jd', 'Qc', 'Ks', 'Ah'], ['As', '2c', '3d', '4h', '5d']], 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:
5-5-6-7-9 is scored as a straight and beats ace high.

Input: [hand_a, hand_b], each five distinct cards "Rs" (ranks 23456789TJQKA, suits cdhs). Return 1 if hand_a wins, -1 if hand_b wins, 0 for a split. Categories rank in the standard order; within a category compare rank groups by (group size, rank) descending; a wheel straight is five-high; suits never break ties.

split: open-access


prompt:
A-2-3-4-5 fails to qualify for low and loses to 7-5-4-3-2.

Input: {"a": five cards, "b": five cards}. Ace-to-five low: aces count 1, straights and flushes are ignored, any paired rank disqualifies, the highest card must be 8 or lower to qualify. Compare qualifying lows from the highest card downward; lower wins. Return "a", "b", "tie", or "none" when neither qualifies.

split: open-access


prompt:
2-2-4-6-8 is treated as an 8-6-4-2 low and wins the low pot.

Input: {"a": five cards, "b": five cards}. Ace-to-five low: aces count 1, straights and flushes are ignored, any paired rank disqualifies, the highest card must be 8 or lower to qualify. Compare qualifying lows from the highest card downward; lower wins. Return "a", "b", "tie", or "none" when neither qualifies.

split: open-access


prompt:
An 8-6-4-3-2 low is disqualified and the pot is not split.

Input: {"a": five cards, "b": five cards}. Ace-to-five low: aces count 1, straights and flushes are ignored, any paired rank disqualifies, the highest card must be 8 or lower to qualify. Compare qualifying lows from the highest card downward; lower wins. Return "a", "b", "tie", or "none" when neither qualifies.

split: open-access


prompt:
8-4-3-2-A beats 7-6-5-4-3 because its card total is smaller.

Input: {"a": five cards, "b": five cards}. Ace-to-five low: aces count 1, straights and flushes are ignored, any paired rank disqualifies, the highest card must be 8 or lower to qualify. Compare qualifying lows from the highest card downward; lower wins. Return "a", "b", "tie", or "none" when neither qualifies.

split: open-access


prompt:
A-2-3-4-5 all hearts and a 2-3-4-5-6 straight both fail to qualify for low.

Input: {"a": five cards, "b": five cards}. Ace-to-five low: aces count 1, straights and flushes are ignored, any paired rank disqualifies, the highest card must be 8 or lower to qualify. Compare qualifying lows from the highest card downward; lower wins. Return "a", "b", "tie", or "none" when neither qualifies.

split: open-access


prompt:
When only one player has a qualifying low, the other player is awarded the low.

Input: {"a": five cards, "b": five cards}. Ace-to-five low: aces count 1, straights and flushes are ignored, any paired rank disqualifies, the highest card must be 8 or lower to qualify. Compare qualifying lows from the highest card downward; lower wins. Return "a", "b", "tie", or "none" when neither qualifies.

split: open-access


prompt:
A-2-3-4-5 in a seven-card hand is not found as a straight.

Input: 5 to 7 distinct cards "Rs". Build a rank bitmask (bit r for rank value r, 2..14; the ace also sets bit 1). Return the top rank of the highest five-card straight contained in the ranks (5 for the wheel), or 0 if none.

split: open-access


prompt:
A wheel is reported as no straight although the ace bit is mirrored.

Input: 5 to 7 distinct cards "Rs". Build a rank bitmask (bit r for rank value r, 2..14; the ace also sets bit 1). Return the top rank of the highest five-card straight contained in the ranks (5 for the wheel), or 0 if none.

split: open-access


prompt:
9-T-J-Q with no eight or king is reported as a queen-high straight.

Input: 5 to 7 distinct cards "Rs". Build a rank bitmask (bit r for rank value r, 2..14; the ace also sets bit 1). Return the top rank of the highest five-card straight contained in the ranks (5 for the wheel), or 0 if none.

split: open-access


prompt:
A pair inside a straight corrupts the mask and hides or invents straights.

Input: 5 to 7 distinct cards "Rs". Build a rank bitmask (bit r for rank value r, 2..14; the ace also sets bit 1). Return the top rank of the highest five-card straight contained in the ranks (5 for the wheel), or 0 if none.

split: open-access


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

N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    P=[2,3,5,7,11,13,17,19,23,29,31,37,39]
    prod=1
    for c in x:
        prod*=P[R.index('T' if c[:-1]=='10' else c[:-1])]
    exps=[]
    for p in P:
        e=0
        while prod%p==0:
            prod//=p
            e+=1
        if e: exps.append(e)
    exps.sort(reverse=True)
    names={(4,1):'four of a kind',(3,2):'full house',(3,1,1):'three of a kind',(2,2,1):'two pair',(2,1,1,1):'one pair',(1,1,1,1,1):'high card'}
    return names[tuple(exps)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('high card low', ['2h', '3d', '5c', '7s', '9h'], 'high card'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair')],
 [('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with three', ['Ah', '3d', '9c', '7s', '4h'], 'high card'),
  ('ace with king', ['Ah', 'Kd', 'Qc', '7s', '4h'], 'high card'),
  ('high card low', ['2h', '3d', '5c', '7s', '9h'], 'high card'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')],
 [('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with three', ['Ah', '3d', '9c', '7s', '4h'], 'high card'),
  ('ace with king', ['Ah', 'Kd', 'Qc', '7s', '4h'], 'high card'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('deuce and ace', ['2h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')],
 [('ace with three', ['Ah', '3d', '9c', '7s', '4h'], 'high card'),
  ('ace with king', ['Ah', 'Kd', 'Qc', '7s', '4h'], 'high card'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('deuce and ace', ['2h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('ten token with ace', ['10h', 'Ad', '8c', '6s', '4h'], 'high card')],
 [('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('deuce and ace', ['2h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('high card low', ['2h', '3d', '5c', '7s', '9h'], 'high card'),
  ('ten token with ace', ['10h', 'Ad', '8c', '6s', '4h'], 'high card')]]
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):
    R='23456789TJQKA'
    P=[2,3,5,7,11,13,17,19,23,29,31,37,49]
    prod=1
    for c in x:
        prod*=P[R.index('T' if c[:-1]=='10' else c[:-1])]
    exps=[]
    for p in P:
        e=0
        while prod%p==0:
            prod//=p
            e+=1
        if e: exps.append(e)
    exps.sort(reverse=True)
    names={(4,1):'four of a kind',(3,2):'full house',(3,1,1):'three of a kind',(2,2,1):'two pair',(2,1,1,1):'one pair',(1,1,1,1,1):'high card'}
    return names[tuple(exps)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('high card low', ['2h', '3d', '5c', '7s', '9h'], 'high card'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair')],
 [('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with three', ['Ah', '3d', '9c', '7s', '4h'], 'high card'),
  ('ace with king', ['Ah', 'Kd', 'Qc', '7s', '4h'], 'high card'),
  ('high card low', ['2h', '3d', '5c', '7s', '9h'], 'high card'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')],
 [('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with three', ['Ah', '3d', '9c', '7s', '4h'], 'high card'),
  ('ace with king', ['Ah', 'Kd', 'Qc', '7s', '4h'], 'high card'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('deuce and ace', ['2h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')],
 [('ace with three', ['Ah', '3d', '9c', '7s', '4h'], 'high card'),
  ('ace with king', ['Ah', 'Kd', 'Qc', '7s', '4h'], 'high card'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('deuce and ace', ['2h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('ten token with ace', ['10h', 'Ad', '8c', '6s', '4h'], 'high card')],
 [('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('deuce and ace', ['2h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('high card low', ['2h', '3d', '5c', '7s', '9h'], 'high card'),
  ('ten token with ace', ['10h', 'Ad', '8c', '6s', '4h'], 'high card')]]
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:
Any hand holding an ace and a trey or a seven is reported as containing a pair.

Input: five cards "Rs" (rank may be written "10" for ten; suits ignored, repeated ranks allowed up to four). Each rank maps to a distinct prime (2 for deuce ... 41 for ace); the product of the five primes is factored back into rank multiplicities, and the sorted multiplicity pattern names the rank shape: four of a kind, full house, three of a kind, two pair, one pair or high card.

split: open-access


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

N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    P=[2,3,5,7,11,13,17,19,23,29,31,37,41]
    prod=1
    for c in x:
        prod*=P[R.index('T' if c[:-1]=='10' else c[:-1])]
    exps=[]
    for p in P:
        e=0
        if prod%p==0:
            prod//=p
            e+=1
        if e: exps.append(e)
    exps.sort(reverse=True)
    names={(4,1):'four of a kind',(3,2):'full house',(3,1,1):'three of a kind',(2,2,1):'two pair',(2,1,1,1):'one pair',(1,1,1,1,1):'high card'}
    return names[tuple(exps)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with three', ['Ah', '3d', '9c', '7s', '4h'], 'high card'),
  ('ace with king', ['Ah', 'Kd', 'Qc', '7s', '4h'], 'high card'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('deuce and ace', ['2h', 'Ad', '8c', '6s', '4h'], 'high card')],
 [('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('deuce and ace', ['2h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('high card low', ['2h', '3d', '5c', '7s', '9h'], 'high card'),
  ('ten token with ace', ['10h', 'Ad', '8c', '6s', '4h'], 'high card')],
 [('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')],
 [('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')],
 [('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')]]
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):
    R='23456789TJQKA'
    P=[2,3,5,7,11,13,17,19,23,29,31,37,41]
    prod=1
    for c in x:
        prod*=P[R.index('T' if c[:-1]=='10' else c[:-1])]
    exps=[]
    for p in P:
        e=0
        while prod%(p*p)==0:
            prod//=p*p
            e+=2
        if prod%p==0:
            prod//=p
            e+=1
        e=min(e,2)
        if e: exps.append(e)
    exps.sort(reverse=True)
    names={(4,1):'four of a kind',(3,2):'full house',(3,1,1):'three of a kind',(2,2,1):'two pair',(2,1,1,1):'one pair',(1,1,1,1,1):'high card'}
    return names[tuple(exps)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with three', ['Ah', '3d', '9c', '7s', '4h'], 'high card'),
  ('ace with king', ['Ah', 'Kd', 'Qc', '7s', '4h'], 'high card'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('deuce and ace', ['2h', 'Ad', '8c', '6s', '4h'], 'high card')],
 [('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('deuce and ace', ['2h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('high card low', ['2h', '3d', '5c', '7s', '9h'], 'high card'),
  ('ten token with ace', ['10h', 'Ad', '8c', '6s', '4h'], 'high card')],
 [('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')],
 [('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')],
 [('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')]]
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 paired hand is reported as high card.

Input: five cards "Rs" (rank may be written "10" for ten; suits ignored, repeated ranks allowed up to four). Each rank maps to a distinct prime (2 for deuce ... 41 for ace); the product of the five primes is factored back into rank multiplicities, and the sorted multiplicity pattern names the rank shape: four of a kind, full house, three of a kind, two pair, one pair or high card.

split: open-access


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

N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    P=[2,3,5,7,11,13,17,19,23,29,31,37,41]
    prod=1
    for c in x:
        prod*=P[R.find(c[0])]
    exps=[]
    for p in P:
        e=0
        while prod%p==0:
            prod//=p
            e+=1
        if e: exps.append(e)
    exps.sort(reverse=True)
    names={(4,1):'four of a kind',(3,2):'full house',(3,1,1):'three of a kind',(2,2,1):'two pair',(2,1,1,1):'one pair',(1,1,1,1,1):'high card'}
    return names[tuple(exps)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with three', ['Ah', '3d', '9c', '7s', '4h'], 'high card'),
  ('ace with king', ['Ah', 'Kd', 'Qc', '7s', '4h'], 'high card'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('ten token with ace', ['10h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair')],
 [('ace with king', ['Ah', 'Kd', 'Qc', '7s', '4h'], 'high card'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')],
 [('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('deuce and ace', ['2h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('high card low', ['2h', '3d', '5c', '7s', '9h'], 'high card'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token with ace', ['10h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')],
 [('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('deuce and ace', ['2h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('high card low', ['2h', '3d', '5c', '7s', '9h'], 'high card'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token with ace', ['10h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')],
 [('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with three', ['Ah', '3d', '9c', '7s', '4h'], 'high card'),
  ('ace with king', ['Ah', 'Kd', 'Qc', '7s', '4h'], 'high card'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('ten token with ace', ['10h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')]]
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):
    R='23456789TJQKA'
    P=[2,3,5,7,11,13,17,19,23,29,31,37,41]
    prod=1
    for c in x:
        prod*=P[R.find(c[:-1])]
    exps=[]
    for p in P:
        e=0
        while prod%p==0:
            prod//=p
            e+=1
        if e: exps.append(e)
    exps.sort(reverse=True)
    names={(4,1):'four of a kind',(3,2):'full house',(3,1,1):'three of a kind',(2,2,1):'two pair',(2,1,1,1):'one pair',(1,1,1,1,1):'high card'}
    return names[tuple(exps)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with three', ['Ah', '3d', '9c', '7s', '4h'], 'high card'),
  ('ace with king', ['Ah', 'Kd', 'Qc', '7s', '4h'], 'high card'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('ten token with ace', ['10h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair')],
 [('ace with king', ['Ah', 'Kd', 'Qc', '7s', '4h'], 'high card'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')],
 [('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('deuce and ace', ['2h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('high card low', ['2h', '3d', '5c', '7s', '9h'], 'high card'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token with ace', ['10h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')],
 [('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('deuce and ace', ['2h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('high card low', ['2h', '3d', '5c', '7s', '9h'], 'high card'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token with ace', ['10h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')],
 [('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with three', ['Ah', '3d', '9c', '7s', '4h'], 'high card'),
  ('ace with king', ['Ah', 'Kd', 'Qc', '7s', '4h'], 'high card'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('ten token with ace', ['10h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')]]
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 hand holding "10h" and an ace is reported as a pair.

Input: five cards "Rs" (rank may be written "10" for ten; suits ignored, repeated ranks allowed up to four). Each rank maps to a distinct prime (2 for deuce ... 41 for ace); the product of the five primes is factored back into rank multiplicities, and the sorted multiplicity pattern names the rank shape: four of a kind, full house, three of a kind, two pair, one pair or high card.

split: open-access


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

N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    P=[2,3,5,7,11,13,17,19,23,29,31,37,41]
    prod=1
    for c in x:
        prod*=P[R.index('T' if c[:-1]=='10' else c[:-1])]
    exps=[]
    for p in P:
        e=0
        while prod%p==0:
            prod//=p
            e+=1
        if e: exps.append(e)
    exps.sort()
    names={(4,1):'four of a kind',(3,2):'full house',(3,1,1):'three of a kind',(2,2,1):'two pair',(2,1,1,1):'one pair',(1,1,1,1,1):'high card'}
    return names[tuple(exps)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with three', ['Ah', '3d', '9c', '7s', '4h'], 'high card'),
  ('ace with king', ['Ah', 'Kd', 'Qc', '7s', '4h'], 'high card'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('deuce and ace', ['2h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('high card low', ['2h', '3d', '5c', '7s', '9h'], 'high card')],
 [('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('deuce and ace', ['2h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('high card low', ['2h', '3d', '5c', '7s', '9h'], 'high card'),
  ('ten token with ace', ['10h', 'Ad', '8c', '6s', '4h'], 'high card')],
 [('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair')],
 [('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('ace with three', ['Ah', '3d', '9c', '7s', '4h'], 'high card'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')],
 [('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('ace with three', ['Ah', '3d', '9c', '7s', '4h'], 'high card'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')]]
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):
    R='23456789TJQKA'
    P=[2,3,5,7,11,13,17,19,23,29,31,37,41]
    prod=1
    for c in x:
        prod*=P[R.index('T' if c[:-1]=='10' else c[:-1])]
    exps=[]
    for p in P:
        e=0
        while prod%p==0:
            prod//=p
            e+=1
        if e: exps.append(e)
    exps=exps[::-1]
    names={(4,1):'four of a kind',(3,2):'full house',(3,1,1):'three of a kind',(2,2,1):'two pair',(2,1,1,1):'one pair',(1,1,1,1,1):'high card'}
    return names[tuple(exps)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with three', ['Ah', '3d', '9c', '7s', '4h'], 'high card'),
  ('ace with king', ['Ah', 'Kd', 'Qc', '7s', '4h'], 'high card'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('deuce and ace', ['2h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('high card low', ['2h', '3d', '5c', '7s', '9h'], 'high card')],
 [('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('deuce and ace', ['2h', 'Ad', '8c', '6s', '4h'], 'high card'),
  ('high card low', ['2h', '3d', '5c', '7s', '9h'], 'high card'),
  ('ten token with ace', ['10h', 'Ad', '8c', '6s', '4h'], 'high card')],
 [('pair of aces', ['Ah', 'Ad', '9c', '7s', '4h'], 'one pair'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('full house', ['Kh', 'Kd', '2c', '2s', '2h'], 'full house'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair')],
 [('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('ace with three', ['Ah', '3d', '9c', '7s', '4h'], 'high card'),
  ('quads', ['9h', '9d', '9c', '9s', '2h'], 'four of a kind'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')],
 [('ace high', ['Ah', 'Kd', '9c', '7s', '4h'], 'high card'),
  ('ace with three', ['Ah', '3d', '9c', '7s', '4h'], 'high card'),
  ('ace with seven pair', ['Ah', '7d', '7c', '2s', '4h'], 'one pair'),
  ('two pair', ['Jh', 'Jd', '4c', '4s', 'Ah'], 'two pair'),
  ('trips deuces', ['2h', '2d', '2c', 'Ks', 'Qh'], 'three of a kind'),
  ('pair of deuces', ['2h', '2d', '5c', '7s', '9h'], 'one pair'),
  ('ten token pair', ['10h', 'Td', '8c', '6s', '4h'], 'one pair'),
  ('ten token full house', ['10h', '10d', 'Tc', '6s', '6h'], 'full house')]]
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:
Paired hands raise a lookup failure instead of being named.

Input: five cards "Rs" (rank may be written "10" for ten; suits ignored, repeated ranks allowed up to four). Each rank maps to a distinct prime (2 for deuce ... 41 for ace); the product of the five primes is factored back into rank multiplicities, and the sorted multiplicity pattern names the rank shape: four of a kind, full house, three of a kind, two pair, one pair or high card.

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 and flush: return (8,[top])
        if shape==[4,1]: return (7,order)
        if shape==[3,2]: return (6,order)
        if flush: return (5,vals)
        if straight: return (4,[top])
        if shape==[3,1,1]: return (3,order)
        if shape==[2,2,1]: return (2,order)
        if shape==[2,1,1,1]: return (1,order)
        return (0,vals)

    board=x['board']; folded=x.get('folded',[])
    scores={}
    for name,hole in x['players'].items():
        if name in folded: continue
        scores[name]=max(key5(c) for c in [tuple(hole)+c for c in itertools.combinations(board,3)])
    best=max(scores.values())
    return sorted(n for n,k in scores.items() if k==best)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann']),
  ('flush kickers deep',
   {'board': ['Ah', 'Kh', '9h', '3d', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2h'], 'bob': ['8h', '2c']}},
   ['ann']),
  ('same category different kicker',
   {'board': ['Ah', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', 'Kd'], 'bob': ['8s', 'Qd']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann']),
  ('flush kickers deep',
   {'board': ['Ah', 'Kh', '9h', '3d', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2h'], 'bob': ['8h', '2c']}},
   ['ann']),
  ('same category different kicker',
   {'board': ['Ah', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', 'Kd'], 'bob': ['8s', 'Qd']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob']),
  ('set beats two pair',
   {'board': ['Kh', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', '8s'], 'bob': ['Kc', '7d']}},
   ['ann']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat']),
  ('single hole flush',
   {'board': ['2s', '7s', '9s', 'Js', '4d'],
    'folded': [],
    'players': {'ann': ['As', 'Kd'], 'bob': ['Qc', 'Qd']}},
   ['ann'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat']),
  ('single hole flush',
   {'board': ['2s', '7s', '9s', 'Js', '4d'],
    'folded': [],
    'players': {'ann': ['As', 'Kd'], 'bob': ['Qc', 'Qd']}},
   ['ann'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat']),
  ('single hole flush',
   {'board': ['2s', '7s', '9s', 'Js', '4d'],
    'folded': [],
    'players': {'ann': ['As', 'Kd'], 'bob': ['Qc', 'Qd']}},
   ['ann'])]]
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 and flush: return (8,[top])
        if shape==[4,1]: return (7,order)
        if shape==[3,2]: return (6,order)
        if flush: return (5,vals)
        if straight: return (4,[top])
        if shape==[3,1,1]: return (3,order)
        if shape==[2,2,1]: return (2,order)
        if shape==[2,1,1,1]: return (1,order)
        return (0,vals)

    board=x['board']; folded=x.get('folded',[])
    scores={}
    for name,hole in x['players'].items():
        if name in folded: continue
        scores[name]=max(key5(c) for c in [tuple(hole[:1])+c for c in itertools.combinations(board,4)]+[tuple(hole)+c for c in itertools.combinations(board,3)])
    best=max(scores.values())
    return sorted(n for n,k in scores.items() if k==best)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann']),
  ('flush kickers deep',
   {'board': ['Ah', 'Kh', '9h', '3d', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2h'], 'bob': ['8h', '2c']}},
   ['ann']),
  ('same category different kicker',
   {'board': ['Ah', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', 'Kd'], 'bob': ['8s', 'Qd']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann']),
  ('flush kickers deep',
   {'board': ['Ah', 'Kh', '9h', '3d', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2h'], 'bob': ['8h', '2c']}},
   ['ann']),
  ('same category different kicker',
   {'board': ['Ah', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', 'Kd'], 'bob': ['8s', 'Qd']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob']),
  ('set beats two pair',
   {'board': ['Kh', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', '8s'], 'bob': ['Kc', '7d']}},
   ['ann']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat']),
  ('single hole flush',
   {'board': ['2s', '7s', '9s', 'Js', '4d'],
    'folded': [],
    'players': {'ann': ['As', 'Kd'], 'bob': ['Qc', 'Qd']}},
   ['ann'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat']),
  ('single hole flush',
   {'board': ['2s', '7s', '9s', 'Js', '4d'],
    'folded': [],
    'players': {'ann': ['As', 'Kd'], 'bob': ['Qc', 'Qd']}},
   ['ann'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat']),
  ('single hole flush',
   {'board': ['2s', '7s', '9s', 'Js', '4d'],
    'folded': [],
    'players': {'ann': ['As', 'Kd'], 'bob': ['Qc', 'Qd']}},
   ['ann'])]]
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, or one hole card plays, the wrong player is paid.

Input: {"board": five community cards, "players": {name: two hole cards}, "folded": [names]}. Each live player uses the best five of their seven cards (zero, one or two hole cards may play). Return the sorted list of live players holding the best hand; ties split.

split: open-access