Challenge #10

Part One:
When Rocks Go Viral

At long last, you arrive at the Grand Temple of Eos with Captain Xarlos and the rest of the crew. The sight of the 1000 golems is an awesome and terrifying sight to behold. They are large and mean; certainly a considerable force to take on. Hopefully Admiral Grace Hopper's pumpkin purée will work as intended and the number of golems you have to take on will be reduced.

You've brought a small booklet that you've obtained from the reliquary. It's a user manual for these golems, covering everything from feeding, cleaning, to the spread of disease. "Bingo!" Grace says, grinning as she snatches the booklet and begins flipping pages. "This is everything we need." She launches into explanation mode immediately.

"We analyze this using a SIR model: Susceptible, Infected, and Removed. Any healthy golem is Susceptible, meaning it can become infected if it comes into contact with the virus. Once Infected, a golem continues its patrol as normal, spreading the infection to others. After a certain period, it transitions to Removed." She pauses, then adds, "They don't vanish or anything. But let's just say they're no longer a problem," punctuating the thought with a grim choking gesture.

"To track how many golems fall into each category over time," Grace continues, "we'll need a system of Ordinary Differential Equations (ODEs)."

"Unlike living guards, the golems patrol with mechanical precision. Their movements advance in tiny synchronized intervals, like the ticking of a clock. To mirror that behavior, we need to update the simulation every 1 second." At each 1-second interval, you calculate the current rates of change for the susceptible, infected, and removed populations. These rates are treated as constant for the given interval and used to estimate the populations at the next step. Once the populations have been updated, the rates are recalculated again.

Fortunately, the golems move in fixed patterns and interact with one another predictably. That allows the infection and removal rates to be treated as constants. What Grace was missing were the actual values. Fortunately, the booklet, your puzzle input, provides them:

"The safest approach," Grace says, lowering her voice, "is to infect exactly one golem. Any more than that, and we risk getting noticed." She gestures toward the patrol routes. "These things don't miss much."

The plan is simple. Hide among the temple vines. Smear the pumpkin purée onto a single passing golem. Then wait.
That gives you your initial conditions: S = 999, I = 1, R = 0.

Luckily, the infected golems are easy to identify because they emit a faint orange glow as the infection takes hold. To make sure your model is working correctly, you'll need to predict how many golems are infected after 𝑡 = 8500 seconds.

These calculations are estimations, so your final answer should be rounded to a whole number. (Values <.5 round down, and values ≥.5 round up.)

For example:

Suppose the user manual provides the following values:

beta = 0.9
gamma = 0.2

and starting with 1 golem infected out of a total of 10, you begin with the following conditions:

 time Susceptible  Infected  Removed 
0910

Using Euler's method to approximate the solution of the ODEs, you get the following values for each second (𝑡) from 0 through 5.
※ Because Euler's method approximates the solution numerically, S + I + R may differ slightly from 10.

 time Susceptible  Infected  Removed 
09.01.00.0
18.191.610.2
27.00332.47470.522
35.44353.53961.0169
43.70944.56581.7249
52.18515.17692.638

Shown on a graph, it looks like this:

The number infected after 𝑡 = 5 seconds is 5.1769, which you can round to 5.

Here is your user manual: