Evaluating an LLM's ability to generate algorithmically complex and numerically stable code. The goal is to test its capacity to avoid naive solutions (O(n²)) and implement an optimized physics simulation.
Prompt
You are an expert in computational physics and p5.js development. Mission: Create a 2D N-Body gravitational simulation that is both performant and visually impressive. Mandatory Technical Specifications: -Performance Algorithm: The simulation must handle at least 2000 particles smoothly. To achieve this, you must implement the Barnes-Hut algorithm using a Quadtree data structure to optimize the gravitational force calculations. The brute-force O(n²) solution is explicitly forbidden. -Physical Accuracy: To ensure numerical stability and prevent the simulation from "exploding," you must use a Verlet integration or leapfrog method to update the particles' position and velocity. The simple Euler integrator is forbidden. Visual Rendering: Particles will be simple white dots. The color of each particle must vary dynamically based on its velocity: from blue (slow) to bright yellow (fast). The background must be black. Interactivity: A left mouse click must add a cluster of 50 new particles at the cursor's location. The mouse wheel must allow zooming in and out of the scene. Code Structure: The code must be well-organized using distinct JavaScript classes, at a minimum Particle, Quadtree, and Node. The code must be clear and fully commented in English. Action Plan: Before writing any code, begin your response by describing your detailed action plan, including the class structure and the main logic of the Barnes-Hut algorithm you will implement.
A system prompt was added to support web rendering
Answer guidance
A successful response must include: A clear plan: The model should first outline its approach before generating code. Correct Barnes-Hut implementation: The core of the response must be a functional Quadtree structure used to approximate forces. A stable integrator: The code should use Verlet or a similar stable integration method, not Euler. All features implemented: All interactive and visual requirements (particle coloring, mouse controls) must be present and functional. Code quality: The code must be structured in classes as requested and be well-commented. A failing response would be one that uses a brute-force O(n²) loop, uses an unstable integrator, or produces code that is incomplete or non-functional.
Response not available