From c5d4b8066b6c4d58d0838b672c3c80bdc7af9aed Mon Sep 17 00:00:00 2001 From: Mika Suhonen Date: Mon, 5 Dec 2022 16:14:05 +0200 Subject: [PATCH] Second answer, horrible kludge --- 05/e.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/05/e.py b/05/e.py index 86355fc..76ac23c 100644 --- a/05/e.py +++ b/05/e.py @@ -19,6 +19,8 @@ for i in [1, 5, 9, 13, 17, 21, 25, 29, 33]: temp.append(stack_input[l][i]) stacks.append(temp) +stacks2 = [row[:] for row in stacks] + for move in moves: move = move.split(' ') amount = int(move[1]) @@ -30,9 +32,19 @@ for move in moves: moved = stacks[move_from-1].pop() stacks[move_to-1].append(moved) -res = '' + index = len(stacks2[move_from-1])-amount + tomove = stacks2[move_from-1][index:] + stacks2[move_from-1] = stacks2[move_from-1][:index] + stacks2[move_to-1].extend(tomove) +res = '' for stack in stacks: res += stack[len(stack)-1] -print(res) +print("First answer: " + res) + +res2 = '' +for stack in stacks2: + res2 += stack[len(stack)-1] + +print("Second answer: " + res2)