day 22 part 1
This commit is contained in:
parent
de03aad9d6
commit
264496e0e1
2 changed files with 94 additions and 0 deletions
41
22/1.py
Normal file
41
22/1.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
with open("input") as f:
|
||||
content = [x.strip() for x in f]
|
||||
|
||||
player1 = []
|
||||
player2 = []
|
||||
part = 0
|
||||
for c in content:
|
||||
if not c:
|
||||
part += 1
|
||||
continue
|
||||
if part == 0: # reading player 2 stack
|
||||
if c.startswith("Player"):
|
||||
continue
|
||||
player1.append(int(c))
|
||||
if part == 1: # reading player 1 stack
|
||||
if c.startswith("Player"):
|
||||
continue
|
||||
player2.append(int(c))
|
||||
|
||||
while len(player1) and len(player2):
|
||||
if player1[0] > player2[0]:
|
||||
player1.append(player1[0])
|
||||
player1.append(player2[0])
|
||||
del(player1[0])
|
||||
del(player2[0])
|
||||
else:
|
||||
player2.append(player2[0])
|
||||
player2.append(player1[0])
|
||||
del(player1[0])
|
||||
del(player2[0])
|
||||
|
||||
if len(player1):
|
||||
winner = player1
|
||||
else:
|
||||
winner = player2
|
||||
|
||||
result = 0
|
||||
for i in range(len(winner)):
|
||||
result += (len(winner) - i ) * winner[i]
|
||||
|
||||
print(result)
|
53
22/input
Normal file
53
22/input
Normal file
|
@ -0,0 +1,53 @@
|
|||
Player 1:
|
||||
29
|
||||
21
|
||||
38
|
||||
30
|
||||
25
|
||||
7
|
||||
2
|
||||
36
|
||||
16
|
||||
44
|
||||
20
|
||||
12
|
||||
45
|
||||
4
|
||||
31
|
||||
34
|
||||
33
|
||||
42
|
||||
50
|
||||
14
|
||||
39
|
||||
37
|
||||
11
|
||||
43
|
||||
18
|
||||
|
||||
Player 2:
|
||||
32
|
||||
24
|
||||
10
|
||||
41
|
||||
13
|
||||
3
|
||||
6
|
||||
5
|
||||
9
|
||||
8
|
||||
48
|
||||
49
|
||||
46
|
||||
17
|
||||
22
|
||||
35
|
||||
1
|
||||
19
|
||||
23
|
||||
28
|
||||
40
|
||||
26
|
||||
47
|
||||
15
|
||||
27
|
Loading…
Add table
Reference in a new issue