Part 1
In this puzzle, we are again given pseudoassembly to execute. This time, there is a new opcode for outputting a value. We are asked to find the input which results in a specific output: alternating 0 and 1 in an infinite loop.
Since the pseudoassembly is the same as in day 23, we can copy the code from before. The new opcode is implemented by a new register out. Instead of checking for an infinite loop, we break after we got 20 values in our output register and check these:
def check_if_alternating(s):
if s.count(0) + s.count(1) != len(s):
return False
if s[0] == 1:
return False
for a, b in zip(s, s[1:]):
if a == b:
return False
return True
Part 2
No part 2 for the last day, so were are done for 2016.
Extra
The program we are executing computes the binary for (input + some constant). This output is repeated in an infinite loop.
No comments:
Post a Comment