Advent of Code 2024 - Day 22

Hello, Erlang problem-solvers! :monkey::sparkles: Today’s challenge takes us deep into the jungle, where the Monkey Exchange Market is bustling with activity. The task involves decoding pseudorandom sequences generated by mischievous monkeys to strategically trade hiding spots for bananas.

The goal: Simulate the evolution of secret numbers across 2000 iterations for each buyer and predict their final values.

Key Steps for Tackling Day 22

  • Mix and Prune Logic: Implement the bitwise XOR for mixing and the modulo operation for pruning secret numbers.
  • Iterative Simulation: Efficiently simulate the sequence of secret numbers for each buyer up to the 2000th iteration.
  • Parallelization: Consider leveraging Erlang’s concurrency features to compute sequences for multiple buyers simultaneously.

Example Approach

Use Erlang’s powerful bitwise and modulo operations to replicate the monkey buyers’ logic, iterating through the transformations and tracking the results.

:bulb: Pro Tip
Write clear functions for each transformation step to simplify debugging and reusability. Testing against smaller inputs will help validate your approach before scaling up.

:sparkles: Motivation for today
Even the cheekiest monkey cannot outsmart an Erlanger! Decode, strategize, and claim victory in the market.

Share your solutions, thoughts, or challenges below. Whether you’re bananas about pseudorandom sequences or just getting started, let’s collaborate and crack this puzzle together! :banana::computer:

Happy coding, and may your bananas always multiply! :christmas_tree::paw_prints:

The combined runtime for both parts is 2.5 seconds.

I did consider computing the sequences in separate processes. That made it almost a second slower. The reason is probably that each seller process must send back a lot of data to the main process.

1 Like