blob: b93cc785f74b1d77f89f7a8b420fff67c301b255 (
plain)
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
|
#!/usr/bin/env python3
from functools import reduce
# filename = "in/day05_mod.ref"
filename = "in/day05_mod.pzl"
res1 = ''
res2 = ''
f = open(filename)
stacks1 = []
stacks2 = []
for line in f:
line = line.strip()
if line == '':
break
stack = []
for c in line:
stack.append(c)
stacks1.append(stack)
stacks2.append(stack)
# print(stacks1)
for line in f:
line = line.strip()
line = line.replace('move', '').replace('from ', '').replace('to ', '').strip()
mcount, mfrom, mto = [int(i) for i in line.split(' ')]
mfrom -= 1
mto -= 1
to_move = stacks1[mfrom][-mcount:]
stacks1[mfrom] = stacks1[mfrom][:-mcount]
stacks1[mto] = stacks1[mto] + to_move[::-1]
# print(stacks1)
to_move = stacks2[mfrom][-mcount:]
stacks2[mfrom] = stacks2[mfrom][:-mcount]
stacks2[mto] = stacks2[mto] + to_move
# print(stacks2)
f.close()
print(stacks1)
print(stacks2)
for i in stacks1:
res1 = res1 + i[-1]
print('res1:', res1)
for i in stacks2:
res2 = res2 + i[-1]
print('res2:', res2)
|