FA-83466 / Card game rule engines / Open access
Queen-king-ace is rejected as a run · case 01
Ace-high runs are invalid because ace only counts low.
ROOT CAUSE
The ace-high alternative is never tried.
VERIFIED REPAIR
Retry with the ace moved above the king.
Unsuccessful approach: Treating both A and 2 as high cards accepts wrapping runs like K-A-2.
Case contract
Input a list of cards. A set is 3-4 cards of one rank in distinct suits. A run is 3+ consecutive cards of one suit; ace is low (A-2-3) or high (Q-K-A) but runs do not wrap (K-A-2). Return "set", "run" or "invalid".
Why this case matters
Card-game engines, scoring apps and online tables apply this rule automatically on every hand.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
cards = x
order = 'A23456789TJQK'
if len(cards) < 3:
return 'invalid'
ranks = [c[0] for c in cards]
suits = [c[1] for c in cards]
if len(set(ranks)) == 1:
if len(cards) <= 4 and len(set(suits)) == len(cards):
return 'set'
return 'invalid'
if len(set(suits)) != 1:
return 'invalid'
idx = sorted(order.index(r) for r in ranks)
if all(idx[i + 1] == idx[i] + 1 for i in range(len(idx) - 1)):
return 'run'
return 'invalid'
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['9H', '9C', '9D', '9D'], 'invalid'], [['4D', '5D', '3D', '6D'], 'run'], [['KD', '6S', 'QS', '6H'], 'invalid'], [['8H', '8S'], 'invalid'], [['JD', 'QD', '2D', 'KD', 'AD'], 'invalid'], [['8H', '6D', 'AH'], 'invalid'], [['KD', 'TD', 'AD', 'JD', 'QD'], 'run'], [['KH', 'AH', '2H'], 'invalid']], [[['9C', 'JC', 'QC', 'TC'], 'run'], [['7S', '4D', 'JC'], 'invalid'], [['KH', 'QH', 'JH'], 'run'], [['5D', '5S'], 'invalid'], [['KD', 'TD', 'AD', 'JD', 'QD'], 'run'], [['KH', 'KD', 'KC', 'KC', 'KS'], 'invalid'], [['AH', 'QH', 'KH', 'JH'], 'run'], [['AD', '2D', 'KD'], 'invalid']], [[['JD', 'QD', '2D', 'KD', 'AD'], 'invalid'], [['KD', 'TD', 'AD', 'JD', 'QD'], 'run'], [['6C', '2C', '8D', '8C'], 'invalid'], [['5H', '2H', '3H', '6H', '4H'], 'run'], [['4H', '4S', '4C', '4D'], 'set'], [['3D', '3H', '3C'], 'set'], [['4D', 'KC', 'QC'], 'invalid'], [['AD', 'AH', 'AD'], 'invalid']], [[['AD', 'AH', 'AD'], 'invalid'], [['QC', 'QS', 'QD', 'QD'], 'invalid'], [['9S', 'JS', 'QS', '8S', 'TS'], 'run'], [['KS', '4S', '8D', '3C'], 'invalid'], [['9C', 'JC', 'TC', '8C'], 'run'], [['AH', '2H', '3H'], 'run'], [['QH', 'KH', 'AH', '2H'], 'invalid'], [['AH', 'QH', 'KH', 'JH'], 'run']], [[['KD', 'TD', 'AD', 'JD', 'QD'], 'run'], [['9H', 'JH', 'QC', '2D'], 'invalid'], [['5S', 'AH'], 'invalid'], [['TH', 'JH', 'KH', 'QH'], 'run'], [['QC', '6D'], 'invalid'], [['9D', '7D', '3S', '9S'], 'invalid'], [['AS', 'TD'], 'invalid'], [['KH', 'AH', '2H'], 'invalid']]]
for i, (args, expected) in enumerate(fixtures[N-1]):
check("meld case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| meld case 0 | invalid | invalid | Passed |
| meld case 1 | run | run | Passed |
| meld case 2 | invalid | invalid | Passed |
| meld case 3 | invalid | invalid | Passed |
| meld case 4 | invalid | invalid | Passed |
| meld case 5 | invalid | invalid | Passed |
| meld case 6 | invalid | run | Failed |
| meld case 7 | invalid | invalid | Passed |
SHA-256 / 8bc21c155c71b0670d741835dd2010a204acc4d3897b8562cd915ae97c150852
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
cards = x
order = 'A23456789TJQK'
if len(cards) < 3:
return 'invalid'
ranks = [c[0] for c in cards]
suits = [c[1] for c in cards]
if len(set(ranks)) == 1:
if len(cards) <= 4 and len(set(suits)) == len(cards):
return 'set'
return 'invalid'
if len(set(suits)) != 1:
return 'invalid'
idx = sorted(order.index(r) for r in ranks)
if all(idx[i + 1] == idx[i] + 1 for i in range(len(idx) - 1)):
return 'run'
if idx[0] == 0:
high = sorted(i + 13 if i < 2 else i for i in idx)
if all(high[i + 1] == high[i] + 1 for i in range(len(high) - 1)):
return 'run'
return 'invalid'
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['9H', '9C', '9D', '9D'], 'invalid'], [['4D', '5D', '3D', '6D'], 'run'], [['KD', '6S', 'QS', '6H'], 'invalid'], [['8H', '8S'], 'invalid'], [['JD', 'QD', '2D', 'KD', 'AD'], 'invalid'], [['8H', '6D', 'AH'], 'invalid'], [['KD', 'TD', 'AD', 'JD', 'QD'], 'run'], [['KH', 'AH', '2H'], 'invalid']], [[['9C', 'JC', 'QC', 'TC'], 'run'], [['7S', '4D', 'JC'], 'invalid'], [['KH', 'QH', 'JH'], 'run'], [['5D', '5S'], 'invalid'], [['KD', 'TD', 'AD', 'JD', 'QD'], 'run'], [['KH', 'KD', 'KC', 'KC', 'KS'], 'invalid'], [['AH', 'QH', 'KH', 'JH'], 'run'], [['AD', '2D', 'KD'], 'invalid']], [[['JD', 'QD', '2D', 'KD', 'AD'], 'invalid'], [['KD', 'TD', 'AD', 'JD', 'QD'], 'run'], [['6C', '2C', '8D', '8C'], 'invalid'], [['5H', '2H', '3H', '6H', '4H'], 'run'], [['4H', '4S', '4C', '4D'], 'set'], [['3D', '3H', '3C'], 'set'], [['4D', 'KC', 'QC'], 'invalid'], [['AD', 'AH', 'AD'], 'invalid']], [[['AD', 'AH', 'AD'], 'invalid'], [['QC', 'QS', 'QD', 'QD'], 'invalid'], [['9S', 'JS', 'QS', '8S', 'TS'], 'run'], [['KS', '4S', '8D', '3C'], 'invalid'], [['9C', 'JC', 'TC', '8C'], 'run'], [['AH', '2H', '3H'], 'run'], [['QH', 'KH', 'AH', '2H'], 'invalid'], [['AH', 'QH', 'KH', 'JH'], 'run']], [[['KD', 'TD', 'AD', 'JD', 'QD'], 'run'], [['9H', 'JH', 'QC', '2D'], 'invalid'], [['5S', 'AH'], 'invalid'], [['TH', 'JH', 'KH', 'QH'], 'run'], [['QC', '6D'], 'invalid'], [['9D', '7D', '3S', '9S'], 'invalid'], [['AS', 'TD'], 'invalid'], [['KH', 'AH', '2H'], 'invalid']]]
for i, (args, expected) in enumerate(fixtures[N-1]):
check("meld case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| meld case 0 | invalid | invalid | Passed |
| meld case 1 | run | run | Passed |
| meld case 2 | invalid | invalid | Passed |
| meld case 3 | invalid | invalid | Passed |
| meld case 4 | run | invalid | Failed |
| meld case 5 | invalid | invalid | Passed |
| meld case 6 | run | run | Passed |
| meld case 7 | run | invalid | Failed |
SHA-256 / 6d9d380af234125661e52641305fb8847b89d3d0ff59c4dd15629b96a1d45e28
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
cards = x
order = 'A23456789TJQK'
if len(cards) < 3:
return 'invalid'
ranks = [c[0] for c in cards]
suits = [c[1] for c in cards]
if len(set(ranks)) == 1:
if len(cards) <= 4 and len(set(suits)) == len(cards):
return 'set'
return 'invalid'
if len(set(suits)) != 1:
return 'invalid'
idx = sorted(order.index(r) for r in ranks)
if all(idx[i + 1] == idx[i] + 1 for i in range(len(idx) - 1)):
return 'run'
if idx[0] == 0:
high = sorted(idx[1:] + [13])
if all(high[i + 1] == high[i] + 1 for i in range(len(high) - 1)):
return 'run'
return 'invalid'
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['9H', '9C', '9D', '9D'], 'invalid'], [['4D', '5D', '3D', '6D'], 'run'], [['KD', '6S', 'QS', '6H'], 'invalid'], [['8H', '8S'], 'invalid'], [['JD', 'QD', '2D', 'KD', 'AD'], 'invalid'], [['8H', '6D', 'AH'], 'invalid'], [['KD', 'TD', 'AD', 'JD', 'QD'], 'run'], [['KH', 'AH', '2H'], 'invalid']], [[['9C', 'JC', 'QC', 'TC'], 'run'], [['7S', '4D', 'JC'], 'invalid'], [['KH', 'QH', 'JH'], 'run'], [['5D', '5S'], 'invalid'], [['KD', 'TD', 'AD', 'JD', 'QD'], 'run'], [['KH', 'KD', 'KC', 'KC', 'KS'], 'invalid'], [['AH', 'QH', 'KH', 'JH'], 'run'], [['AD', '2D', 'KD'], 'invalid']], [[['JD', 'QD', '2D', 'KD', 'AD'], 'invalid'], [['KD', 'TD', 'AD', 'JD', 'QD'], 'run'], [['6C', '2C', '8D', '8C'], 'invalid'], [['5H', '2H', '3H', '6H', '4H'], 'run'], [['4H', '4S', '4C', '4D'], 'set'], [['3D', '3H', '3C'], 'set'], [['4D', 'KC', 'QC'], 'invalid'], [['AD', 'AH', 'AD'], 'invalid']], [[['AD', 'AH', 'AD'], 'invalid'], [['QC', 'QS', 'QD', 'QD'], 'invalid'], [['9S', 'JS', 'QS', '8S', 'TS'], 'run'], [['KS', '4S', '8D', '3C'], 'invalid'], [['9C', 'JC', 'TC', '8C'], 'run'], [['AH', '2H', '3H'], 'run'], [['QH', 'KH', 'AH', '2H'], 'invalid'], [['AH', 'QH', 'KH', 'JH'], 'run']], [[['KD', 'TD', 'AD', 'JD', 'QD'], 'run'], [['9H', 'JH', 'QC', '2D'], 'invalid'], [['5S', 'AH'], 'invalid'], [['TH', 'JH', 'KH', 'QH'], 'run'], [['QC', '6D'], 'invalid'], [['9D', '7D', '3S', '9S'], 'invalid'], [['AS', 'TD'], 'invalid'], [['KH', 'AH', '2H'], 'invalid']]]
for i, (args, expected) in enumerate(fixtures[N-1]):
check("meld case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| meld case 0 | invalid | invalid | Passed |
| meld case 1 | run | run | Passed |
| meld case 2 | invalid | invalid | Passed |
| meld case 3 | invalid | invalid | Passed |
| meld case 4 | invalid | invalid | Passed |
| meld case 5 | invalid | invalid | Passed |
| meld case 6 | run | run | Passed |
| meld case 7 | invalid | invalid | Passed |
SHA-256 / 64ce07243add2e642ad5c022a9aa50e4e8fc17e6b23ae20d36e8d853977fa314
Verification & scope
A bounded toy rule contract stated explicitly in the contract field; cards are two-character codes (rank, suit). Not a complete implementation of any published rulebook or casino table rules. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:50:21.949547+00:00.
Case digest / 8881a1058e582e48014e282dc56f33ebe564cc4f67c811865bec1aecbb39cdeb