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

N = 1
observations = []
def solve(x):
    kc, dc, gin, big = x
    def dw(cards):
        t = 0
        for c in cards:
            r = c[0]
            t += 1 if r == 'A' else 10 if r in 'TJQK' else int(r)
        return t
    k = dw(kc)
    d = dw(dc)
    if k >= 10:
        return ['illegal', 0]
    if big:
        return ['knocker', 31 + d]
    if gin:
        return ['knocker', 25 + d]
    if d <= k:
        return ['defender', 25 + k - d]
    return ['knocker', d - k]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[[], ['5H', 'JH', 'AC', '4H'], True, False], ['knocker', 45]], [[[], ['KS', '5S', '4H'], False, False], ['knocker', 19]], [[['KD', 'JH', '9S'], ['JS', '7D'], False, False], ['illegal', 0]], [[['4S', '4D', 'AS'], ['3D', 'JS', 'KD', '7D'], False, False], ['knocker', 21]], [[['TS', 'JC', '5S'], ['4H', '7C'], False, False], ['illegal', 0]], [[[], ['KS', 'TD', '5D', '7D'], False, False], ['knocker', 32]], [[[], ['4D', 'JS'], True, False], ['knocker', 39]], [[['KC'], ['5D'], False, False], ['defender', 30]]], [[[['6S', '8S', '6C'], ['4C', 'KH', '9S'], False, False], ['illegal', 0]], [[[], [], True, False], ['knocker', 25]], [[['6C'], [], False, False], ['defender', 31]], [[[], ['4D', 'JS'], True, False], ['knocker', 39]], [[['4S'], ['JH', '9H', '8C'], False, False], ['knocker', 23]], [[[], ['KH', '3D'], False, False], ['knocker', 13]], [[['2C'], ['2D', 'AH', 'JD', '5S'], False, False], ['knocker', 16]], [[['QH'], ['9D'], False, False], ['defender', 26]]], [[[['KH', '4H', 'JD'], [], False, False], ['illegal', 0]], [[[], ['8S', 'QD'], True, False], ['knocker', 43]], [[['7D', '7S'], ['2S', 'QC'], False, False], ['illegal', 0]], [[['2C'], ['2D', 'AH', 'JD', '5S'], False, False], ['knocker', 16]], [[[], ['3C', '3H', '5S'], True, False], ['knocker', 36]], [[['AC', '9D', 'AD'], ['8S'], False, False], ['illegal', 0]], [[[], ['8D', 'KC', '7C', 'AC'], False, False], ['knocker', 26]], [[['2H', '5S', '3C'], ['7C', '4C', 'TC'], False, False], ['knocker', 11]]], [[[[], ['JS', '8H', '7C'], False, False], ['knocker', 25]], [[[], ['2C'], False, False], ['knocker', 2]], [[[], ['KD'], False, False], ['knocker', 10]], [[[], [], True, False], ['knocker', 25]], [[['TH', '3H', 'KC'], ['TD', 'AS', 'JD', '5H'], False, False], ['illegal', 0]], [[['TH', '8S'], ['QC', '5S', '2S', '6D'], False, False], ['illegal', 0]], [[[], ['4C', '7H'], True, True], ['knocker', 42]], [[['JS'], ['7D'], False, False], ['defender', 28]]], [[[[], ['8D', 'KC', '7C', 'AC'], False, False], ['knocker', 26]], [[['TH', '6C'], ['6D', 'QC'], False, False], ['illegal', 0]], [[['9C'], ['8S', 'JD'], False, False], ['knocker', 9]], [[['5H', '6D'], ['QH', '8D', 'KH'], False, False], ['illegal', 0]], [[['QC', 'JD'], ['7C', 'KH', '8C', '5S'], False, False], ['illegal', 0]], [[[], ['4D', '3S'], False, False], ['knocker', 7]], [[[], ['4S', 'AH', '8C', 'JS'], True, True], ['knocker', 54]], [[['KC'], ['8H', '2C', '9S', '6D'], False, False], ['knocker', 15]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("knock score 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)

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

N = 1
observations = []
def solve(x):
    kc, dc, gin, big = x
    def dw(cards):
        t = 0
        for c in cards:
            r = c[0]
            t += 1 if r == 'A' else 10 if r in 'TJQK' else int(r)
        return t
    k = dw(kc)
    d = dw(dc)
    if k + d > 10:
        return ['illegal', 0]
    if big:
        return ['knocker', 31 + d]
    if gin:
        return ['knocker', 25 + d]
    if d <= k:
        return ['defender', 25 + k - d]
    return ['knocker', d - k]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[[], ['5H', 'JH', 'AC', '4H'], True, False], ['knocker', 45]], [[[], ['KS', '5S', '4H'], False, False], ['knocker', 19]], [[['KD', 'JH', '9S'], ['JS', '7D'], False, False], ['illegal', 0]], [[['4S', '4D', 'AS'], ['3D', 'JS', 'KD', '7D'], False, False], ['knocker', 21]], [[['TS', 'JC', '5S'], ['4H', '7C'], False, False], ['illegal', 0]], [[[], ['KS', 'TD', '5D', '7D'], False, False], ['knocker', 32]], [[[], ['4D', 'JS'], True, False], ['knocker', 39]], [[['KC'], ['5D'], False, False], ['defender', 30]]], [[[['6S', '8S', '6C'], ['4C', 'KH', '9S'], False, False], ['illegal', 0]], [[[], [], True, False], ['knocker', 25]], [[['6C'], [], False, False], ['defender', 31]], [[[], ['4D', 'JS'], True, False], ['knocker', 39]], [[['4S'], ['JH', '9H', '8C'], False, False], ['knocker', 23]], [[[], ['KH', '3D'], False, False], ['knocker', 13]], [[['2C'], ['2D', 'AH', 'JD', '5S'], False, False], ['knocker', 16]], [[['QH'], ['9D'], False, False], ['defender', 26]]], [[[['KH', '4H', 'JD'], [], False, False], ['illegal', 0]], [[[], ['8S', 'QD'], True, False], ['knocker', 43]], [[['7D', '7S'], ['2S', 'QC'], False, False], ['illegal', 0]], [[['2C'], ['2D', 'AH', 'JD', '5S'], False, False], ['knocker', 16]], [[[], ['3C', '3H', '5S'], True, False], ['knocker', 36]], [[['AC', '9D', 'AD'], ['8S'], False, False], ['illegal', 0]], [[[], ['8D', 'KC', '7C', 'AC'], False, False], ['knocker', 26]], [[['2H', '5S', '3C'], ['7C', '4C', 'TC'], False, False], ['knocker', 11]]], [[[[], ['JS', '8H', '7C'], False, False], ['knocker', 25]], [[[], ['2C'], False, False], ['knocker', 2]], [[[], ['KD'], False, False], ['knocker', 10]], [[[], [], True, False], ['knocker', 25]], [[['TH', '3H', 'KC'], ['TD', 'AS', 'JD', '5H'], False, False], ['illegal', 0]], [[['TH', '8S'], ['QC', '5S', '2S', '6D'], False, False], ['illegal', 0]], [[[], ['4C', '7H'], True, True], ['knocker', 42]], [[['JS'], ['7D'], False, False], ['defender', 28]]], [[[[], ['8D', 'KC', '7C', 'AC'], False, False], ['knocker', 26]], [[['TH', '6C'], ['6D', 'QC'], False, False], ['illegal', 0]], [[['9C'], ['8S', 'JD'], False, False], ['knocker', 9]], [[['5H', '6D'], ['QH', '8D', 'KH'], False, False], ['illegal', 0]], [[['QC', 'JD'], ['7C', 'KH', '8C', '5S'], False, False], ['illegal', 0]], [[[], ['4D', '3S'], False, False], ['knocker', 7]], [[[], ['4S', 'AH', '8C', 'JS'], True, True], ['knocker', 54]], [[['KC'], ['8H', '2C', '9S', '6D'], False, False], ['knocker', 15]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("knock score 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)

prompt:
A legal ten-point knock is reported illegal.

Input [knocker_deadwood_cards, defender_deadwood_after_layoffs, gin, big_gin]. Deadwood: A=1, T/J/Q/K=10, others pip. Knocking above 10 is ["illegal", 0]. Big gin scores 31 + defender deadwood, gin 25 + defender deadwood (gin cannot be undercut). Otherwise if defender deadwood <= knocker deadwood the defender undercuts for 25 + difference; else knocker scores the difference.

split: open-access


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

N = 1
observations = []
def solve(x):
    card, top, declared = x
    if card[0] == '8':
        return True
    return card[1] == top[1] or card[0] == top[0]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['3D', '8D', 'S'], False], [['7H', '8C', 'C'], False], [['8C', '8S', 'S'], True], [['JD', '8S', None], False], [['8S', '8H', 'S'], True], [['TS', '3H', None], False], [['8S', '8D', 'H'], True], [['JS', '8S', 'D'], False]], [[['8C', 'JD', None], True], [['6H', 'TC', None], False], [['KC', '6H', None], False], [['2D', '3C', None], False], [['8C', '4D', None], True], [['7C', 'QC', None], True], [['2S', '8C', 'S'], True], [['9S', '8S', 'H'], False]], [[['3D', '8D', 'S'], False], [['JS', '8C', 'C'], False], [['3C', '8H', None], False], [['6C', '8S', 'C'], True], [['AH', 'TC', None], False], [['KH', '8H', 'H'], True], [['3D', 'AS', None], False], [['9S', '8S', 'H'], False]], [[['TC', '8C', 'D'], False], [['2H', '2C', None], True], [['6S', '4D', None], False], [['2S', '8C', 'S'], True], [['AC', '8D', 'S'], False], [['8C', '8C', 'H'], True], [['4D', '8D', 'S'], False], [['4D', '8D', 'S'], False]], [[['AC', '4D', None], False], [['JD', '8C', 'H'], False], [['8C', 'AC', None], True], [['8H', '8D', 'C'], True], [['8H', 'TC', None], True], [['TC', '9D', None], False], [['7S', '8S', 'D'], False], [['9S', '8D', 'S'], True]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("playable 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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    card, top, declared = x
    if card[0] == '8':
        return True
    if top[0] == '8' and declared:
        return card[1] == declared or card[1] == top[1]
    return card[1] == top[1] or card[0] == top[0]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['3D', '8D', 'S'], False], [['7H', '8C', 'C'], False], [['8C', '8S', 'S'], True], [['JD', '8S', None], False], [['8S', '8H', 'S'], True], [['TS', '3H', None], False], [['8S', '8D', 'H'], True], [['JS', '8S', 'D'], False]], [[['8C', 'JD', None], True], [['6H', 'TC', None], False], [['KC', '6H', None], False], [['2D', '3C', None], False], [['8C', '4D', None], True], [['7C', 'QC', None], True], [['2S', '8C', 'S'], True], [['9S', '8S', 'H'], False]], [[['3D', '8D', 'S'], False], [['JS', '8C', 'C'], False], [['3C', '8H', None], False], [['6C', '8S', 'C'], True], [['AH', 'TC', None], False], [['KH', '8H', 'H'], True], [['3D', 'AS', None], False], [['9S', '8S', 'H'], False]], [[['TC', '8C', 'D'], False], [['2H', '2C', None], True], [['6S', '4D', None], False], [['2S', '8C', 'S'], True], [['AC', '8D', 'S'], False], [['8C', '8C', 'H'], True], [['4D', '8D', 'S'], False], [['4D', '8D', 'S'], False]], [[['AC', '4D', None], False], [['JD', '8C', 'H'], False], [['8C', 'AC', None], True], [['8H', '8D', 'C'], True], [['8H', 'TC', None], True], [['TC', '9D', None], False], [['7S', '8S', 'D'], False], [['9S', '8D', 'S'], True]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("playable 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)

prompt:
After an eight declared hearts, the eight own suit is still playable.

Input [card, top_card, declared_suit_or_None]. Eights are always playable. When the top card is an 8 with a declared suit, only that suit (or an 8) may follow. Otherwise match suit or rank. Return a bool.

split: open-access


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

N = 1
observations = []
def solve(x):
    card, top, declared = x
    if card[0] == '8':
        return True
    if top[0] == '8' and declared:
        return card[1] == declared
    return card[1] == top[1]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['AH', '6H', None], True], [['7H', '8C', 'C'], False], [['8C', '8S', 'S'], True], [['JD', '8S', None], False], [['8S', '8H', 'S'], True], [['TS', '3H', None], False], [['2H', '2C', None], True], [['QS', 'QD', None], True]], [[['8C', 'JD', None], True], [['6H', 'TC', None], False], [['KC', '6H', None], False], [['2D', '3C', None], False], [['8C', '4D', None], True], [['7C', 'QC', None], True], [['JS', 'JH', None], True], [['JS', 'JH', None], True]], [[['JH', '7C', None], False], [['JS', '8C', 'C'], False], [['3C', '8H', None], False], [['6C', '8S', 'C'], True], [['AH', 'TC', None], False], [['KH', '8H', 'H'], True], [['2H', '2C', None], True], [['QS', 'QD', None], True]], [[['TC', '8C', 'D'], False], [['2H', '2C', None], True], [['6S', '4D', None], False], [['2S', '8C', 'S'], True], [['AC', '8D', 'S'], False], [['8C', '8C', 'H'], True], [['2H', '2C', None], True], [['2H', '2C', None], True]], [[['2H', '2C', None], True], [['JD', '8C', 'H'], False], [['8C', 'AC', None], True], [['8H', '8D', 'C'], True], [['8H', 'TC', None], True], [['TC', '9D', None], False], [['3S', '8H', None], False], [['QS', 'QD', None], True]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("playable 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)

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

N = 1
observations = []
def solve(x):
    card, top, declared = x
    if card[0] == '8':
        return True
    if top[0] == '8' and declared:
        return card[1] == declared
    return card == top or card[1] == top[1]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['AH', '6H', None], True], [['7H', '8C', 'C'], False], [['8C', '8S', 'S'], True], [['JD', '8S', None], False], [['8S', '8H', 'S'], True], [['TS', '3H', None], False], [['2H', '2C', None], True], [['QS', 'QD', None], True]], [[['8C', 'JD', None], True], [['6H', 'TC', None], False], [['KC', '6H', None], False], [['2D', '3C', None], False], [['8C', '4D', None], True], [['7C', 'QC', None], True], [['JS', 'JH', None], True], [['JS', 'JH', None], True]], [[['JH', '7C', None], False], [['JS', '8C', 'C'], False], [['3C', '8H', None], False], [['6C', '8S', 'C'], True], [['AH', 'TC', None], False], [['KH', '8H', 'H'], True], [['2H', '2C', None], True], [['QS', 'QD', None], True]], [[['TC', '8C', 'D'], False], [['2H', '2C', None], True], [['6S', '4D', None], False], [['2S', '8C', 'S'], True], [['AC', '8D', 'S'], False], [['8C', '8C', 'H'], True], [['2H', '2C', None], True], [['2H', '2C', None], True]], [[['2H', '2C', None], True], [['JD', '8C', 'H'], False], [['8C', 'AC', None], True], [['8H', '8D', 'C'], True], [['8H', 'TC', None], True], [['TC', '9D', None], False], [['3S', '8H', None], False], [['QS', 'QD', None], True]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("playable 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)

prompt:
A seven cannot be played on a seven of another suit.

Input [card, top_card, declared_suit_or_None]. Eights are always playable. When the top card is an 8 with a declared suit, only that suit (or an 8) may follow. Otherwise match suit or rank. Return a bool.

split: open-access


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

N = 1
observations = []
def solve(x):
    card, top, declared = x
    if top[0] == '8' and declared:
        return card[1] == declared
    if card[0] == '8':
        return True
    return card[1] == top[1] or card[0] == top[0]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['8C', '8D', 'S'], True], [['7H', '8C', 'C'], False], [['8C', '8S', 'S'], True], [['JD', '8S', None], False], [['8S', '8H', 'S'], True], [['TS', '3H', None], False], [['8S', '8D', 'H'], True], [['8S', '3H', None], True]], [[['8C', 'JD', None], True], [['6H', 'TC', None], False], [['KC', '6H', None], False], [['2D', '3C', None], False], [['8C', '4D', None], True], [['7C', 'QC', None], True], [['8C', '8C', 'H'], True], [['8D', '8H', 'H'], True]], [[['JH', '7C', None], False], [['JS', '8C', 'C'], False], [['3C', '8H', None], False], [['6C', '8S', 'C'], True], [['AH', 'TC', None], False], [['KH', '8H', 'H'], True], [['8H', '8C', 'C'], True], [['8S', '8H', 'H'], True]], [[['TC', '8C', 'D'], False], [['2H', '2C', None], True], [['6S', '4D', None], False], [['2S', '8C', 'S'], True], [['AC', '8D', 'S'], False], [['8C', '8C', 'H'], True], [['8S', '8H', 'H'], True], [['8H', '6C', None], True]], [[['AC', '4D', None], False], [['JD', '8C', 'H'], False], [['8C', 'AC', None], True], [['8H', '8D', 'C'], True], [['8H', 'TC', None], True], [['TC', '9D', None], False], [['8S', '4C', None], True], [['8S', '8S', 'D'], True]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("playable 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)

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

N = 1
observations = []
def solve(x):
    card, top, declared = x
    if top[0] == '8' and declared:
        return card[1] == declared
    return card[1] == top[1] or card[0] == top[0]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['8C', '8D', 'S'], True], [['7H', '8C', 'C'], False], [['8C', '8S', 'S'], True], [['JD', '8S', None], False], [['8S', '8H', 'S'], True], [['TS', '3H', None], False], [['8S', '8D', 'H'], True], [['8S', '3H', None], True]], [[['8C', 'JD', None], True], [['6H', 'TC', None], False], [['KC', '6H', None], False], [['2D', '3C', None], False], [['8C', '4D', None], True], [['7C', 'QC', None], True], [['8C', '8C', 'H'], True], [['8D', '8H', 'H'], True]], [[['JH', '7C', None], False], [['JS', '8C', 'C'], False], [['3C', '8H', None], False], [['6C', '8S', 'C'], True], [['AH', 'TC', None], False], [['KH', '8H', 'H'], True], [['8H', '8C', 'C'], True], [['8S', '8H', 'H'], True]], [[['TC', '8C', 'D'], False], [['2H', '2C', None], True], [['6S', '4D', None], False], [['2S', '8C', 'S'], True], [['AC', '8D', 'S'], False], [['8C', '8C', 'H'], True], [['8S', '8H', 'H'], True], [['8H', '6C', None], True]], [[['AC', '4D', None], False], [['JD', '8C', 'H'], False], [['8C', 'AC', None], True], [['8H', '8D', 'C'], True], [['8H', 'TC', None], True], [['TC', '9D', None], False], [['8S', '4C', None], True], [['8S', '8S', 'D'], True]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("playable 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)

prompt:
After a declared suit, eights of other suits are refused.

Input [card, top_card, declared_suit_or_None]. Eights are always playable. When the top card is an 8 with a declared suit, only that suit (or an 8) may follow. Otherwise match suit or rank. Return a bool.

split: open-access


prompt:
With two players a reverse does not let the player go again.

Input [players, current, direction(+1/-1), card]. Reverse flips direction (with two players it acts as skip); skip jumps one player; draw2/wild4 make the next player draw 2/4 and lose their turn. Return [next_player, direction, draw_count, victim_or_None].

split: open-access


prompt:
After a reverse the next player is the one in the old direction.

Input [players, current, direction(+1/-1), card]. Reverse flips direction (with two players it acts as skip); skip jumps one player; draw2/wild4 make the next player draw 2/4 and lose their turn. Return [next_player, direction, draw_count, victim_or_None].

split: open-access


prompt:
In counter-clockwise play the wrong player draws.

Input [players, current, direction(+1/-1), card]. Reverse flips direction (with two players it acts as skip); skip jumps one player; draw2/wild4 make the next player draw 2/4 and lose their turn. Return [next_player, direction, draw_count, victim_or_None].

split: open-access


prompt:
After a draw two the victim plays immediately.

Input [players, current, direction(+1/-1), card]. Reverse flips direction (with two players it acts as skip); skip jumps one player; draw2/wild4 make the next player draw 2/4 and lose their turn. Return [next_player, direction, draw_count, victim_or_None].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    hand, starter, crib = x
    order = 'A23456789TJQK'
    cards = hand + [starter]
    def val(c):
        return order.index(c[0]) + 1
    score = 0
    for k in range(2, 6):
        for combo in itertools.combinations(cards, k):
            if sum(val(c) for c in combo) == 15:
                score += 2
    for a, b in itertools.combinations(cards, 2):
        if a[0] == b[0]:
            score += 2
    ranks = sorted(order.index(c[0]) for c in cards)
    for size in (5, 4, 3):
        runs = 0
        for combo in itertools.combinations(ranks, size):
            if all(combo[i + 1] == combo[i] + 1 for i in range(size - 1)):
                runs += 1
        if runs:
            score += runs * size
            break
    suits = [c[1] for c in hand]
    if len(set(suits)) == 1:
        if starter[1] == suits[0]:
            score += 5
        elif not crib:
            score += 4
    for c in hand:
        if c[0] == 'J' and c[1] == starter[1]:
            score += 1
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['AC', '9C', '4C', 'TC'], '5S', True], 6], [[['KD', 'AH', '4S', '8D'], 'QH', False], 4], [[['3C', '3S', '4S', '5H'], '2D', False], 12], [[['5H', '9S', '6S', '2S'], 'AH', False], 4], [[['3S', '3H', '5H', 'JH'], 'QS', False], 6], [[['4C', 'QC', 'AC', '6C'], '5D', True], 9], [[['AD', 'AH', '2S', '3H'], 'KC', False], 12], [[['AD', 'JS', '2H', 'QH'], '4S', False], 5]], [[[['6S', '8D', 'JD', '9C'], '6D', False], 7], [[['4S', '5D', '9D', 'TC'], 'QH', True], 4], [[['5H', 'KC', '2H', '3S'], '6H', True], 4], [[['9H', '7H', 'QH', 'TH'], 'JH', False], 9], [[['2C', '2S', '3S', '4H'], 'KD', False], 12], [[['4S', '3S', '9S', 'TD'], '7C', False], 0], [[['7C', '7S', '8S', '9H'], 'JD', True], 12], [[['AH', 'KC', 'TH', '4S'], '6D', True], 4]], [[[['3H', 'QS', '3C', '6S'], '8D', False], 2], [[['JH', '9H', '9S', 'TD'], '3H', False], 9], [[['6C', '2C', '7C', 'AC'], '4H', True], 2], [[['4D', 'AS', '7H', 'QD'], '9S', False], 2], [[['6S', '5S', 'QS', '8C'], 'AC', False], 4], [[['8S', 'QS', 'TH', '9C'], 'QC', False], 5], [[['AD', 'JS', '2H', 'QH'], '4S', False], 5], [[['JC', 'KH', '4D', '6S'], 'AH', True], 4]], [[[['9S', '3S', 'QS', 'TS'], 'QH', False], 6], [[['AS', '9S', 'TS', '2S'], '4C', False], 8], [[['TD', 'KS', 'TH', 'TS'], 'JC', False], 6], [[['KS', '5D', '3H', '8D'], 'KD', True], 6], [[['2S', '8S', 'TC', 'JS'], 'QH', False], 3], [[['9H', '7S', 'QH', '5H'], '3D', False], 4], [[['KH', '3C', '5H', '5C'], '8S', False], 6], [[['7C', '8C', '9D', 'AD'], '6S', False], 10]], [[[['6C', '2C', '7C', 'AC'], '4H', True], 2], [[['2H', '5H', 'AC', '3S'], '8C', False], 5], [[['AD', '4S', '9D', '4H'], 'TH', False], 6], [[['9S', '9C', 'JH', 'KS'], '3H', False], 3], [[['KD', 'TC', 'QS', '4D'], 'TH', True], 2], [[['QD', '8S', 'JC', '5H'], '6C', False], 5], [[['JS', '8S', '2S', 'TS'], '2D', False], 6], [[['5H', '2H', 'QH', '6H'], '7S', True], 7]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("hand score 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    hand, starter, crib = x
    order = 'A23456789TJQK'
    cards = hand + [starter]
    def val(c):
        return min(order.index(c[0]) + 1, 10) if c[0] != 'A' else 11
    score = 0
    for k in range(2, 6):
        for combo in itertools.combinations(cards, k):
            if sum(val(c) for c in combo) == 15:
                score += 2
    for a, b in itertools.combinations(cards, 2):
        if a[0] == b[0]:
            score += 2
    ranks = sorted(order.index(c[0]) for c in cards)
    for size in (5, 4, 3):
        runs = 0
        for combo in itertools.combinations(ranks, size):
            if all(combo[i + 1] == combo[i] + 1 for i in range(size - 1)):
                runs += 1
        if runs:
            score += runs * size
            break
    suits = [c[1] for c in hand]
    if len(set(suits)) == 1:
        if starter[1] == suits[0]:
            score += 5
        elif not crib:
            score += 4
    for c in hand:
        if c[0] == 'J' and c[1] == starter[1]:
            score += 1
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['AC', '9C', '4C', 'TC'], '5S', True], 6], [[['KD', 'AH', '4S', '8D'], 'QH', False], 4], [[['3C', '3S', '4S', '5H'], '2D', False], 12], [[['5H', '9S', '6S', '2S'], 'AH', False], 4], [[['3S', '3H', '5H', 'JH'], 'QS', False], 6], [[['4C', 'QC', 'AC', '6C'], '5D', True], 9], [[['AD', 'AH', '2S', '3H'], 'KC', False], 12], [[['AD', 'JS', '2H', 'QH'], '4S', False], 5]], [[[['6S', '8D', 'JD', '9C'], '6D', False], 7], [[['4S', '5D', '9D', 'TC'], 'QH', True], 4], [[['5H', 'KC', '2H', '3S'], '6H', True], 4], [[['9H', '7H', 'QH', 'TH'], 'JH', False], 9], [[['2C', '2S', '3S', '4H'], 'KD', False], 12], [[['4S', '3S', '9S', 'TD'], '7C', False], 0], [[['7C', '7S', '8S', '9H'], 'JD', True], 12], [[['AH', 'KC', 'TH', '4S'], '6D', True], 4]], [[[['3H', 'QS', '3C', '6S'], '8D', False], 2], [[['JH', '9H', '9S', 'TD'], '3H', False], 9], [[['6C', '2C', '7C', 'AC'], '4H', True], 2], [[['4D', 'AS', '7H', 'QD'], '9S', False], 2], [[['6S', '5S', 'QS', '8C'], 'AC', False], 4], [[['8S', 'QS', 'TH', '9C'], 'QC', False], 5], [[['AD', 'JS', '2H', 'QH'], '4S', False], 5], [[['JC', 'KH', '4D', '6S'], 'AH', True], 4]], [[[['9S', '3S', 'QS', 'TS'], 'QH', False], 6], [[['AS', '9S', 'TS', '2S'], '4C', False], 8], [[['TD', 'KS', 'TH', 'TS'], 'JC', False], 6], [[['KS', '5D', '3H', '8D'], 'KD', True], 6], [[['2S', '8S', 'TC', 'JS'], 'QH', False], 3], [[['9H', '7S', 'QH', '5H'], '3D', False], 4], [[['KH', '3C', '5H', '5C'], '8S', False], 6], [[['7C', '8C', '9D', 'AD'], '6S', False], 10]], [[[['6C', '2C', '7C', 'AC'], '4H', True], 2], [[['2H', '5H', 'AC', '3S'], '8C', False], 5], [[['AD', '4S', '9D', '4H'], 'TH', False], 6], [[['9S', '9C', 'JH', 'KS'], '3H', False], 3], [[['KD', 'TC', 'QS', '4D'], 'TH', True], 2], [[['QD', '8S', 'JC', '5H'], '6C', False], 5], [[['JS', '8S', '2S', 'TS'], '2D', False], 6], [[['5H', '2H', 'QH', '6H'], '7S', True], 7]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("hand score 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)

prompt:
J-5, Q-5 and K-5 no longer make fifteen.

Input [four_card_hand, starter, is_crib]. Fifteens (any 2-5 cards, A=1, T/J/Q/K=10) score 2; each pair 2; runs score their length for every distinct combination of the longest run length; a four-card hand flush scores 4 (+1 with the starter) but the crib scores only a five-card flush; a hand jack matching the starter suit scores 1. Return the total.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    hand, starter, crib = x
    order = 'A23456789TJQK'
    cards = hand + [starter]
    def val(c):
        return min(order.index(c[0]) + 1, 10)
    score = 0
    for k in range(2, 5):
        for combo in itertools.combinations(cards, k):
            if sum(val(c) for c in combo) == 15:
                score += 2
    for a, b in itertools.combinations(cards, 2):
        if a[0] == b[0]:
            score += 2
    ranks = sorted(order.index(c[0]) for c in cards)
    for size in (5, 4, 3):
        runs = 0
        for combo in itertools.combinations(ranks, size):
            if all(combo[i + 1] == combo[i] + 1 for i in range(size - 1)):
                runs += 1
        if runs:
            score += runs * size
            break
    suits = [c[1] for c in hand]
    if len(set(suits)) == 1:
        if starter[1] == suits[0]:
            score += 5
        elif not crib:
            score += 4
    for c in hand:
        if c[0] == 'J' and c[1] == starter[1]:
            score += 1
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['AC', '9C', '4C', 'TC'], '5S', True], 6], [[['KD', 'AH', '4S', '8D'], 'QH', False], 4], [[['3C', '3S', '4S', '5H'], '2D', False], 12], [[['5H', '9S', '6S', '2S'], 'AH', False], 4], [[['3S', '3H', '5H', 'JH'], 'QS', False], 6], [[['4C', 'QC', 'AC', '6C'], '5D', True], 9], [[['6S', '8D', 'JD', '9C'], '6D', False], 7], [[['AS', '2H', '3D', '4C'], '5S', False], 7]], [[[['6S', '8D', 'JD', '9C'], '6D', False], 7], [[['4S', '5D', '9D', 'TC'], 'QH', True], 4], [[['5H', 'KC', '2H', '3S'], '6H', True], 4], [[['9H', '7H', 'QH', 'TH'], 'JH', False], 9], [[['2C', '2S', '3S', '4H'], 'KD', False], 12], [[['4S', '3S', '9S', 'TD'], '7C', False], 0], [[['KS', '5D', '3H', '8D'], 'KD', True], 6], [[['2C', '2D', '3H', '3S'], '5D', False], 6]], [[[['3H', 'QS', '3C', '6S'], '8D', False], 2], [[['JH', '9H', '9S', 'TD'], '3H', False], 9], [[['6C', '2C', '7C', 'AC'], '4H', True], 2], [[['4D', 'AS', '7H', 'QD'], '9S', False], 2], [[['6S', '5S', 'QS', '8C'], 'AC', False], 4], [[['8S', 'QS', 'TH', '9C'], 'QC', False], 5], [[['5H', '2H', 'QH', '6H'], '7S', True], 7], [[['AC', '2D', '3H', '4S'], '5D', True], 7]], [[[['9S', '3S', 'QS', 'TS'], 'QH', False], 6], [[['AS', '9S', 'TS', '2S'], '4C', False], 8], [[['TD', 'KS', 'TH', 'TS'], 'JC', False], 6], [[['KS', '5D', '3H', '8D'], 'KD', True], 6], [[['2S', '8S', 'TC', 'JS'], 'QH', False], 3], [[['9H', '7S', 'QH', '5H'], '3D', False], 4], [[['5S', 'JD', '4D', '3D'], 'TS', True], 7], [[['AH', 'AD', '2C', '5S'], '6H', True], 4]], [[[['8D', '8C', '9S', 'TH'], 'AH', True], 8], [[['2H', '5H', 'AC', '3S'], '8C', False], 5], [[['AD', '4S', '9D', '4H'], 'TH', False], 6], [[['9S', '9C', 'JH', 'KS'], '3H', False], 3], [[['KD', 'TC', 'QS', '4D'], 'TH', True], 2], [[['QD', '8S', 'JC', '5H'], '6C', False], 5], [[['QH', '5H', 'KS', '3C'], 'AS', True], 4], [[['AS', '2H', '3D', '4C'], '5S', False], 7]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("hand score 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    hand, starter, crib = x
    order = 'A23456789TJQK'
    cards = hand + [starter]
    def val(c):
        return min(order.index(c[0]) + 1, 10)
    score = 0
    for k in range(3, 6):
        for combo in itertools.combinations(cards, k):
            if sum(val(c) for c in combo) == 15:
                score += 2
    for a, b in itertools.combinations(cards, 2):
        if a[0] == b[0]:
            score += 2
    ranks = sorted(order.index(c[0]) for c in cards)
    for size in (5, 4, 3):
        runs = 0
        for combo in itertools.combinations(ranks, size):
            if all(combo[i + 1] == combo[i] + 1 for i in range(size - 1)):
                runs += 1
        if runs:
            score += runs * size
            break
    suits = [c[1] for c in hand]
    if len(set(suits)) == 1:
        if starter[1] == suits[0]:
            score += 5
        elif not crib:
            score += 4
    for c in hand:
        if c[0] == 'J' and c[1] == starter[1]:
            score += 1
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['AC', '9C', '4C', 'TC'], '5S', True], 6], [[['KD', 'AH', '4S', '8D'], 'QH', False], 4], [[['3C', '3S', '4S', '5H'], '2D', False], 12], [[['5H', '9S', '6S', '2S'], 'AH', False], 4], [[['3S', '3H', '5H', 'JH'], 'QS', False], 6], [[['4C', 'QC', 'AC', '6C'], '5D', True], 9], [[['6S', '8D', 'JD', '9C'], '6D', False], 7], [[['AS', '2H', '3D', '4C'], '5S', False], 7]], [[[['6S', '8D', 'JD', '9C'], '6D', False], 7], [[['4S', '5D', '9D', 'TC'], 'QH', True], 4], [[['5H', 'KC', '2H', '3S'], '6H', True], 4], [[['9H', '7H', 'QH', 'TH'], 'JH', False], 9], [[['2C', '2S', '3S', '4H'], 'KD', False], 12], [[['4S', '3S', '9S', 'TD'], '7C', False], 0], [[['KS', '5D', '3H', '8D'], 'KD', True], 6], [[['2C', '2D', '3H', '3S'], '5D', False], 6]], [[[['3H', 'QS', '3C', '6S'], '8D', False], 2], [[['JH', '9H', '9S', 'TD'], '3H', False], 9], [[['6C', '2C', '7C', 'AC'], '4H', True], 2], [[['4D', 'AS', '7H', 'QD'], '9S', False], 2], [[['6S', '5S', 'QS', '8C'], 'AC', False], 4], [[['8S', 'QS', 'TH', '9C'], 'QC', False], 5], [[['5H', '2H', 'QH', '6H'], '7S', True], 7], [[['AC', '2D', '3H', '4S'], '5D', True], 7]], [[[['9S', '3S', 'QS', 'TS'], 'QH', False], 6], [[['AS', '9S', 'TS', '2S'], '4C', False], 8], [[['TD', 'KS', 'TH', 'TS'], 'JC', False], 6], [[['KS', '5D', '3H', '8D'], 'KD', True], 6], [[['2S', '8S', 'TC', 'JS'], 'QH', False], 3], [[['9H', '7S', 'QH', '5H'], '3D', False], 4], [[['5S', 'JD', '4D', '3D'], 'TS', True], 7], [[['AH', 'AD', '2C', '5S'], '6H', True], 4]], [[[['8D', '8C', '9S', 'TH'], 'AH', True], 8], [[['2H', '5H', 'AC', '3S'], '8C', False], 5], [[['AD', '4S', '9D', '4H'], 'TH', False], 6], [[['9S', '9C', 'JH', 'KS'], '3H', False], 3], [[['KD', 'TC', 'QS', '4D'], 'TH', True], 2], [[['QD', '8S', 'JC', '5H'], '6C', False], 5], [[['QH', '5H', 'KS', '3C'], 'AS', True], 4], [[['AS', '2H', '3D', '4C'], '5S', False], 7]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("hand score 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)

prompt:
A hand whose five cards together total 15 misses 2 points.

Input [four_card_hand, starter, is_crib]. Fifteens (any 2-5 cards, A=1, T/J/Q/K=10) score 2; each pair 2; runs score their length for every distinct combination of the longest run length; a four-card hand flush scores 4 (+1 with the starter) but the crib scores only a five-card flush; a hand jack matching the starter suit scores 1. Return the total.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    hand, starter, crib = x
    order = 'A23456789TJQK'
    cards = hand + [starter]
    def val(c):
        return min(order.index(c[0]) + 1, 10)
    score = 0
    for k in range(2, 6):
        for combo in itertools.combinations(cards, k):
            if sum(val(c) for c in combo) == 15:
                score += 2
    for a, b in itertools.combinations(cards, 2):
        if a[0] == b[0]:
            score += 2
    ranks = sorted(order.index(c[0]) for c in cards)
    for size in (5, 4, 3):
        runs = 0
        for combo in itertools.combinations(ranks, size):
            if all(combo[i + 1] == combo[i] + 1 for i in range(size - 1)):
                runs += 1
        if runs:
            score += runs * size
    suits = [c[1] for c in hand]
    if len(set(suits)) == 1:
        if starter[1] == suits[0]:
            score += 5
        elif not crib:
            score += 4
    for c in hand:
        if c[0] == 'J' and c[1] == starter[1]:
            score += 1
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['AC', '9C', '4C', 'TC'], '5S', True], 6], [[['KD', 'AH', '4S', '8D'], 'QH', False], 4], [[['3C', '3S', '4S', '5H'], '2D', False], 12], [[['5H', '9S', '6S', '2S'], 'AH', False], 4], [[['3S', '3H', '5H', 'JH'], 'QS', False], 6], [[['4C', 'QC', 'AC', '6C'], '5D', True], 9], [[['AD', 'AH', '2S', '3H'], 'KC', False], 12], [[['6H', '6D', '7S', '8H'], 'JD', False], 10]], [[[['6S', '8D', 'JD', '9C'], '6D', False], 7], [[['4S', '5D', '9D', 'TC'], 'QH', True], 4], [[['5H', 'KC', '2H', '3S'], '6H', True], 4], [[['9H', '7H', 'QH', 'TH'], 'JH', False], 9], [[['2C', '2S', '3S', '4H'], 'KD', False], 12], [[['4S', '3S', '9S', 'TD'], '7C', False], 0], [[['4C', '4S', '5S', '6H'], '3D', True], 14], [[['KH', '9S', 'JS', 'JD'], 'QC', False], 8]], [[[['3H', 'QS', '3C', '6S'], '8D', False], 2], [[['JH', '9H', '9S', 'TD'], '3H', False], 9], [[['6C', '2C', '7C', 'AC'], '4H', True], 2], [[['4D', 'AS', '7H', 'QD'], '9S', False], 2], [[['6S', '5S', 'QS', '8C'], 'AC', False], 4], [[['8S', 'QS', 'TH', '9C'], 'QC', False], 5], [[['QS', 'KC', 'JC', '6H'], 'TH', False], 4], [[['AC', 'AH', '2S', '3H'], 'AD', False], 15]], [[[['AD', 'AH', '2S', '3H'], 'KC', False], 12], [[['AS', '9S', 'TS', '2S'], '4C', False], 8], [[['TD', 'KS', 'TH', 'TS'], 'JC', False], 6], [[['KS', '5D', '3H', '8D'], 'KD', True], 6], [[['2S', '8S', 'TC', 'JS'], 'QH', False], 3], [[['9H', '7S', 'QH', '5H'], '3D', False], 4], [[['KH', '3C', '5H', '5C'], '8S', False], 6], [[['3H', '4D', '6D', 'AS'], '5S', False], 8]], [[[['8D', '8C', '9S', 'TH'], 'AH', True], 8], [[['2H', '5H', 'AC', '3S'], '8C', False], 5], [[['AD', '4S', '9D', '4H'], 'TH', False], 6], [[['9S', '9C', 'JH', 'KS'], '3H', False], 3], [[['KD', 'TC', 'QS', '4D'], 'TH', True], 2], [[['QD', '8S', 'JC', '5H'], '6C', False], 5], [[['6H', '6D', '7S', '8H'], 'JD', False], 10], [[['5S', 'TD', 'JC', 'QH'], 'KS', False], 12]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("hand score 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    hand, starter, crib = x
    order = 'A23456789TJQK'
    cards = hand + [starter]
    def val(c):
        return min(order.index(c[0]) + 1, 10)
    score = 0
    for k in range(2, 6):
        for combo in itertools.combinations(cards, k):
            if sum(val(c) for c in combo) == 15:
                score += 2
    for a, b in itertools.combinations(cards, 2):
        if a[0] == b[0]:
            score += 2
    ranks = sorted(order.index(c[0]) for c in cards)
    for size in (5, 4, 3):
        runs = 0
        for combo in itertools.combinations(ranks, size):
            if all(combo[i + 1] == combo[i] + 1 for i in range(size - 1)):
                runs += 1
        if runs:
            score += size
            break
    suits = [c[1] for c in hand]
    if len(set(suits)) == 1:
        if starter[1] == suits[0]:
            score += 5
        elif not crib:
            score += 4
    for c in hand:
        if c[0] == 'J' and c[1] == starter[1]:
            score += 1
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['AC', '9C', '4C', 'TC'], '5S', True], 6], [[['KD', 'AH', '4S', '8D'], 'QH', False], 4], [[['3C', '3S', '4S', '5H'], '2D', False], 12], [[['5H', '9S', '6S', '2S'], 'AH', False], 4], [[['3S', '3H', '5H', 'JH'], 'QS', False], 6], [[['4C', 'QC', 'AC', '6C'], '5D', True], 9], [[['AD', 'AH', '2S', '3H'], 'KC', False], 12], [[['6H', '6D', '7S', '8H'], 'JD', False], 10]], [[[['6S', '8D', 'JD', '9C'], '6D', False], 7], [[['4S', '5D', '9D', 'TC'], 'QH', True], 4], [[['5H', 'KC', '2H', '3S'], '6H', True], 4], [[['9H', '7H', 'QH', 'TH'], 'JH', False], 9], [[['2C', '2S', '3S', '4H'], 'KD', False], 12], [[['4S', '3S', '9S', 'TD'], '7C', False], 0], [[['4C', '4S', '5S', '6H'], '3D', True], 14], [[['KH', '9S', 'JS', 'JD'], 'QC', False], 8]], [[[['3H', 'QS', '3C', '6S'], '8D', False], 2], [[['JH', '9H', '9S', 'TD'], '3H', False], 9], [[['6C', '2C', '7C', 'AC'], '4H', True], 2], [[['4D', 'AS', '7H', 'QD'], '9S', False], 2], [[['6S', '5S', 'QS', '8C'], 'AC', False], 4], [[['8S', 'QS', 'TH', '9C'], 'QC', False], 5], [[['QS', 'KC', 'JC', '6H'], 'TH', False], 4], [[['AC', 'AH', '2S', '3H'], 'AD', False], 15]], [[[['AD', 'AH', '2S', '3H'], 'KC', False], 12], [[['AS', '9S', 'TS', '2S'], '4C', False], 8], [[['TD', 'KS', 'TH', 'TS'], 'JC', False], 6], [[['KS', '5D', '3H', '8D'], 'KD', True], 6], [[['2S', '8S', 'TC', 'JS'], 'QH', False], 3], [[['9H', '7S', 'QH', '5H'], '3D', False], 4], [[['KH', '3C', '5H', '5C'], '8S', False], 6], [[['3H', '4D', '6D', 'AS'], '5S', False], 8]], [[[['8D', '8C', '9S', 'TH'], 'AH', True], 8], [[['2H', '5H', 'AC', '3S'], '8C', False], 5], [[['AD', '4S', '9D', '4H'], 'TH', False], 6], [[['9S', '9C', 'JH', 'KS'], '3H', False], 3], [[['KD', 'TC', 'QS', '4D'], 'TH', True], 2], [[['QD', '8S', 'JC', '5H'], '6C', False], 5], [[['6H', '6D', '7S', '8H'], 'JD', False], 10], [[['5S', 'TD', 'JC', 'QH'], 'KS', False], 12]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("hand score 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)

prompt:
A four-card run also scores its two three-card sub-runs.

Input [four_card_hand, starter, is_crib]. Fifteens (any 2-5 cards, A=1, T/J/Q/K=10) score 2; each pair 2; runs score their length for every distinct combination of the longest run length; a four-card hand flush scores 4 (+1 with the starter) but the crib scores only a five-card flush; a hand jack matching the starter suit scores 1. Return the total.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    hand, starter, crib = x
    order = 'A23456789TJQK'
    cards = hand + [starter]
    def val(c):
        return min(order.index(c[0]) + 1, 10)
    score = 0
    for k in range(2, 6):
        for combo in itertools.combinations(cards, k):
            if sum(val(c) for c in combo) == 15:
                score += 2
    for a, b in itertools.combinations(cards, 2):
        if a[0] == b[0]:
            score += 2
    ranks = sorted(order.index(c[0]) for c in cards)
    for size in (5, 4, 3):
        runs = 0
        for combo in itertools.combinations(ranks, size):
            if all(combo[i + 1] == combo[i] + 1 for i in range(size - 1)):
                runs += 1
        if runs:
            score += runs * size
            break
    suits = [c[1] for c in hand]
    if len(set(suits)) == 1:
        if starter[1] == suits[0]:
            score += 5
        else:
            score += 4
    for c in hand:
        if c[0] == 'J' and c[1] == starter[1]:
            score += 1
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['AC', '9C', '4C', 'TC'], '5S', True], 6], [[['KD', 'AH', '4S', '8D'], 'QH', False], 4], [[['3C', '3S', '4S', '5H'], '2D', False], 12], [[['5H', '9S', '6S', '2S'], 'AH', False], 4], [[['3S', '3H', '5H', 'JH'], 'QS', False], 6], [[['4C', 'QC', 'AC', '6C'], '5D', True], 9], [[['AD', 'AH', '2S', '3H'], 'KC', False], 12], [[['4H', '5H', '6H', '7H'], '8H', True], 14]], [[[['6S', '8D', 'JD', '9C'], '6D', False], 7], [[['4S', '5D', '9D', 'TC'], 'QH', True], 4], [[['5H', 'KC', '2H', '3S'], '6H', True], 4], [[['9H', '7H', 'QH', 'TH'], 'JH', False], 9], [[['2C', '2S', '3S', '4H'], 'KD', False], 12], [[['4S', '3S', '9S', 'TD'], '7C', False], 0], [[['9C', 'TC', '7C', '3C'], '5S', True], 4], [[['4H', '5H', '6H', '7H'], '8H', True], 14]], [[[['3H', 'QS', '3C', '6S'], '8D', False], 2], [[['JH', '9H', '9S', 'TD'], '3H', False], 9], [[['6C', '2C', '7C', 'AC'], '4H', True], 2], [[['4D', 'AS', '7H', 'QD'], '9S', False], 2], [[['6S', '5S', 'QS', '8C'], 'AC', False], 4], [[['8S', 'QS', 'TH', '9C'], 'QC', False], 5], [[['4S', 'QS', 'KS', 'AS'], '4C', True], 10], [[['4H', '5H', '6H', '7H'], '8H', True], 14]], [[[['AC', '9C', '4C', 'TC'], '5S', True], 6], [[['AS', '9S', 'TS', '2S'], '4C', False], 8], [[['TD', 'KS', 'TH', 'TS'], 'JC', False], 6], [[['KS', '5D', '3H', '8D'], 'KD', True], 6], [[['2S', '8S', 'TC', 'JS'], 'QH', False], 3], [[['9H', '7S', 'QH', '5H'], '3D', False], 4], [[['KH', '3C', '5H', '5C'], '8S', False], 6], [[['4H', '5H', '6H', '7H'], '8H', True], 14]], [[[['8D', '8C', '9S', 'TH'], 'AH', True], 8], [[['2H', '5H', 'AC', '3S'], '8C', False], 5], [[['AD', '4S', '9D', '4H'], 'TH', False], 6], [[['9S', '9C', 'JH', 'KS'], '3H', False], 3], [[['KD', 'TC', 'QS', '4D'], 'TH', True], 2], [[['QD', '8S', 'JC', '5H'], '6C', False], 5], [[['9C', 'TC', '7C', '3C'], '5S', True], 4], [[['4H', '5H', '6H', '7H'], '8H', True], 14]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("hand score 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    hand, starter, crib = x
    order = 'A23456789TJQK'
    cards = hand + [starter]
    def val(c):
        return min(order.index(c[0]) + 1, 10)
    score = 0
    for k in range(2, 6):
        for combo in itertools.combinations(cards, k):
            if sum(val(c) for c in combo) == 15:
                score += 2
    for a, b in itertools.combinations(cards, 2):
        if a[0] == b[0]:
            score += 2
    ranks = sorted(order.index(c[0]) for c in cards)
    for size in (5, 4, 3):
        runs = 0
        for combo in itertools.combinations(ranks, size):
            if all(combo[i + 1] == combo[i] + 1 for i in range(size - 1)):
                runs += 1
        if runs:
            score += runs * size
            break
    suits = [c[1] for c in hand]
    if len(set(suits)) == 1:
        if starter[1] == suits[0] and not crib:
            score += 5
        elif not crib:
            score += 4
    for c in hand:
        if c[0] == 'J' and c[1] == starter[1]:
            score += 1
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['AC', '9C', '4C', 'TC'], '5S', True], 6], [[['KD', 'AH', '4S', '8D'], 'QH', False], 4], [[['3C', '3S', '4S', '5H'], '2D', False], 12], [[['5H', '9S', '6S', '2S'], 'AH', False], 4], [[['3S', '3H', '5H', 'JH'], 'QS', False], 6], [[['4C', 'QC', 'AC', '6C'], '5D', True], 9], [[['AD', 'AH', '2S', '3H'], 'KC', False], 12], [[['4H', '5H', '6H', '7H'], '8H', True], 14]], [[[['6S', '8D', 'JD', '9C'], '6D', False], 7], [[['4S', '5D', '9D', 'TC'], 'QH', True], 4], [[['5H', 'KC', '2H', '3S'], '6H', True], 4], [[['9H', '7H', 'QH', 'TH'], 'JH', False], 9], [[['2C', '2S', '3S', '4H'], 'KD', False], 12], [[['4S', '3S', '9S', 'TD'], '7C', False], 0], [[['9C', 'TC', '7C', '3C'], '5S', True], 4], [[['4H', '5H', '6H', '7H'], '8H', True], 14]], [[[['3H', 'QS', '3C', '6S'], '8D', False], 2], [[['JH', '9H', '9S', 'TD'], '3H', False], 9], [[['6C', '2C', '7C', 'AC'], '4H', True], 2], [[['4D', 'AS', '7H', 'QD'], '9S', False], 2], [[['6S', '5S', 'QS', '8C'], 'AC', False], 4], [[['8S', 'QS', 'TH', '9C'], 'QC', False], 5], [[['4S', 'QS', 'KS', 'AS'], '4C', True], 10], [[['4H', '5H', '6H', '7H'], '8H', True], 14]], [[[['AC', '9C', '4C', 'TC'], '5S', True], 6], [[['AS', '9S', 'TS', '2S'], '4C', False], 8], [[['TD', 'KS', 'TH', 'TS'], 'JC', False], 6], [[['KS', '5D', '3H', '8D'], 'KD', True], 6], [[['2S', '8S', 'TC', 'JS'], 'QH', False], 3], [[['9H', '7S', 'QH', '5H'], '3D', False], 4], [[['KH', '3C', '5H', '5C'], '8S', False], 6], [[['4H', '5H', '6H', '7H'], '8H', True], 14]], [[[['8D', '8C', '9S', 'TH'], 'AH', True], 8], [[['2H', '5H', 'AC', '3S'], '8C', False], 5], [[['AD', '4S', '9D', '4H'], 'TH', False], 6], [[['9S', '9C', 'JH', 'KS'], '3H', False], 3], [[['KD', 'TC', 'QS', '4D'], 'TH', True], 2], [[['QD', '8S', 'JC', '5H'], '6C', False], 5], [[['9C', 'TC', '7C', '3C'], '5S', True], 4], [[['4H', '5H', '6H', '7H'], '8H', True], 14]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("hand score 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)

prompt:
A crib whose four cards share a suit but not the starter scores 4.

Input [four_card_hand, starter, is_crib]. Fifteens (any 2-5 cards, A=1, T/J/Q/K=10) score 2; each pair 2; runs score their length for every distinct combination of the longest run length; a four-card hand flush scores 4 (+1 with the starter) but the crib scores only a five-card flush; a hand jack matching the starter suit scores 1. Return the total.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    hand, starter, crib = x
    order = 'A23456789TJQK'
    cards = hand + [starter]
    def val(c):
        return min(order.index(c[0]) + 1, 10)
    score = 0
    for k in range(2, 6):
        for combo in itertools.combinations(cards, k):
            if sum(val(c) for c in combo) == 15:
                score += 2
    for a, b in itertools.combinations(cards, 2):
        if a[0] == b[0]:
            score += 2
    ranks = sorted(order.index(c[0]) for c in cards)
    for size in (5, 4, 3):
        runs = 0
        for combo in itertools.combinations(ranks, size):
            if all(combo[i + 1] == combo[i] + 1 for i in range(size - 1)):
                runs += 1
        if runs:
            score += runs * size
            break
    suits = [c[1] for c in hand]
    if len(set(suits)) == 1:
        if starter[1] == suits[0]:
            score += 5
        elif not crib:
            score += 4
    for c in cards:
        if c[0] == 'J' and c[1] == starter[1]:
            score += 1
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['4D', '3D', 'TD', '2D'], 'JD', False], 12], [[['KD', 'AH', '4S', '8D'], 'QH', False], 4], [[['3C', '3S', '4S', '5H'], '2D', False], 12], [[['5H', '9S', '6S', '2S'], 'AH', False], 4], [[['3S', '3H', '5H', 'JH'], 'QS', False], 6], [[['4C', 'QC', 'AC', '6C'], '5D', True], 9], [[['AD', 'AH', '2S', '3H'], 'KC', False], 12], [[['7D', 'QS', 'JC', '2C'], '5D', True], 4]], [[[['6S', '8D', 'JD', '9C'], '6D', False], 7], [[['4S', '5D', '9D', 'TC'], 'QH', True], 4], [[['5H', 'KC', '2H', '3S'], '6H', True], 4], [[['9H', '7H', 'QH', 'TH'], 'JH', False], 9], [[['2C', '2S', '3S', '4H'], 'KD', False], 12], [[['4S', '3S', '9S', 'TD'], '7C', False], 0], [[['TD', 'KS', 'TH', 'TS'], 'JC', False], 6], [[['JD', 'TS', '5D', '9S'], '4C', False], 7]], [[[['3H', 'QS', '3C', '6S'], '8D', False], 2], [[['JH', '9H', '9S', 'TD'], '3H', False], 9], [[['6C', '2C', '7C', 'AC'], '4H', True], 2], [[['4D', 'AS', '7H', 'QD'], '9S', False], 2], [[['6S', '5S', 'QS', '8C'], 'AC', False], 4], [[['8S', 'QS', 'TH', '9C'], 'QC', False], 5], [[['4S', 'QD', '8D', '9H'], 'JD', False], 0], [[['JC', 'KH', '4D', '6S'], 'AH', True], 4]], [[[['9S', '3S', 'QS', 'TS'], 'QH', False], 6], [[['AS', '9S', 'TS', '2S'], '4C', False], 8], [[['TD', 'KS', 'TH', 'TS'], 'JC', False], 6], [[['KS', '5D', '3H', '8D'], 'KD', True], 6], [[['2S', '8S', 'TC', 'JS'], 'QH', False], 3], [[['9H', '7S', 'QH', '5H'], '3D', False], 4], [[['JH', 'TH', '5D', '6C'], '4C', False], 9], [[['4C', 'AD', '4H', '2D'], 'JC', False], 6]], [[[['3S', '3H', '5H', 'JH'], 'QS', False], 6], [[['2H', '5H', 'AC', '3S'], '8C', False], 5], [[['AD', '4S', '9D', '4H'], 'TH', False], 6], [[['9S', '9C', 'JH', 'KS'], '3H', False], 3], [[['KD', 'TC', 'QS', '4D'], 'TH', True], 2], [[['QD', '8S', 'JC', '5H'], '6C', False], 5], [[['JS', '8S', '2S', 'TS'], '2D', False], 6], [[['JH', '2C', '3D', '9S'], 'JS', False], 6]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("hand score 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    hand, starter, crib = x
    order = 'A23456789TJQK'
    cards = hand + [starter]
    def val(c):
        return min(order.index(c[0]) + 1, 10)
    score = 0
    for k in range(2, 6):
        for combo in itertools.combinations(cards, k):
            if sum(val(c) for c in combo) == 15:
                score += 2
    for a, b in itertools.combinations(cards, 2):
        if a[0] == b[0]:
            score += 2
    ranks = sorted(order.index(c[0]) for c in cards)
    for size in (5, 4, 3):
        runs = 0
        for combo in itertools.combinations(ranks, size):
            if all(combo[i + 1] == combo[i] + 1 for i in range(size - 1)):
                runs += 1
        if runs:
            score += runs * size
            break
    suits = [c[1] for c in hand]
    if len(set(suits)) == 1:
        if starter[1] == suits[0]:
            score += 5
        elif not crib:
            score += 4
    for c in hand:
        if c[0] == 'J':
            score += 1
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['4D', '3D', 'TD', '2D'], 'JD', False], 12], [[['KD', 'AH', '4S', '8D'], 'QH', False], 4], [[['3C', '3S', '4S', '5H'], '2D', False], 12], [[['5H', '9S', '6S', '2S'], 'AH', False], 4], [[['3S', '3H', '5H', 'JH'], 'QS', False], 6], [[['4C', 'QC', 'AC', '6C'], '5D', True], 9], [[['AD', 'AH', '2S', '3H'], 'KC', False], 12], [[['7D', 'QS', 'JC', '2C'], '5D', True], 4]], [[[['6S', '8D', 'JD', '9C'], '6D', False], 7], [[['4S', '5D', '9D', 'TC'], 'QH', True], 4], [[['5H', 'KC', '2H', '3S'], '6H', True], 4], [[['9H', '7H', 'QH', 'TH'], 'JH', False], 9], [[['2C', '2S', '3S', '4H'], 'KD', False], 12], [[['4S', '3S', '9S', 'TD'], '7C', False], 0], [[['TD', 'KS', 'TH', 'TS'], 'JC', False], 6], [[['JD', 'TS', '5D', '9S'], '4C', False], 7]], [[[['3H', 'QS', '3C', '6S'], '8D', False], 2], [[['JH', '9H', '9S', 'TD'], '3H', False], 9], [[['6C', '2C', '7C', 'AC'], '4H', True], 2], [[['4D', 'AS', '7H', 'QD'], '9S', False], 2], [[['6S', '5S', 'QS', '8C'], 'AC', False], 4], [[['8S', 'QS', 'TH', '9C'], 'QC', False], 5], [[['4S', 'QD', '8D', '9H'], 'JD', False], 0], [[['JC', 'KH', '4D', '6S'], 'AH', True], 4]], [[[['9S', '3S', 'QS', 'TS'], 'QH', False], 6], [[['AS', '9S', 'TS', '2S'], '4C', False], 8], [[['TD', 'KS', 'TH', 'TS'], 'JC', False], 6], [[['KS', '5D', '3H', '8D'], 'KD', True], 6], [[['2S', '8S', 'TC', 'JS'], 'QH', False], 3], [[['9H', '7S', 'QH', '5H'], '3D', False], 4], [[['JH', 'TH', '5D', '6C'], '4C', False], 9], [[['4C', 'AD', '4H', '2D'], 'JC', False], 6]], [[[['3S', '3H', '5H', 'JH'], 'QS', False], 6], [[['2H', '5H', 'AC', '3S'], '8C', False], 5], [[['AD', '4S', '9D', '4H'], 'TH', False], 6], [[['9S', '9C', 'JH', 'KS'], '3H', False], 3], [[['KD', 'TC', 'QS', '4D'], 'TH', True], 2], [[['QD', '8S', 'JC', '5H'], '6C', False], 5], [[['JS', '8S', '2S', 'TS'], '2D', False], 6], [[['JH', '2C', '3D', '9S'], 'JS', False], 6]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("hand score 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)

prompt:
The starter jack matches its own suit and adds a point to every hand.

Input [four_card_hand, starter, is_crib]. Fifteens (any 2-5 cards, A=1, T/J/Q/K=10) score 2; each pair 2; runs score their length for every distinct combination of the longest run length; a four-card hand flush scores 4 (+1 with the starter) but the crib scores only a five-card flush; a hand jack matching the starter suit scores 1. Return the total.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    hand, starter, crib = x
    order = 'A23456789TJQK'
    cards = hand + [starter]
    def val(c):
        return min(order.index(c[0]) + 1, 10)
    score = 0
    for k in range(2, 6):
        for combo in itertools.combinations(cards, k):
            if sum(val(c) for c in combo) == 15:
                score += 2
    for r in set(c[0] for c in cards):
        if sum(1 for c in cards if c[0] == r) >= 2:
            score += 2
    ranks = sorted(order.index(c[0]) for c in cards)
    for size in (5, 4, 3):
        runs = 0
        for combo in itertools.combinations(ranks, size):
            if all(combo[i + 1] == combo[i] + 1 for i in range(size - 1)):
                runs += 1
        if runs:
            score += runs * size
            break
    suits = [c[1] for c in hand]
    if len(set(suits)) == 1:
        if starter[1] == suits[0]:
            score += 5
        elif not crib:
            score += 4
    for c in hand:
        if c[0] == 'J' and c[1] == starter[1]:
            score += 1
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['AC', '9C', '4C', 'TC'], '5S', True], 6], [[['KD', 'AH', '4S', '8D'], 'QH', False], 4], [[['3C', '3S', '4S', '5H'], '2D', False], 12], [[['5H', '9S', '6S', '2S'], 'AH', False], 4], [[['3S', '3H', '5H', 'JH'], 'QS', False], 6], [[['4C', 'QC', 'AC', '6C'], '5D', True], 9], [[['TD', 'KS', 'TH', 'TS'], 'JC', False], 6], [[['6H', '7H', 'TC', 'TD'], 'TS', False], 6]], [[[['6S', '8D', 'JD', '9C'], '6D', False], 7], [[['4S', '5D', '9D', 'TC'], 'QH', True], 4], [[['5H', 'KC', '2H', '3S'], '6H', True], 4], [[['9H', '7H', 'QH', 'TH'], 'JH', False], 9], [[['2C', '2S', '3S', '4H'], 'KD', False], 12], [[['4S', '3S', '9S', 'TD'], '7C', False], 0], [[['6H', '7H', 'TC', 'TD'], 'TS', False], 6], [[['5H', '5D', '5S', 'JC'], '5C', False], 29]], [[[['3H', 'QS', '3C', '6S'], '8D', False], 2], [[['JH', '9H', '9S', 'TD'], '3H', False], 9], [[['6C', '2C', '7C', 'AC'], '4H', True], 2], [[['4D', 'AS', '7H', 'QD'], '9S', False], 2], [[['6S', '5S', 'QS', '8C'], 'AC', False], 4], [[['8S', 'QS', 'TH', '9C'], 'QC', False], 5], [[['6H', '7H', 'TC', 'TD'], 'TS', False], 6], [[['6H', '7H', 'TC', 'TD'], 'TS', False], 6]], [[[['9S', '3S', 'QS', 'TS'], 'QH', False], 6], [[['AS', '9S', 'TS', '2S'], '4C', False], 8], [[['TD', 'KS', 'TH', 'TS'], 'JC', False], 6], [[['KS', '5D', '3H', '8D'], 'KD', True], 6], [[['2S', '8S', 'TC', 'JS'], 'QH', False], 3], [[['9H', '7S', 'QH', '5H'], '3D', False], 4], [[['6H', '7H', 'TC', 'TD'], 'TS', False], 6], [[['4H', '4D', '4S', '3C'], '8C', False], 14]], [[[['8D', '8C', '9S', 'TH'], 'AH', True], 8], [[['2H', '5H', 'AC', '3S'], '8C', False], 5], [[['AD', '4S', '9D', '4H'], 'TH', False], 6], [[['9S', '9C', 'JH', 'KS'], '3H', False], 3], [[['KD', 'TC', 'QS', '4D'], 'TH', True], 2], [[['QD', '8S', 'JC', '5H'], '6C', False], 5], [[['6H', '7H', 'TC', 'TD'], 'TS', False], 6], [[['AC', 'AH', '2S', '3H'], 'AD', False], 15]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("hand score 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    hand, starter, crib = x
    order = 'A23456789TJQK'
    cards = hand + [starter]
    def val(c):
        return min(order.index(c[0]) + 1, 10)
    score = 0
    for k in range(2, 6):
        for combo in itertools.combinations(cards, k):
            if sum(val(c) for c in combo) == 15:
                score += 2
    for r in set(c[0] for c in cards):
        k = sum(1 for c in cards if c[0] == r)
        if k >= 2:
            score += 2 * (k - 1)
    ranks = sorted(order.index(c[0]) for c in cards)
    for size in (5, 4, 3):
        runs = 0
        for combo in itertools.combinations(ranks, size):
            if all(combo[i + 1] == combo[i] + 1 for i in range(size - 1)):
                runs += 1
        if runs:
            score += runs * size
            break
    suits = [c[1] for c in hand]
    if len(set(suits)) == 1:
        if starter[1] == suits[0]:
            score += 5
        elif not crib:
            score += 4
    for c in hand:
        if c[0] == 'J' and c[1] == starter[1]:
            score += 1
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['AC', '9C', '4C', 'TC'], '5S', True], 6], [[['KD', 'AH', '4S', '8D'], 'QH', False], 4], [[['3C', '3S', '4S', '5H'], '2D', False], 12], [[['5H', '9S', '6S', '2S'], 'AH', False], 4], [[['3S', '3H', '5H', 'JH'], 'QS', False], 6], [[['4C', 'QC', 'AC', '6C'], '5D', True], 9], [[['TD', 'KS', 'TH', 'TS'], 'JC', False], 6], [[['6H', '7H', 'TC', 'TD'], 'TS', False], 6]], [[[['6S', '8D', 'JD', '9C'], '6D', False], 7], [[['4S', '5D', '9D', 'TC'], 'QH', True], 4], [[['5H', 'KC', '2H', '3S'], '6H', True], 4], [[['9H', '7H', 'QH', 'TH'], 'JH', False], 9], [[['2C', '2S', '3S', '4H'], 'KD', False], 12], [[['4S', '3S', '9S', 'TD'], '7C', False], 0], [[['6H', '7H', 'TC', 'TD'], 'TS', False], 6], [[['5H', '5D', '5S', 'JC'], '5C', False], 29]], [[[['3H', 'QS', '3C', '6S'], '8D', False], 2], [[['JH', '9H', '9S', 'TD'], '3H', False], 9], [[['6C', '2C', '7C', 'AC'], '4H', True], 2], [[['4D', 'AS', '7H', 'QD'], '9S', False], 2], [[['6S', '5S', 'QS', '8C'], 'AC', False], 4], [[['8S', 'QS', 'TH', '9C'], 'QC', False], 5], [[['6H', '7H', 'TC', 'TD'], 'TS', False], 6], [[['6H', '7H', 'TC', 'TD'], 'TS', False], 6]], [[[['9S', '3S', 'QS', 'TS'], 'QH', False], 6], [[['AS', '9S', 'TS', '2S'], '4C', False], 8], [[['TD', 'KS', 'TH', 'TS'], 'JC', False], 6], [[['KS', '5D', '3H', '8D'], 'KD', True], 6], [[['2S', '8S', 'TC', 'JS'], 'QH', False], 3], [[['9H', '7S', 'QH', '5H'], '3D', False], 4], [[['6H', '7H', 'TC', 'TD'], 'TS', False], 6], [[['4H', '4D', '4S', '3C'], '8C', False], 14]], [[[['8D', '8C', '9S', 'TH'], 'AH', True], 8], [[['2H', '5H', 'AC', '3S'], '8C', False], 5], [[['AD', '4S', '9D', '4H'], 'TH', False], 6], [[['9S', '9C', 'JH', 'KS'], '3H', False], 3], [[['KD', 'TC', 'QS', '4D'], 'TH', True], 2], [[['QD', '8S', 'JC', '5H'], '6C', False], 5], [[['6H', '7H', 'TC', 'TD'], 'TS', False], 6], [[['AC', 'AH', '2S', '3H'], 'AD', False], 15]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("hand score 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)

prompt:
A pair royal is worth 2 instead of 6.

Input [four_card_hand, starter, is_crib]. Fifteens (any 2-5 cards, A=1, T/J/Q/K=10) score 2; each pair 2; runs score their length for every distinct combination of the longest run length; a four-card hand flush scores 4 (+1 with the starter) but the crib scores only a five-card flush; a hand jack matching the starter suit scores 1. Return the total.

split: open-access


prompt:
A five played after 5-6 pegs a pair.

Input [cards_in_current_count, new_card]. Values A=1, T/J/Q/K=10; a count above 31 is "illegal". Points: count 15 -> 2, count 31 -> 2; the new card with the immediately preceding same-rank run scores 2/6/12; the longest trailing sequence of 3+ cards whose ranks are consecutive in any order scores its length. Return [points, count].

split: open-access


prompt:
Completing a four- or five-card run pegs 3.

Input [cards_in_current_count, new_card]. Values A=1, T/J/Q/K=10; a count above 31 is "illegal". Points: count 15 -> 2, count 31 -> 2; the new card with the immediately preceding same-rank run scores 2/6/12; the longest trailing sequence of 3+ cards whose ranks are consecutive in any order scores its length. Return [points, count].

split: open-access


prompt:
Cards that make exactly 31 are refused.

Input [cards_in_current_count, new_card]. Values A=1, T/J/Q/K=10; a count above 31 is "illegal". Points: count 15 -> 2, count 31 -> 2; the new card with the immediately preceding same-rank run scores 2/6/12; the longest trailing sequence of 3+ cards whose ranks are consecutive in any order scores its length. Return [points, count].

split: open-access


prompt:
Reaching 30 scores 2.

Input [cards_in_current_count, new_card]. Values A=1, T/J/Q/K=10; a count above 31 is "illegal". Points: count 15 -> 2, count 31 -> 2; the new card with the immediately preceding same-rank run scores 2/6/12; the longest trailing sequence of 3+ cards whose ranks are consecutive in any order scores its length. Return [points, count].

split: open-access


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

N = 1
observations = []
def solve(x):
    level, strain, dbl, vul, tricks = x
    need = 6 + level
    if tricks < need:
        down = need - tricks
        if dbl == 0:
            return -(100 if vul else 50) * down
        pen = 0
        for k in range(1, down + 1):
            if vul:
                pen += 200 if k == 1 else 300
            else:
                pen += 100 if k == 1 else 200 if k <= 3 else 300
        return -pen * dbl
    per = 20 if strain in 'CD' else 30
    base = per * level + (10 * level if strain == 'N' else 0)
    mult = [1, 2, 4][dbl]
    trick_score = base * mult
    score = trick_score
    score += (500 if vul else 300) if trick_score >= 100 else 50
    if level == 6:
        score += 750 if vul else 500
    elif level == 7:
        score += 1500 if vul else 1000
    over = tricks - need
    if dbl == 0:
        score += over * per
    else:
        score += over * (200 if vul else 100) * dbl
    score += 50 * dbl
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[7, 'N', 2, False, 13], 2280], [[7, 'S', 0, True, 12], -100], [[6, 'N', 0, True, 12], 1440], [[2, 'H', 1, True, 9], 870], [[3, 'H', 2, False, 11], 1160], [[5, 'N', 0, False, 11], 460], [[2, 'D', 0, True, 8], 90], [[4, 'N', 0, True, 12], 690]], [[[6, 'S', 0, False, 12], 980], [[7, 'D', 0, True, 8], -500], [[6, 'H', 0, False, 12], 980], [[6, 'H', 0, False, 11], -50], [[6, 'N', 0, False, 12], 990], [[6, 'D', 2, True, 13], 2230], [[5, 'N', 0, True, 6], -500], [[7, 'N', 1, True, 13], 2490]], [[[6, 'N', 0, True, 12], 1440], [[2, 'C', 0, True, 9], 110], [[4, 'N', 0, False, 12], 490], [[7, 'C', 0, True, 13], 2140], [[3, 'S', 1, False, 5], -800], [[5, 'C', 2, False, 13], 1200], [[7, 'C', 1, True, 8], -1400], [[1, 'N', 0, True, 7], 90]], [[[4, 'N', 2, True, 11], 1520], [[2, 'C', 2, False, 7], -200], [[2, 'H', 2, False, 5], -1000], [[7, 'H', 2, False, 11], -600], [[3, 'N', 1, True, 7], -500], [[6, 'S', 0, True, 12], 1430], [[4, 'N', 0, True, 12], 690], [[3, 'N', 2, False, 11], 1200]], [[[1, 'D', 2, True, 6], -400], [[5, 'H', 0, True, 11], 650], [[4, 'D', 0, True, 7], -300], [[7, 'D', 1, True, 10], -800], [[4, 'C', 1, True, 9], -200], [[3, 'S', 2, True, 9], 960], [[6, 'N', 0, False, 12], 990], [[7, 'N', 1, True, 13], 2490]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("duplicate score 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)

prompt:
3NT made scores as a partscore.

Input [level, strain, doubled(0/1/2), vulnerable, tricks]. Trick score C/D 20, H/S 30, NT 40+30; x2/x4 doubled/redoubled. Game bonus 300/500 when trick score >= 100 else 50 partscore; slam 500/750 (6) or 1000/1500 (7); overtricks trick value undoubled, 100/200 per double level; insult 50 per double level. Undertricks: 50/100 undoubled; doubled NV 100, 200, 200, then 300; doubled V 200 then 300; redoubled x2.

split: open-access


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

N = 1
observations = []
def solve(x):
    level, strain, dbl, vul, tricks = x
    need = 6 + level
    if tricks < need:
        down = need - tricks
        if dbl == 0:
            return -(100 if vul else 50) * down
        pen = 0
        for k in range(1, down + 1):
            if vul:
                pen += 200 if k == 1 else 300
            else:
                pen += 100 if k == 1 else 200 if k <= 3 else 300
        return -pen * dbl
    per = 20 if strain in 'CD' else 30
    base = per * level + (10 if strain == 'N' else 0)
    mult = [1, 2, 4][dbl]
    trick_score = base * mult
    score = trick_score
    score += (500 if vul else 300) if base >= 100 else 50
    if level == 6:
        score += 750 if vul else 500
    elif level == 7:
        score += 1500 if vul else 1000
    over = tricks - need
    if dbl == 0:
        score += over * per
    else:
        score += over * (200 if vul else 100) * dbl
    score += 50 * dbl
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[4, 'C', 1, False, 10], 510], [[7, 'S', 0, True, 12], -100], [[6, 'N', 0, True, 12], 1440], [[2, 'H', 1, True, 9], 870], [[3, 'H', 2, False, 11], 1160], [[5, 'N', 0, False, 11], 460], [[2, 'D', 0, True, 8], 90], [[5, 'C', 0, False, 12], 420]], [[[6, 'S', 0, False, 12], 980], [[7, 'D', 0, True, 8], -500], [[6, 'H', 0, False, 12], 980], [[6, 'H', 0, False, 11], -50], [[6, 'N', 0, False, 12], 990], [[6, 'D', 2, True, 13], 2230], [[3, 'S', 2, True, 9], 960], [[5, 'C', 0, False, 12], 420]], [[[6, 'H', 0, True, 13], 1460], [[2, 'C', 0, True, 9], 110], [[4, 'N', 0, False, 12], 490], [[7, 'C', 0, True, 13], 2140], [[3, 'S', 1, False, 5], -800], [[5, 'C', 2, False, 13], 1200], [[2, 'H', 1, True, 8], 670], [[5, 'C', 0, False, 12], 420]], [[[4, 'N', 2, True, 11], 1520], [[2, 'C', 2, False, 7], -200], [[2, 'H', 2, False, 5], -1000], [[7, 'H', 2, False, 11], -600], [[3, 'N', 1, True, 7], -500], [[6, 'S', 0, True, 12], 1430], [[5, 'C', 0, False, 12], 420], [[4, 'D', 2, False, 11], 920]], [[[1, 'D', 2, True, 6], -400], [[5, 'H', 0, True, 11], 650], [[4, 'D', 0, True, 7], -300], [[7, 'D', 1, True, 10], -800], [[4, 'C', 1, True, 9], -200], [[3, 'S', 2, True, 9], 960], [[5, 'C', 0, False, 12], 420], [[3, 'D', 2, True, 9], 840]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("duplicate score 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)

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

N = 1
observations = []
def solve(x):
    level, strain, dbl, vul, tricks = x
    need = 6 + level
    if tricks < need:
        down = need - tricks
        if dbl == 0:
            return -(100 if vul else 50) * down
        pen = 0
        for k in range(1, down + 1):
            if vul:
                pen += 200 if k == 1 else 300
            else:
                pen += 100 if k == 1 else 200 if k <= 3 else 300
        return -pen * dbl
    per = 20 if strain in 'CD' else 30
    base = per * level + (10 if strain == 'N' else 0)
    mult = [1, 2, 4][dbl]
    trick_score = base * mult
    score = trick_score
    score += (500 if vul else 300) if trick_score > 100 else 50
    if level == 6:
        score += 750 if vul else 500
    elif level == 7:
        score += 1500 if vul else 1000
    over = tricks - need
    if dbl == 0:
        score += over * per
    else:
        score += over * (200 if vul else 100) * dbl
    score += 50 * dbl
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[4, 'C', 1, False, 10], 510], [[7, 'S', 0, True, 12], -100], [[6, 'N', 0, True, 12], 1440], [[2, 'H', 1, True, 9], 870], [[3, 'H', 2, False, 11], 1160], [[5, 'N', 0, False, 11], 460], [[2, 'D', 0, True, 8], 90], [[5, 'C', 0, False, 12], 420]], [[[6, 'S', 0, False, 12], 980], [[7, 'D', 0, True, 8], -500], [[6, 'H', 0, False, 12], 980], [[6, 'H', 0, False, 11], -50], [[6, 'N', 0, False, 12], 990], [[6, 'D', 2, True, 13], 2230], [[3, 'S', 2, True, 9], 960], [[5, 'C', 0, False, 12], 420]], [[[6, 'H', 0, True, 13], 1460], [[2, 'C', 0, True, 9], 110], [[4, 'N', 0, False, 12], 490], [[7, 'C', 0, True, 13], 2140], [[3, 'S', 1, False, 5], -800], [[5, 'C', 2, False, 13], 1200], [[2, 'H', 1, True, 8], 670], [[5, 'C', 0, False, 12], 420]], [[[4, 'N', 2, True, 11], 1520], [[2, 'C', 2, False, 7], -200], [[2, 'H', 2, False, 5], -1000], [[7, 'H', 2, False, 11], -600], [[3, 'N', 1, True, 7], -500], [[6, 'S', 0, True, 12], 1430], [[5, 'C', 0, False, 12], 420], [[4, 'D', 2, False, 11], 920]], [[[1, 'D', 2, True, 6], -400], [[5, 'H', 0, True, 11], 650], [[4, 'D', 0, True, 7], -300], [[7, 'D', 1, True, 10], -800], [[4, 'C', 1, True, 9], -200], [[3, 'S', 2, True, 9], 960], [[5, 'C', 0, False, 12], 420], [[3, 'D', 2, True, 9], 840]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("duplicate score 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)

prompt:
2H doubled and made gets a partscore bonus.

Input [level, strain, doubled(0/1/2), vulnerable, tricks]. Trick score C/D 20, H/S 30, NT 40+30; x2/x4 doubled/redoubled. Game bonus 300/500 when trick score >= 100 else 50 partscore; slam 500/750 (6) or 1000/1500 (7); overtricks trick value undoubled, 100/200 per double level; insult 50 per double level. Undertricks: 50/100 undoubled; doubled NV 100, 200, 200, then 300; doubled V 200 then 300; redoubled x2.

split: open-access


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

N = 1
observations = []
def solve(x):
    level, strain, dbl, vul, tricks = x
    need = 6 + level
    if tricks < need:
        down = need - tricks
        if dbl == 0:
            return -(100 if vul else 50) * down
        pen = 0
        for k in range(1, down + 1):
            if vul:
                pen += 200 if k == 1 else 300
            else:
                pen += 100 if k == 1 else 200
        return -pen * dbl
    per = 20 if strain in 'CD' else 30
    base = per * level + (10 if strain == 'N' else 0)
    mult = [1, 2, 4][dbl]
    trick_score = base * mult
    score = trick_score
    score += (500 if vul else 300) if trick_score >= 100 else 50
    if level == 6:
        score += 750 if vul else 500
    elif level == 7:
        score += 1500 if vul else 1000
    over = tricks - need
    if dbl == 0:
        score += over * per
    else:
        score += over * (200 if vul else 100) * dbl
    score += 50 * dbl
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[4, 'C', 1, False, 10], 510], [[7, 'S', 0, True, 12], -100], [[6, 'N', 0, True, 12], 1440], [[2, 'H', 1, True, 9], 870], [[3, 'H', 2, False, 11], 1160], [[5, 'N', 0, False, 11], 460], [[3, 'S', 1, False, 5], -800], [[3, 'N', 2, False, 4], -2200]], [[[6, 'S', 0, False, 12], 980], [[7, 'D', 0, True, 8], -500], [[6, 'H', 0, False, 12], 980], [[6, 'H', 0, False, 11], -50], [[6, 'N', 0, False, 12], 990], [[6, 'D', 2, True, 13], 2230], [[5, 'N', 2, False, 6], -2200], [[2, 'C', 1, False, 4], -800]], [[[6, 'H', 0, True, 13], 1460], [[2, 'C', 0, True, 9], 110], [[4, 'N', 0, False, 12], 490], [[7, 'C', 0, True, 13], 2140], [[3, 'S', 1, False, 5], -800], [[5, 'C', 2, False, 13], 1200], [[3, 'N', 2, False, 4], -2200], [[3, 'N', 2, False, 4], -2200]], [[[4, 'N', 2, True, 11], 1520], [[2, 'C', 2, False, 7], -200], [[2, 'H', 2, False, 5], -1000], [[7, 'H', 2, False, 11], -600], [[3, 'N', 1, True, 7], -500], [[6, 'S', 0, True, 12], 1430], [[5, 'N', 2, False, 6], -2200], [[2, 'D', 1, False, 3], -1100]], [[[1, 'D', 2, True, 6], -400], [[5, 'H', 0, True, 11], 650], [[4, 'D', 0, True, 7], -300], [[7, 'D', 1, True, 10], -800], [[4, 'C', 1, True, 9], -200], [[3, 'S', 2, True, 9], 960], [[1, 'D', 2, False, 2], -2200], [[3, 'N', 2, False, 4], -2200]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("duplicate score 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)

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

N = 1
observations = []
def solve(x):
    level, strain, dbl, vul, tricks = x
    need = 6 + level
    if tricks < need:
        down = need - tricks
        if dbl == 0:
            return -(100 if vul else 50) * down
        pen = 0
        for k in range(1, down + 1):
            if vul:
                pen += 200 if k == 1 else 300
            else:
                pen += 100 if k == 1 else 200 if k <= 4 else 300
        return -pen * dbl
    per = 20 if strain in 'CD' else 30
    base = per * level + (10 if strain == 'N' else 0)
    mult = [1, 2, 4][dbl]
    trick_score = base * mult
    score = trick_score
    score += (500 if vul else 300) if trick_score >= 100 else 50
    if level == 6:
        score += 750 if vul else 500
    elif level == 7:
        score += 1500 if vul else 1000
    over = tricks - need
    if dbl == 0:
        score += over * per
    else:
        score += over * (200 if vul else 100) * dbl
    score += 50 * dbl
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[4, 'C', 1, False, 10], 510], [[7, 'S', 0, True, 12], -100], [[6, 'N', 0, True, 12], 1440], [[2, 'H', 1, True, 9], 870], [[3, 'H', 2, False, 11], 1160], [[5, 'N', 0, False, 11], 460], [[3, 'S', 1, False, 5], -800], [[3, 'N', 2, False, 4], -2200]], [[[6, 'S', 0, False, 12], 980], [[7, 'D', 0, True, 8], -500], [[6, 'H', 0, False, 12], 980], [[6, 'H', 0, False, 11], -50], [[6, 'N', 0, False, 12], 990], [[6, 'D', 2, True, 13], 2230], [[5, 'N', 2, False, 6], -2200], [[2, 'C', 1, False, 4], -800]], [[[6, 'H', 0, True, 13], 1460], [[2, 'C', 0, True, 9], 110], [[4, 'N', 0, False, 12], 490], [[7, 'C', 0, True, 13], 2140], [[3, 'S', 1, False, 5], -800], [[5, 'C', 2, False, 13], 1200], [[3, 'N', 2, False, 4], -2200], [[3, 'N', 2, False, 4], -2200]], [[[4, 'N', 2, True, 11], 1520], [[2, 'C', 2, False, 7], -200], [[2, 'H', 2, False, 5], -1000], [[7, 'H', 2, False, 11], -600], [[3, 'N', 1, True, 7], -500], [[6, 'S', 0, True, 12], 1430], [[5, 'N', 2, False, 6], -2200], [[2, 'D', 1, False, 3], -1100]], [[[1, 'D', 2, True, 6], -400], [[5, 'H', 0, True, 11], 650], [[4, 'D', 0, True, 7], -300], [[7, 'D', 1, True, 10], -800], [[4, 'C', 1, True, 9], -200], [[3, 'S', 2, True, 9], 960], [[1, 'D', 2, False, 2], -2200], [[3, 'N', 2, False, 4], -2200]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("duplicate score 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)

prompt:
Big sacrifices are undercharged.

Input [level, strain, doubled(0/1/2), vulnerable, tricks]. Trick score C/D 20, H/S 30, NT 40+30; x2/x4 doubled/redoubled. Game bonus 300/500 when trick score >= 100 else 50 partscore; slam 500/750 (6) or 1000/1500 (7); overtricks trick value undoubled, 100/200 per double level; insult 50 per double level. Undertricks: 50/100 undoubled; doubled NV 100, 200, 200, then 300; doubled V 200 then 300; redoubled x2.

split: open-access


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

N = 1
observations = []
def solve(x):
    level, strain, dbl, vul, tricks = x
    need = 6 + level
    if tricks < need:
        down = need - tricks
        if dbl == 0:
            return -(100 if vul else 50) * down
        pen = 0
        for k in range(1, down + 1):
            if vul:
                pen += 200 if k == 1 else 300
            else:
                pen += 100 if k == 1 else 200 if k <= 3 else 300
        return -pen * dbl
    per = 20 if strain in 'CD' else 30
    base = per * level + (10 if strain == 'N' else 0)
    mult = [1, 2, 4][dbl]
    trick_score = base * mult
    score = trick_score
    score += (500 if vul else 300) if trick_score >= 100 else 50
    if level == 6:
        score += 750 if vul else 500
    elif level == 7:
        score += 1500 if vul else 1000
    over = tricks - need
    if dbl == 0:
        score += over * per
    else:
        score += over * (200 if vul else 100)
    score += 50 * dbl
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[4, 'C', 1, False, 10], 510], [[7, 'S', 0, True, 12], -100], [[6, 'N', 0, True, 12], 1440], [[2, 'H', 1, True, 9], 870], [[3, 'H', 2, False, 11], 1160], [[5, 'N', 0, False, 11], 460], [[2, 'D', 0, True, 8], 90], [[1, 'H', 1, True, 8], 360]], [[[6, 'S', 0, False, 12], 980], [[7, 'D', 0, True, 8], -500], [[6, 'H', 0, False, 12], 980], [[6, 'H', 0, False, 11], -50], [[6, 'N', 0, False, 12], 990], [[6, 'D', 2, True, 13], 2230], [[4, 'N', 2, True, 11], 1520], [[1, 'D', 2, True, 8], 630]], [[[6, 'H', 0, True, 13], 1460], [[2, 'C', 0, True, 9], 110], [[4, 'N', 0, False, 12], 490], [[7, 'C', 0, True, 13], 2140], [[3, 'S', 1, False, 5], -800], [[5, 'C', 2, False, 13], 1200], [[2, 'D', 2, False, 10], 960], [[4, 'D', 2, False, 11], 920]], [[[4, 'N', 2, True, 11], 1520], [[2, 'C', 2, False, 7], -200], [[2, 'H', 2, False, 5], -1000], [[7, 'H', 2, False, 11], -600], [[3, 'N', 1, True, 7], -500], [[6, 'S', 0, True, 12], 1430], [[6, 'D', 2, True, 13], 2230], [[1, 'C', 1, False, 8], 240]], [[[1, 'D', 2, True, 6], -400], [[5, 'H', 0, True, 11], 650], [[4, 'D', 0, True, 7], -300], [[7, 'D', 1, True, 10], -800], [[4, 'C', 1, True, 9], -200], [[3, 'S', 2, True, 9], 960], [[4, 'D', 2, False, 11], 920], [[4, 'C', 1, True, 12], 1110]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("duplicate score 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)

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

N = 1
observations = []
def solve(x):
    level, strain, dbl, vul, tricks = x
    need = 6 + level
    if tricks < need:
        down = need - tricks
        if dbl == 0:
            return -(100 if vul else 50) * down
        pen = 0
        for k in range(1, down + 1):
            if vul:
                pen += 200 if k == 1 else 300
            else:
                pen += 100 if k == 1 else 200 if k <= 3 else 300
        return -pen * dbl
    per = 20 if strain in 'CD' else 30
    base = per * level + (10 if strain == 'N' else 0)
    mult = [1, 2, 4][dbl]
    trick_score = base * mult
    score = trick_score
    score += (500 if vul else 300) if trick_score >= 100 else 50
    if level == 6:
        score += 750 if vul else 500
    elif level == 7:
        score += 1500 if vul else 1000
    over = tricks - need
    if dbl == 0:
        score += over * per
    else:
        score += over * per * mult
    score += 50 * dbl
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[4, 'C', 1, False, 10], 510], [[7, 'S', 0, True, 12], -100], [[6, 'N', 0, True, 12], 1440], [[2, 'H', 1, True, 9], 870], [[3, 'H', 2, False, 11], 1160], [[5, 'N', 0, False, 11], 460], [[2, 'D', 0, True, 8], 90], [[1, 'H', 1, True, 8], 360]], [[[6, 'S', 0, False, 12], 980], [[7, 'D', 0, True, 8], -500], [[6, 'H', 0, False, 12], 980], [[6, 'H', 0, False, 11], -50], [[6, 'N', 0, False, 12], 990], [[6, 'D', 2, True, 13], 2230], [[4, 'N', 2, True, 11], 1520], [[1, 'D', 2, True, 8], 630]], [[[6, 'H', 0, True, 13], 1460], [[2, 'C', 0, True, 9], 110], [[4, 'N', 0, False, 12], 490], [[7, 'C', 0, True, 13], 2140], [[3, 'S', 1, False, 5], -800], [[5, 'C', 2, False, 13], 1200], [[2, 'D', 2, False, 10], 960], [[4, 'D', 2, False, 11], 920]], [[[4, 'N', 2, True, 11], 1520], [[2, 'C', 2, False, 7], -200], [[2, 'H', 2, False, 5], -1000], [[7, 'H', 2, False, 11], -600], [[3, 'N', 1, True, 7], -500], [[6, 'S', 0, True, 12], 1430], [[6, 'D', 2, True, 13], 2230], [[1, 'C', 1, False, 8], 240]], [[[1, 'D', 2, True, 6], -400], [[5, 'H', 0, True, 11], 650], [[4, 'D', 0, True, 7], -300], [[7, 'D', 1, True, 10], -800], [[4, 'C', 1, True, 9], -200], [[3, 'S', 2, True, 9], 960], [[4, 'D', 2, False, 11], 920], [[4, 'C', 1, True, 12], 1110]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("duplicate score 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)

prompt:
Each redoubled overtrick earns 100/200 instead of 200/400.

Input [level, strain, doubled(0/1/2), vulnerable, tricks]. Trick score C/D 20, H/S 30, NT 40+30; x2/x4 doubled/redoubled. Game bonus 300/500 when trick score >= 100 else 50 partscore; slam 500/750 (6) or 1000/1500 (7); overtricks trick value undoubled, 100/200 per double level; insult 50 per double level. Undertricks: 50/100 undoubled; doubled NV 100, 200, 200, then 300; doubled V 200 then 300; redoubled x2.

split: open-access


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

N = 1
observations = []
def solve(x):
    level, strain, dbl, vul, tricks = x
    need = 6 + level
    if tricks < need:
        down = need - tricks
        if dbl == 0:
            return -(100 if vul else 50) * down
        pen = 0
        for k in range(1, down + 1):
            if vul:
                pen += 200 if k == 1 else 300
            else:
                pen += 100 if k == 1 else 200 if k <= 3 else 300
        return -pen * dbl
    per = 20 if strain in 'CD' else 30
    base = per * level + (10 if strain == 'N' else 0)
    mult = [1, 2, 4][dbl]
    trick_score = base * mult
    score = trick_score
    score += (500 if vul else 300) if trick_score >= 100 else 50
    if level == 6:
        score += 750 if vul else 500
    elif level == 7:
        score += 1500 if vul else 1000
    over = tricks - need
    if dbl == 0:
        score += over * per
    else:
        score += over * (200 if vul else 100) * dbl
    score += 50 if dbl else 0
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[7, 'C', 1, False, 13], 1630], [[7, 'S', 0, True, 12], -100], [[6, 'N', 0, True, 12], 1440], [[2, 'H', 1, True, 9], 870], [[3, 'H', 2, False, 11], 1160], [[5, 'N', 0, False, 11], 460], [[2, 'D', 0, True, 8], 90], [[2, 'H', 2, True, 9], 1240]], [[[2, 'H', 1, True, 9], 870], [[7, 'D', 0, True, 8], -500], [[6, 'H', 0, False, 12], 980], [[6, 'H', 0, False, 11], -50], [[6, 'N', 0, False, 12], 990], [[6, 'D', 2, True, 13], 2230], [[5, 'N', 0, True, 6], -500], [[2, 'C', 2, False, 8], 560]], [[[6, 'H', 0, True, 13], 1460], [[2, 'C', 0, True, 9], 110], [[4, 'N', 0, False, 12], 490], [[7, 'C', 0, True, 13], 2140], [[3, 'S', 1, False, 5], -800], [[5, 'C', 2, False, 13], 1200], [[7, 'C', 1, True, 8], -1400], [[5, 'C', 2, True, 12], 1400]], [[[4, 'N', 2, True, 11], 1520], [[2, 'C', 2, False, 7], -200], [[2, 'H', 2, False, 5], -1000], [[7, 'H', 2, False, 11], -600], [[3, 'N', 1, True, 7], -500], [[6, 'S', 0, True, 12], 1430], [[2, 'H', 2, True, 9], 1240], [[6, 'D', 2, True, 12], 1830]], [[[1, 'D', 2, True, 6], -400], [[5, 'H', 0, True, 11], 650], [[4, 'D', 0, True, 7], -300], [[7, 'D', 1, True, 10], -800], [[4, 'C', 1, True, 9], -200], [[3, 'S', 2, True, 9], 960], [[7, 'S', 1, True, 13], 2470], [[4, 'C', 2, False, 12], 1120]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("duplicate score 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)

prompt:
Doubled makes are 50 short.

Input [level, strain, doubled(0/1/2), vulnerable, tricks]. Trick score C/D 20, H/S 30, NT 40+30; x2/x4 doubled/redoubled. Game bonus 300/500 when trick score >= 100 else 50 partscore; slam 500/750 (6) or 1000/1500 (7); overtricks trick value undoubled, 100/200 per double level; insult 50 per double level. Undertricks: 50/100 undoubled; doubled NV 100, 200, 200, then 300; doubled V 200 then 300; redoubled x2.

split: open-access


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

N = 1
observations = []
def solve(x):
    level, strain, dbl, vul, tricks = x
    need = 6 + level
    if tricks < need:
        down = need - tricks
        if dbl == 0:
            return -(100 if vul else 50) * down
        pen = 0
        for k in range(1, down + 1):
            if vul:
                pen += 200 if k == 1 else 300
            else:
                pen += 100 if k == 1 else 200 if k <= 3 else 300
        return -pen * dbl
    per = 20 if strain in 'CD' else 30
    base = per * level + (10 if strain == 'N' else 0)
    mult = [1, 2, 4][dbl]
    trick_score = base * mult
    score = trick_score
    score += (500 if vul else 300) if trick_score >= 100 else 50
    if level == 6:
        score += 500
    elif level == 7:
        score += 1500 if vul else 1000
    over = tricks - need
    if dbl == 0:
        score += over * per
    else:
        score += over * (200 if vul else 100) * dbl
    score += 50 * dbl
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[4, 'C', 1, False, 10], 510], [[7, 'S', 0, True, 12], -100], [[6, 'N', 0, True, 12], 1440], [[2, 'H', 1, True, 9], 870], [[3, 'H', 2, False, 11], 1160], [[5, 'N', 0, False, 11], 460], [[2, 'D', 0, True, 8], 90], [[6, 'H', 0, False, 13], 1010]], [[[6, 'S', 0, False, 12], 980], [[7, 'D', 0, True, 8], -500], [[6, 'H', 0, False, 12], 980], [[6, 'H', 0, False, 11], -50], [[6, 'N', 0, False, 12], 990], [[6, 'D', 2, True, 13], 2230], [[6, 'S', 0, True, 12], 1430], [[6, 'H', 1, True, 13], 1860]], [[[6, 'H', 0, True, 13], 1460], [[2, 'C', 0, True, 9], 110], [[4, 'N', 0, False, 12], 490], [[7, 'C', 0, True, 13], 2140], [[3, 'S', 1, False, 5], -800], [[5, 'C', 2, False, 13], 1200], [[6, 'S', 1, True, 13], 1860], [[6, 'D', 2, True, 12], 1830]], [[[6, 'D', 2, True, 13], 2230], [[2, 'C', 2, False, 7], -200], [[2, 'H', 2, False, 5], -1000], [[7, 'H', 2, False, 11], -600], [[3, 'N', 1, True, 7], -500], [[6, 'S', 0, True, 12], 1430], [[4, 'C', 0, False, 6], -200], [[6, 'H', 1, True, 13], 1860]], [[[1, 'D', 2, True, 6], -400], [[5, 'H', 0, True, 11], 650], [[4, 'D', 0, True, 7], -300], [[7, 'D', 1, True, 10], -800], [[4, 'C', 1, True, 9], -200], [[3, 'S', 2, True, 9], 960], [[6, 'S', 0, True, 13], 1460], [[6, 'S', 0, True, 13], 1460]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("duplicate score 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)

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

N = 1
observations = []
def solve(x):
    level, strain, dbl, vul, tricks = x
    need = 6 + level
    if tricks < need:
        down = need - tricks
        if dbl == 0:
            return -(100 if vul else 50) * down
        pen = 0
        for k in range(1, down + 1):
            if vul:
                pen += 200 if k == 1 else 300
            else:
                pen += 100 if k == 1 else 200 if k <= 3 else 300
        return -pen * dbl
    per = 20 if strain in 'CD' else 30
    base = per * level + (10 if strain == 'N' else 0)
    mult = [1, 2, 4][dbl]
    trick_score = base * mult
    score = trick_score
    score += (500 if vul else 300) if trick_score >= 100 else 50
    if level == 6 and tricks == 12:
        score += 750 if vul else 500
    elif level == 7:
        score += 1500 if vul else 1000
    over = tricks - need
    if dbl == 0:
        score += over * per
    else:
        score += over * (200 if vul else 100) * dbl
    score += 50 * dbl
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[4, 'C', 1, False, 10], 510], [[7, 'S', 0, True, 12], -100], [[6, 'N', 0, True, 12], 1440], [[2, 'H', 1, True, 9], 870], [[3, 'H', 2, False, 11], 1160], [[5, 'N', 0, False, 11], 460], [[2, 'D', 0, True, 8], 90], [[6, 'H', 0, False, 13], 1010]], [[[6, 'S', 0, False, 12], 980], [[7, 'D', 0, True, 8], -500], [[6, 'H', 0, False, 12], 980], [[6, 'H', 0, False, 11], -50], [[6, 'N', 0, False, 12], 990], [[6, 'D', 2, True, 13], 2230], [[6, 'S', 0, True, 12], 1430], [[6, 'H', 1, True, 13], 1860]], [[[6, 'H', 0, True, 13], 1460], [[2, 'C', 0, True, 9], 110], [[4, 'N', 0, False, 12], 490], [[7, 'C', 0, True, 13], 2140], [[3, 'S', 1, False, 5], -800], [[5, 'C', 2, False, 13], 1200], [[6, 'S', 1, True, 13], 1860], [[6, 'D', 2, True, 12], 1830]], [[[6, 'D', 2, True, 13], 2230], [[2, 'C', 2, False, 7], -200], [[2, 'H', 2, False, 5], -1000], [[7, 'H', 2, False, 11], -600], [[3, 'N', 1, True, 7], -500], [[6, 'S', 0, True, 12], 1430], [[4, 'C', 0, False, 6], -200], [[6, 'H', 1, True, 13], 1860]], [[[1, 'D', 2, True, 6], -400], [[5, 'H', 0, True, 11], 650], [[4, 'D', 0, True, 7], -300], [[7, 'D', 1, True, 10], -800], [[4, 'C', 1, True, 9], -200], [[3, 'S', 2, True, 9], 960], [[6, 'S', 0, True, 13], 1460], [[6, 'S', 0, True, 13], 1460]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("duplicate score 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)

prompt:
6S vulnerable made is 250 short.

Input [level, strain, doubled(0/1/2), vulnerable, tricks]. Trick score C/D 20, H/S 30, NT 40+30; x2/x4 doubled/redoubled. Game bonus 300/500 when trick score >= 100 else 50 partscore; slam 500/750 (6) or 1000/1500 (7); overtricks trick value undoubled, 100/200 per double level; insult 50 per double level. Undertricks: 50/100 undoubled; doubled NV 100, 200, 200, then 300; doubled V 200 then 300; redoubled x2.

split: open-access