Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def day7(s, *, part2=False):
- rank = ['23456789TJQKA', 'J23456789TQKA'][part2]
- def order(hand):
- non_jokers = [card for card in hand if not (card == 'J' and part2)]
- counts = sorted(collections.Counter(non_jokers).values())[::-1] or [0]
- counts[0] += len(hand) - len(non_jokers)
- return counts, [rank.index(card) for card in hand]
- hand_bids = sorted((line.split() for line in s.splitlines()), key=lambda t: order(t[0]))
- return sum(int(bid) * i for i, (_, bid) in enumerate(hand_bids, 1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement