Five parts back to back, each one depending on your previous code being clean enough to extend.
Start by clarifying the problem scope and constraints, then design a modular simulation architecture that separates state representation, update rules, and metrics collection. Implement incrementally, validating each part with small test cases before adding complexity like immunity or barriers.
Pro tip: Emphasize extensibility: design the simulator so new rules (e.g., immunity, barriers) can be plugged in without rewriting core logic. This shows foresight and aligns with OpenAI's emphasis on scalable systems.
Ask questions to understand grid size, infection rules, time-step semantics, and expected outputs. Confirm whether the simulation is deterministic and how metrics should be reported.
Choose an efficient grid representation (e.g., 2D array) and define cell states (healthy, infected, immune, etc.). Plan how to track infection counts and peak statistics over time.
Write the time-step update logic: for each cell, apply spread rules based on neighbors, handle state transitions (infection, recovery, immunity), and update metrics. Ensure barriers are respected.
Implement functions to query infection counts at a given time, peak infection stats, and other required metrics. Consider precomputing or caching results for efficiency.
Create small test grids to verify spread logic, immunity, recovery, and barriers. Check performance for larger grids and discuss trade-offs (e.g., time vs. space).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.