Day 5 completed (and a log to showcase pretty_print)
This commit is contained in:
26
day5/part1.py
Normal file
26
day5/part1.py
Normal file
@@ -0,0 +1,26 @@
|
||||
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]}")
|
||||
for i in range(operation[0]):
|
||||
num = stacks[operation[1] - 1].pop()
|
||||
stacks[operation[2] - 1].append(num)
|
||||
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()
|
||||
Reference in New Issue
Block a user