-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday7_2.py
More file actions
70 lines (60 loc) · 1.28 KB
/
day7_2.py
File metadata and controls
70 lines (60 loc) · 1.28 KB
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
lines = open("datos7_real.txt").read().split('\n')
alphabet = "AKQJT98765432"
mapp = {v: k for (k,v) in enumerate(alphabet)}
def rank(ss, joke):
k=[ 0 ]*6
j = ss.count('J') * joke
for chr in alphabet:
k[ss.count(chr)] += 1
if (k[5] > 0):
s = 0
elif (k[4] > 0):
s = 1
if (j > 0):
s = 0
elif (k[3] > 0) and (k[2] > 0) :
s = 2
if (j > 0):
s = 0
elif (k[3] > 0):
s = 3
if (j > 0):
s = 1
elif (k[2] > 1):
s = 4
if (j == 1):
s = 2
elif (j == 2):
s = 1
elif (k[2] > 0):
s = 5
if (j > 0):
s = 3
elif (j > 0):
s = 5
else:
s=6
for chr in ss:
if (joke and chr == "J"):
s = s * 14 + 13
else:
s = s * 14 + mapp[chr]
return s
def play(joke):
ranked = []
for l in range(len(lines)//2):
(hand, s) = (lines[l*2], lines[l*2+1])
ranked.append((rank(hand, joke), int(s), hand))
p = len(ranked)
s = 0
for (r,v,h) in sorted(ranked):
print (r,h,v,"*",p)
s += v * p
p -= 1
return(s)
def part1():
return play(0)
def part2():
return play(1)
print(part1())
print(part2())