Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with open("input") as file:
- hands = [(line.split()[0],int(line.split()[1])) for line in file.read().splitlines()]
- def hand_type2(hand):
- counts = [hand.count(card) for card in 'AKQT98765432J']
- if (max(counts[:-1])+counts[-1]==5):
- return 6
- elif (max(counts[:-1])+counts[-1]==4):
- return 5
- elif (3 in counts and 2 in counts) or (counts.count(2) == 2 and 'J' in hand):
- return 4
- elif (max(counts[:-1])+counts[-1]==3):
- return 3
- elif counts.count(2) == 2 or (counts.count(2) == 1 and 'J' in hand):
- return 2
- elif 2 in counts or 'J' in hand:
- return 1
- return 0
- hands2 = sorted(sorted(hands, key=lambda x: ['J23456789TQKA'.index(c) for c in x[0]]), key=lambda x: hand_type2(x[0]))
- print(sum([hand[1]*(i+1) for i, hand in enumerate(hands2)]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement