Last active
December 7, 2023 19:46
-
-
Save vjeranc/5a58b62ef91dfedcbed6045cf7c0a39c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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