-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_5.py
34 lines (28 loc) · 1.14 KB
/
day_5.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
f = open("input.txt", "r")
stacks = ["TDWZVP", "LSWVFJD", "ZMLSVTBH",
"RSJ", "CZBGFMLW", "QWVHZRGB",
"VJPCBDN", "PTBQ", "HGZRC"]
stacks2 = ["TDWZVP", "LSWVFJD", "ZMLSVTBH",
"RSJ", "CZBGFMLW", "QWVHZRGB",
"VJPCBDN", "PTBQ", "HGZRC"]
def get_top(stacks):
return (stacks[0][-1] + stacks[1][-1]
+ stacks[2][-1] + stacks[3][-1]
+ stacks[4][-1] + stacks[5][-1]
+ stacks[6][-1] + stacks[7][-1] + stacks[8][-1])
nline = 1
for line in f.readlines():
if nline != 11:
nline += 1
continue
line = line.replace("move ", "").replace("from ", "").replace("to ", "").strip("\n").split(" ")
for i in range(0, int(line[0])):
stacks[int(line[2]) - 1] = stacks[int(line[2]) - 1] + stacks[int(line[1]) - 1][-1]
stacks[int(line[1]) - 1] = stacks[int(line[1]) - 1][0:-1]
stacks2[int(line[2]) - 1] = stacks2[int(line[2]) - 1] + stacks2[int(line[1]) - 1][-(int(line[0])):]
stacks2[int(line[1]) - 1] = stacks2[int(line[1]) - 1][0:-(int(line[0]))]
top = get_top(stacks)
top2 = get_top(stacks2)
print("part one: " + top)
print("part two: " + top2)
f.close()