Part 1
In this puzzle, we have several bots executing a simple function. Each takes two input values, compares them and sends the lower and higher to specific other bots. The configuration of each bot and some initial values are given as puzzle input. We are asked to find the number of the bot comparing two specific values.
We first parse the input into a list of bot configurations and the list of input values. We then iterate over all bots and check if they have two input values. If they do, we send the lower and higher values to other bots and reset the input to avoid checking the same bot multiple times. This iteration is repeated until no bot has valid input left. To solve part 1, we check for the specific input values each time a bot is active.
for bot_number in bot_ids:
values = inputs[bot_number]
if len(values) == 2:
low = min(values)
high = max(values)
if low == 17 and high == 61:
print("PART 1")
print(bot_number.split(" ")[1])
low_output, high_output = bots[bot_number]
inputs[low_output].append(low)
inputs[high_output].append(high)
inputs[bot_number] = []
Part 2
In part 2, we have the same bots, but now we are interested in the complete output. Several bots are named output and we should get the value of these bots.
We can reuse the functions from part 1 and read the output of the indivual bots at the end.
No comments:
Post a Comment