From a6d6b45d4b553e09bd6d75450fd69c7153523e28 Mon Sep 17 00:00:00 2001 From: kwout Date: Sat, 2 Dec 2023 12:04:08 -0500 Subject: [PATCH] 2022 5b solved --- 2022/5.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/2022/5.py b/2022/5.py index f2fe207..2640e89 100644 --- a/2022/5.py +++ b/2022/5.py @@ -1,3 +1,5 @@ +from copy import deepcopy + data = open("input.txt", 'r').read() stacks, instructions = data.split("\n\n") @@ -12,9 +14,17 @@ for i in range(int(stacks[-1][-2])): if crate != " ": s[i].append(crate) +s2 = deepcopy(s) + for i in instructions: - for j in range(int(i[1])): - s[int(i[5])-1].append(s[int(i[3])-1].pop()) + destination = int(i[5])-1 + origin = int(i[3])-1 + quantity = int(i[1]) + s2[destination] += s2[origin][-quantity:] + for j in range(quantity): + s[destination].append(s[origin].pop()) + s2[origin].pop() -print("".join([t.pop() for t in s])) \ No newline at end of file +print("".join([t.pop() for t in s])) +print("".join([t.pop() for t in s2])) \ No newline at end of file