-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06_part1.py
76 lines (64 loc) · 1.79 KB
/
06_part1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def get_card_type(card):
chars_set = set()
for char in card:
chars_set.add(char)
if len(chars_set) == 1:
return "Five of a kind"
if len(chars_set) == 2:
for char in card:
if card.count(char) == 4:
return "Four of a kind"
return "Full house"
if len(chars_set) == 3:
for char in card:
if card.count(char) == 3:
return "Three of a kind"
return "Two pair"
if len(chars_set) == 4:
return "One pair"
if len(chars_set) == 5:
return "High card"
def replace_all_letters(type, letters_dict):
for idx, hand in enumerate(type):
current_hand_cards = hand[0]
for char in current_hand_cards:
if char in letters_dict.keys():
type[idx][0] = type[idx][0].replace(char, letters_dict[char])
return type
line = input()
cards = {
"High card": [],
"One pair": [],
"Two pair": [],
"Three of a kind": [],
"Full house": [],
"Four of a kind": [],
"Five of a kind": [],
}
letter_values = {
"T": "B",
"J": "C",
"Q": "D",
"K": "E",
"A": "F"
}
rank = 0
while line != 'stop':
current_card = line.split()[0]
current_card_bid = int(line.split()[1])
current_card_type = get_card_type(current_card)
current_values = [current_card, current_card_bid]
cards[current_card_type].append(current_values)
line = input()
counter = 0
result = 0
for type in cards.keys():
print(type)
if cards[type]:
cards[type] = replace_all_letters(cards[type], letter_values)
cards[type].sort(key=lambda x: x[0])
for hand in cards[type]:
counter += 1
result += counter * hand[1]
print(f"{hand}, {counter}, {result}")
print(result)