Day 5 completed (and a log to showcase pretty_print)

This commit is contained in:
2024-12-01 17:40:08 +01:00
parent 9e21d8d9c8
commit ae98a486a9
5 changed files with 12020 additions and 0 deletions

27
day5/part2.py Normal file
View File

@@ -0,0 +1,27 @@
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()