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