Part 1
In this puzzle we have a series of conditional instructions and have to execute them. Each follows a similar format: increase or decrease a register if some comparison is true. We should execute the program and report the highest value of any register after the program ends.
Since the program does not contain loops, we can iterate the lines from start to finish. We do not know the number or names of registers at the beginning, so we used a defaultdict setting every register to 0 as default. During the execution, we first parse the line via regex. The rest was straight foreward, and we return the highest value at the end.
Part 2
In part 2, we should return the highest value of a register at any point.
We reuse the code from part 1 and introduce a variable keeping track of the highest value until now. This was sufficient to solve this problem.
No comments:
Post a Comment