-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
23 lines (17 loc) · 688 Bytes
/
main.py
File metadata and controls
23 lines (17 loc) · 688 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from copy import deepcopy
with open('input.txt') as file:
part1, part2 = [line.split('\n')[:-1] for line in file.read().split('\n\n')]
crates = [[j for j in i if j != ' '] for i in zip(*[list(line[1::4]) for line in reversed(part1)])]
def sol(rever):
crate_temp = deepcopy(crates)
for line in part2:
a, b = line.split(' from ')
c, d = [int(i) - 1 for i in b.split(' to ')]
r = [crate_temp[c].pop() for _ in range(int(a[5:]))]
if rever:
crate_temp[d].extend(reversed(r))
else:
crate_temp[d].extend(r)
return ''.join(i.pop() for i in crate_temp)
print(sol(False))
print(sol(True))