Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Bridge Routine by U.V
def bridge_routine(hand, trump="notrump"):
trumps = 'shdc'
cards = {c: [] for c in trumps}
for c, b in hand:
cards[b[0]].append(c[0].upper() if c[0] in 'akqj' else 'x')
for t, c in cards.items():
cards[t] = ''.join(sorted(c, key=lambda x: 'AKQJx'.index(x)))
txt = ' '.join(v if v else '-' for v in cards.values())
ls = [len(i) for i in cards.values()]
p0 = txt.count('A') * 4 + txt.count('K') * 3 + txt.count('Q') * 2 + txt.count('J')
p1 = int(sorted(ls) == [3, 3, 3, 4])
p2 = sum(min(max(i - 4, 0), 3) for i in ls)
p3 = sum((i == 0) * 5 + (i == 1) * 3 for i, t in zip(ls, trumps) if t != trump[0])
p = p0 - p1 + p2 + p3 * (trump != 'notrump')
return [p, txt]
Oct. 21, 2023