Skip to content

Instantly share code, notes, and snippets.

@vjeranc
Last active December 7, 2023 19:46
Show Gist options
  • Save vjeranc/5a58b62ef91dfedcbed6045cf7c0a39c to your computer and use it in GitHub Desktop.
Save vjeranc/5a58b62ef91dfedcbed6045cf7c0a39c to your computer and use it in GitHub Desktop.
from collections import Counter
SND = True # False for part 1
def hand(cnts: Counter):
if SND and 'J' in cnts:
for c, _ in cnts.most_common(2):
if c == 'J': continue
cnts[c] += cnts['J']
cnts.pop('J', 0)
break
return tuple(c for _, c in cnts.most_common())
tr = str.maketrans('TJQKA', ['ABCDE','A0CDE'][SND])
ls = [l.split() for l in open(0)]
cs = sorted((hand(Counter(h)), h.translate(tr), b) for [h, b] in ls)
ans = 0
for i, (_,_,b) in enumerate(cs, 1):
ans += i * int(b)
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment