28 lines
842 B
Python
28 lines
842 B
Python
from common import parse # , pretty_print
|
|
|
|
|
|
def move(stacks: list[list[str]], operation: tuple[int, int, int]) -> list[list[str]]:
|
|
# print(f"move {operation[0]} from {operation[1]} to {operation[2]}")
|
|
dst = operation[2] - 1
|
|
orig = operation[1] - 1
|
|
stacks[dst] += stacks[orig][len(stacks[orig]) - operation[0] : len(stacks[orig])]
|
|
stacks[orig] = stacks[orig][: len(stacks[orig]) - operation[0]]
|
|
return stacks
|
|
|
|
|
|
def solve(input: tuple[list[list[str]], list[tuple[int, int, int]]]) -> str:
|
|
stacks, operations = input
|
|
# pretty_print(stacks)
|
|
for operation in operations:
|
|
stacks = move(stacks, operation)
|
|
# pretty_print(stacks)
|
|
return "".join(map(lambda x: x[len(x) - 1] if len(x) != 0 else "", stacks))
|
|
|
|
|
|
def main():
|
|
print(solve(parse("input")))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|