summaryrefslogtreecommitdiff
path: root/2022/day05.py
diff options
context:
space:
mode:
Diffstat (limited to '2022/day05.py')
-rwxr-xr-x2022/day05.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/2022/day05.py b/2022/day05.py
new file mode 100755
index 0000000..b93cc78
--- /dev/null
+++ b/2022/day05.py
@@ -0,0 +1,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)
+