aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2022-12-05 07:05:49 +0100
committerMarvin Borner2022-12-05 07:23:58 +0100
commitd5f822bcad063435ac1a48f0a0dae41a9b155d73 (patch)
treefb9452289c7de4f5b3c0570f261a4d59501bcc93
parente0dc4f150a95c78bbc129ac5fda00db710f9072f (diff)
i don't like cranes
-rw-r--r--2022/05/input511
-rw-r--r--2022/05/solve.py35
2 files changed, 546 insertions, 0 deletions
diff --git a/2022/05/input b/2022/05/input
new file mode 100644
index 0000000..2d46420
--- /dev/null
+++ b/2022/05/input
@@ -0,0 +1,511 @@
+[T] [V] [W]
+[V] [C] [P] [D] [B]
+[J] [P] [R] [N] [B] [Z]
+[W] [Q] [D] [M] [T] [L] [T]
+[N] [J] [H] [B] [P] [T] [P] [L]
+[R] [D] [F] [P] [R] [P] [R] [S] [G]
+[M] [W] [J] [R] [V] [B] [J] [C] [S]
+[S] [B] [B] [F] [H] [C] [B] [N] [L]
+ 1 2 3 4 5 6 7 8 9
+
+move 7 from 3 to 9
+move 6 from 2 to 1
+move 2 from 4 to 8
+move 10 from 8 to 4
+move 1 from 2 to 4
+move 15 from 4 to 1
+move 28 from 1 to 3
+move 1 from 2 to 5
+move 7 from 5 to 9
+move 5 from 9 to 5
+move 21 from 3 to 1
+move 1 from 6 to 4
+move 4 from 9 to 2
+move 7 from 9 to 2
+move 4 from 2 to 6
+move 1 from 9 to 1
+move 2 from 4 to 9
+move 2 from 7 to 4
+move 4 from 3 to 5
+move 2 from 7 to 9
+move 5 from 2 to 7
+move 2 from 9 to 1
+move 1 from 9 to 2
+move 3 from 3 to 7
+move 3 from 5 to 2
+move 2 from 6 to 1
+move 1 from 9 to 4
+move 25 from 1 to 9
+move 2 from 5 to 3
+move 1 from 1 to 7
+move 9 from 7 to 1
+move 1 from 2 to 8
+move 16 from 9 to 7
+move 5 from 9 to 5
+move 7 from 1 to 8
+move 1 from 9 to 7
+move 18 from 7 to 4
+move 1 from 3 to 4
+move 1 from 1 to 8
+move 2 from 8 to 1
+move 1 from 3 to 9
+move 17 from 4 to 5
+move 5 from 8 to 6
+move 2 from 8 to 1
+move 6 from 6 to 7
+move 2 from 9 to 4
+move 5 from 1 to 3
+move 3 from 3 to 7
+move 1 from 1 to 2
+move 2 from 3 to 8
+move 2 from 4 to 1
+move 2 from 8 to 7
+move 2 from 9 to 7
+move 1 from 2 to 4
+move 1 from 2 to 4
+move 2 from 1 to 7
+move 11 from 7 to 1
+move 4 from 4 to 1
+move 3 from 1 to 3
+move 7 from 1 to 8
+move 4 from 2 to 8
+move 2 from 1 to 4
+move 2 from 4 to 3
+move 2 from 1 to 3
+move 3 from 7 to 4
+move 4 from 8 to 6
+move 1 from 7 to 5
+move 2 from 4 to 1
+move 4 from 6 to 2
+move 3 from 1 to 8
+move 6 from 8 to 6
+move 1 from 2 to 1
+move 23 from 5 to 8
+move 21 from 8 to 3
+move 2 from 6 to 9
+move 1 from 8 to 9
+move 2 from 3 to 7
+move 26 from 3 to 8
+move 2 from 9 to 2
+move 8 from 6 to 3
+move 3 from 5 to 4
+move 1 from 7 to 4
+move 1 from 7 to 9
+move 1 from 5 to 4
+move 5 from 2 to 9
+move 7 from 9 to 8
+move 38 from 8 to 7
+move 1 from 1 to 7
+move 1 from 4 to 9
+move 3 from 4 to 1
+move 4 from 3 to 2
+move 1 from 1 to 7
+move 34 from 7 to 6
+move 3 from 4 to 7
+move 1 from 4 to 2
+move 2 from 1 to 3
+move 1 from 2 to 9
+move 5 from 3 to 6
+move 1 from 4 to 6
+move 4 from 2 to 6
+move 1 from 9 to 5
+move 4 from 7 to 3
+move 1 from 5 to 9
+move 1 from 9 to 1
+move 1 from 3 to 6
+move 1 from 9 to 3
+move 5 from 7 to 9
+move 1 from 1 to 9
+move 3 from 9 to 1
+move 1 from 3 to 4
+move 38 from 6 to 1
+move 2 from 9 to 4
+move 3 from 3 to 6
+move 1 from 9 to 5
+move 8 from 6 to 8
+move 1 from 3 to 6
+move 1 from 6 to 8
+move 2 from 4 to 3
+move 4 from 8 to 5
+move 1 from 6 to 2
+move 1 from 2 to 7
+move 1 from 6 to 3
+move 3 from 8 to 7
+move 4 from 7 to 6
+move 1 from 4 to 1
+move 5 from 1 to 4
+move 4 from 6 to 5
+move 3 from 5 to 8
+move 3 from 5 to 3
+move 1 from 8 to 2
+move 6 from 3 to 8
+move 1 from 5 to 7
+move 1 from 2 to 1
+move 1 from 7 to 6
+move 3 from 4 to 9
+move 6 from 8 to 6
+move 3 from 8 to 2
+move 3 from 6 to 2
+move 1 from 4 to 5
+move 1 from 6 to 9
+move 2 from 6 to 1
+move 1 from 4 to 1
+move 2 from 5 to 2
+move 1 from 8 to 5
+move 1 from 9 to 8
+move 22 from 1 to 5
+move 3 from 2 to 3
+move 1 from 8 to 4
+move 2 from 3 to 6
+move 1 from 6 to 4
+move 1 from 3 to 8
+move 1 from 2 to 8
+move 10 from 5 to 3
+move 1 from 6 to 8
+move 2 from 8 to 4
+move 1 from 6 to 3
+move 2 from 2 to 3
+move 1 from 8 to 5
+move 13 from 3 to 4
+move 2 from 1 to 7
+move 11 from 1 to 2
+move 3 from 4 to 5
+move 6 from 1 to 9
+move 8 from 2 to 6
+move 4 from 2 to 1
+move 2 from 6 to 5
+move 4 from 1 to 8
+move 2 from 8 to 6
+move 1 from 7 to 1
+move 1 from 7 to 2
+move 8 from 6 to 5
+move 1 from 8 to 4
+move 1 from 1 to 6
+move 10 from 5 to 1
+move 3 from 9 to 4
+move 6 from 1 to 3
+move 9 from 4 to 5
+move 1 from 2 to 1
+move 1 from 4 to 9
+move 1 from 6 to 8
+move 1 from 2 to 1
+move 1 from 4 to 8
+move 2 from 8 to 9
+move 1 from 8 to 6
+move 1 from 3 to 2
+move 1 from 1 to 4
+move 1 from 2 to 5
+move 1 from 1 to 8
+move 1 from 6 to 8
+move 8 from 5 to 3
+move 1 from 8 to 7
+move 1 from 7 to 8
+move 6 from 9 to 6
+move 2 from 9 to 2
+move 1 from 9 to 7
+move 1 from 8 to 5
+move 1 from 2 to 7
+move 1 from 2 to 9
+move 16 from 5 to 2
+move 4 from 5 to 1
+move 12 from 3 to 6
+move 1 from 5 to 4
+move 8 from 6 to 9
+move 1 from 8 to 5
+move 2 from 9 to 6
+move 2 from 2 to 5
+move 3 from 1 to 4
+move 3 from 6 to 7
+move 7 from 9 to 6
+move 4 from 7 to 1
+move 1 from 5 to 2
+move 1 from 3 to 2
+move 4 from 1 to 9
+move 4 from 9 to 5
+move 12 from 6 to 7
+move 4 from 2 to 6
+move 4 from 2 to 9
+move 7 from 6 to 3
+move 3 from 9 to 8
+move 5 from 2 to 4
+move 4 from 5 to 7
+move 1 from 9 to 4
+move 13 from 7 to 8
+move 3 from 7 to 8
+move 2 from 3 to 2
+move 5 from 1 to 5
+move 11 from 4 to 9
+move 7 from 9 to 1
+move 4 from 4 to 3
+move 1 from 6 to 8
+move 8 from 8 to 4
+move 1 from 1 to 7
+move 3 from 4 to 6
+move 4 from 2 to 8
+move 3 from 5 to 4
+move 1 from 4 to 1
+move 4 from 9 to 8
+move 3 from 5 to 2
+move 2 from 2 to 3
+move 1 from 6 to 7
+move 7 from 1 to 9
+move 3 from 7 to 4
+move 1 from 4 to 2
+move 1 from 6 to 8
+move 1 from 5 to 7
+move 1 from 6 to 7
+move 9 from 4 to 6
+move 7 from 9 to 5
+move 1 from 4 to 3
+move 1 from 5 to 6
+move 4 from 3 to 7
+move 3 from 3 to 1
+move 2 from 2 to 4
+move 3 from 1 to 6
+move 4 from 5 to 1
+move 2 from 5 to 3
+move 3 from 6 to 8
+move 6 from 7 to 3
+move 10 from 3 to 7
+move 10 from 6 to 4
+move 3 from 1 to 9
+move 4 from 7 to 2
+move 2 from 3 to 5
+move 1 from 3 to 5
+move 1 from 1 to 2
+move 3 from 9 to 1
+move 2 from 1 to 9
+move 4 from 2 to 5
+move 10 from 4 to 9
+move 2 from 8 to 7
+move 1 from 2 to 9
+move 1 from 9 to 4
+move 1 from 1 to 9
+move 3 from 7 to 8
+move 5 from 9 to 8
+move 6 from 5 to 4
+move 5 from 9 to 6
+move 5 from 8 to 5
+move 4 from 5 to 2
+move 3 from 7 to 8
+move 3 from 9 to 1
+move 2 from 5 to 8
+move 1 from 4 to 6
+move 3 from 6 to 3
+move 8 from 4 to 3
+move 2 from 6 to 7
+move 24 from 8 to 9
+move 1 from 6 to 9
+move 8 from 9 to 3
+move 1 from 1 to 9
+move 2 from 8 to 3
+move 3 from 9 to 4
+move 18 from 3 to 5
+move 1 from 2 to 6
+move 1 from 6 to 1
+move 13 from 9 to 8
+move 3 from 4 to 1
+move 1 from 4 to 2
+move 1 from 5 to 3
+move 1 from 9 to 2
+move 6 from 2 to 9
+move 3 from 3 to 1
+move 3 from 7 to 6
+move 2 from 1 to 5
+move 3 from 6 to 7
+move 17 from 8 to 1
+move 8 from 5 to 7
+move 11 from 7 to 5
+move 1 from 4 to 5
+move 24 from 1 to 3
+move 7 from 5 to 9
+move 11 from 5 to 9
+move 1 from 5 to 4
+move 1 from 5 to 2
+move 1 from 4 to 7
+move 16 from 3 to 1
+move 3 from 5 to 8
+move 1 from 9 to 1
+move 12 from 9 to 2
+move 5 from 3 to 1
+move 2 from 8 to 5
+move 2 from 3 to 4
+move 1 from 8 to 6
+move 2 from 5 to 3
+move 1 from 6 to 1
+move 2 from 4 to 1
+move 8 from 2 to 1
+move 24 from 1 to 6
+move 1 from 9 to 6
+move 4 from 2 to 6
+move 4 from 3 to 2
+move 4 from 9 to 4
+move 1 from 7 to 5
+move 6 from 9 to 1
+move 17 from 6 to 4
+move 1 from 1 to 9
+move 2 from 9 to 7
+move 9 from 6 to 7
+move 12 from 7 to 2
+move 11 from 1 to 2
+move 12 from 4 to 2
+move 1 from 1 to 4
+move 1 from 5 to 7
+move 2 from 6 to 3
+move 2 from 4 to 3
+move 1 from 1 to 6
+move 5 from 4 to 2
+move 1 from 7 to 5
+move 2 from 6 to 9
+move 6 from 2 to 4
+move 1 from 5 to 8
+move 3 from 4 to 1
+move 1 from 8 to 9
+move 5 from 4 to 1
+move 1 from 1 to 2
+move 1 from 3 to 8
+move 7 from 1 to 6
+move 1 from 8 to 6
+move 1 from 3 to 5
+move 1 from 1 to 8
+move 1 from 4 to 5
+move 2 from 5 to 9
+move 1 from 8 to 2
+move 2 from 6 to 8
+move 1 from 8 to 6
+move 1 from 6 to 8
+move 1 from 8 to 5
+move 4 from 9 to 5
+move 1 from 9 to 6
+move 1 from 6 to 8
+move 37 from 2 to 5
+move 1 from 2 to 8
+move 37 from 5 to 8
+move 21 from 8 to 4
+move 1 from 3 to 7
+move 12 from 4 to 1
+move 1 from 7 to 8
+move 4 from 6 to 3
+move 1 from 4 to 2
+move 2 from 2 to 6
+move 2 from 3 to 2
+move 2 from 2 to 7
+move 2 from 7 to 1
+move 3 from 5 to 3
+move 2 from 2 to 8
+move 15 from 8 to 7
+move 1 from 7 to 2
+move 2 from 5 to 8
+move 5 from 4 to 3
+move 3 from 6 to 2
+move 8 from 1 to 9
+move 8 from 9 to 4
+move 7 from 8 to 9
+move 2 from 8 to 5
+move 4 from 1 to 9
+move 10 from 3 to 2
+move 1 from 6 to 7
+move 6 from 7 to 8
+move 10 from 4 to 7
+move 1 from 3 to 7
+move 3 from 9 to 1
+move 5 from 8 to 1
+move 5 from 2 to 7
+move 1 from 4 to 3
+move 1 from 5 to 6
+move 10 from 1 to 7
+move 34 from 7 to 4
+move 1 from 6 to 9
+move 1 from 7 to 3
+move 8 from 4 to 2
+move 1 from 9 to 7
+move 1 from 7 to 9
+move 22 from 4 to 5
+move 1 from 3 to 8
+move 6 from 5 to 6
+move 1 from 8 to 4
+move 9 from 9 to 4
+move 1 from 3 to 2
+move 4 from 2 to 1
+move 11 from 2 to 6
+move 14 from 4 to 7
+move 1 from 2 to 1
+move 12 from 5 to 6
+move 7 from 7 to 9
+move 2 from 5 to 4
+move 1 from 8 to 5
+move 6 from 6 to 8
+move 3 from 7 to 8
+move 1 from 2 to 6
+move 2 from 4 to 3
+move 1 from 3 to 8
+move 1 from 2 to 5
+move 1 from 3 to 4
+move 5 from 8 to 9
+move 5 from 1 to 4
+move 3 from 8 to 9
+move 5 from 4 to 7
+move 18 from 6 to 3
+move 2 from 8 to 9
+move 3 from 6 to 3
+move 5 from 7 to 1
+move 1 from 6 to 7
+move 3 from 9 to 7
+move 6 from 7 to 8
+move 8 from 9 to 8
+move 1 from 7 to 6
+move 12 from 3 to 1
+move 2 from 9 to 7
+move 1 from 8 to 6
+move 9 from 8 to 9
+move 2 from 8 to 7
+move 1 from 7 to 8
+move 2 from 1 to 6
+move 7 from 1 to 9
+move 16 from 9 to 5
+move 4 from 3 to 9
+move 8 from 1 to 3
+move 5 from 5 to 1
+move 1 from 4 to 3
+move 4 from 7 to 6
+move 3 from 8 to 2
+move 8 from 3 to 2
+move 11 from 2 to 7
+move 3 from 6 to 1
+move 4 from 3 to 6
+move 12 from 5 to 7
+move 2 from 3 to 6
+move 7 from 1 to 7
+move 2 from 5 to 1
+move 1 from 9 to 2
+move 1 from 5 to 7
+move 31 from 7 to 4
+move 6 from 9 to 1
+move 6 from 4 to 7
+move 16 from 4 to 5
+move 1 from 9 to 4
+move 1 from 7 to 6
+move 4 from 4 to 1
+move 11 from 5 to 9
+move 2 from 5 to 6
+move 1 from 2 to 9
+move 4 from 5 to 1
+move 8 from 9 to 2
+move 12 from 6 to 5
+move 11 from 5 to 1
+move 18 from 1 to 2
+move 3 from 4 to 3
+move 2 from 6 to 7
+move 2 from 9 to 1
+move 1 from 5 to 9
+move 3 from 9 to 5
+move 13 from 2 to 8
+move 10 from 8 to 2
+move 3 from 8 to 6
+move 3 from 3 to 9
+move 7 from 1 to 5
+move 6 from 5 to 6
+move 3 from 1 to 2
+move 5 from 7 to 8
+move 13 from 2 to 8
+move 9 from 6 to 3
diff --git a/2022/05/solve.py b/2022/05/solve.py
new file mode 100644
index 0000000..8997d4e
--- /dev/null
+++ b/2022/05/solve.py
@@ -0,0 +1,35 @@
+data = [dat for dat in open("input").readlines() if dat != '']
+
+def solve(mover_version):
+ # lists >> stacks hehe
+ stacks = [[] for i in range(len(data[0]) // 4)]
+
+ start = True
+ for line in data:
+ if start:
+ if line[0] == '\n':
+ start = False
+ continue
+
+ cols = line.strip()
+ i = 1
+ while i < len(cols):
+ if cols[i-1] == '[':
+ stacks[i // 4].insert(0, cols[i])
+ i += 4
+ else:
+ proc = line.replace("move ", "").replace("from ", "").replace("to ", "").replace("target ", "").split(" ")
+ what = int(proc[0])
+ source = int(proc[1]) - 1
+ target = int(proc[2]) - 1
+
+ crates = stacks[source][-what:]
+ if mover_version == 9000:
+ crates = crates[::-1]
+ stacks[target] += crates
+ stacks[source] = stacks[source][:-what]
+
+ print(f"Part {'1' if mover_version == 9000 else '2'}: {''.join([stack[-1] for stack in stacks if len(stack) > 0])}")
+
+solve(9000)
+solve(9001)