7 / 7
Dec 2022

I really enjoyed today’s puzzle! Observations / hints / spoilers:

  • The example does not cover all the cases you need to check in Part 2. Interestingly, the input is relatively small if you look at it right, so even though I got Part 2 wrong the first time, it didn’t take me long to work through the example and find my mistake.
  • In part 1,
  • In part 2,

4 days left!!!

The only issue I had with switching from test to real input was, that I tried to calculate all monkey’s values. That lead to overflow even after changing the value type to Long_Long_Integer. When changing it to only calculate needed values for the root monkey, it worked in an instant.

This time, Hashed_Maps was easy to use with the String(1…4) keys. Used a Vector for the queue while calculating.

Run time is small enough to call it near-instant event with both parts.

Interesting! I tried from the start simply to calculate root’s values. I guess there must be more than one tree in the puzzle input, because no monkey depends on root, and if root depended on the monkeys whose values overflow, we’d have a problem!

Nice to have an easier one! I had the same issue of having to switch from Integer to Long_Integer for the second part, but no problems there otherwise.

Part 1

Part 2

Hmm, I believe I needed a longer integer already on the first part, where my answer was 110181395003396.

Also, I just realized that there’s an implicit assumption that each monkey informs only one other monkey. That is, only one monkey is listening for humn’s number, and only one other monkey is listening for that monkey’s number, etc.

For Part 2, I did something quite different from you:

Implemented by turning the data into an Ada function, plus a little edition for the root and humn cases.
See the transformed example below.
For part 1, call the function, with part => part_1;
for part 2, find a zero of the function, with part => part_2.
To find the zero,

Total run time for both parts:
0.32 seconds with HAC,
0.0021 seconds with GNAT.

Neat idea, embedding the monkeys as assignment statements in your code!


Want to read more? Browse other topics in Advent of Code or view latest topics.

Powered by Discourse