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):
>>> import numpy as np
>>> sandpile = np.zeros((5, 5), dtype=np.uint32)
>>> sandpile[2, 2] = 16
>>> apply_gravity(sandpile)
>>> print(sandpile)
[[0 0 1 0 0]
[0 2 1 2 0]
[1 1 0 1 1]
[0 2 1 2 0]
[0 0 1 0 0]]
https://en.wikipedia.org/wiki/Abelian_sandpile_model
Use matplotlib to display the result as an image:
apply_gravity(sandpile)
plt.imshow(sandpile)
plt.show()
To showcase the results, computed a pile of 2 ** 26 grains of sand.
There's no corrections yet, hit the `Submit` button to send your code to the correction bot.
Keyboard shortcuts: