Files
aoc/05/e.py
2022-12-05 12:08:21 +02:00

39 lines
772 B
Python

import os
input = open(os.path.dirname(__file__) +
"/input.txt", "r").read().split('\n\n')
stack_input = input[0].splitlines()
moves = input[1].splitlines()
stacks = []
stack_input.pop()
stack_input.reverse()
for i in [1, 5, 9, 13, 17, 21, 25, 29, 33]:
temp = []
for l in range(0, len(stack_input), 1):
if stack_input[l][i].isalpha():
temp.append(stack_input[l][i])
stacks.append(temp)
for move in moves:
move = move.split(' ')
amount = int(move[1])
move_from = int(move[3])
move_to = int(move[5])
i = 0
while (i < amount):
i += 1
moved = stacks[move_from-1].pop()
stacks[move_to-1].append(moved)
res = ''
for stack in stacks:
res += stack[len(stack)-1]
print(res)