Abelian sandpiles
Created on May 19, 2020 by Julien Palard
Simulate gravity applied to a sandpile.
Write a function apply_gravity
that given a 2D numpy array representing
sand will "apply gravity" on it (and returns nothing):
- Each element of the array is an integer representing the height of the sandpile
- Any "pile" that has 4 or more sand particles on it collapses, resulting in four particles being subtracted from the pile and distributed among its neighbors.
Example
1 2 3 4 5 6 7 8 9 10 |
|
Resources
https://en.wikipedia.org/wiki/Abelian_sandpile_model
Bonus on your machine (not tested by Hackinscience)
Use matplotlib to display the result as an image:
1 2 3 |
|
To showcase the results, computed a pile of 2 ** 26 grains of sand.