Abelian sandpile model: Difference between revisions

m
Added output to Rust version along with a typo fix.
(Created page with "{{task}}{{wikipedia|Abelian sandpile model}} <br> Implement the '''Abelian sandpile model''' also known as '''Bak–Tang–Wiesenfeld model'''. It's history, mathematical defi...")
 
m (Added output to Rust version along with a typo fix.)
Line 5:
The task requires the creation of a 2D grid of arbitrary size on which "piles of sand" can be placed. Any "pile" that has 4 or more sand particles on it ''collapses'', resulting in '''four particles being subtracted from the pile''' and '''distributed among it's neighbors.'''
 
It is recommended to display the output in some kind of image format, as terminal emulators are usually too small to display images larger than a few dozen characters tall. As an example of how to accomplish this, see the [https://rosettacode.org/wiki/Bitmap/Write_a_PPM_file Bitmap/Write a PPM file] task.
 
'''Examples:'''
Line 131:
 
// We place this much sand in the center of the grid.
pile[DIM/2 - 1][DIM/2 - 1] = 102416;
 
// We start the algorithm on the pile we just created.
handle_pile(DIM/2 - 1, DIM/2 - 1, &mut pile);
 
// Uncomment this to show the final pile in the console after the recursive algorithm has ended.
//draw_pile(&pile)
write_piledraw_pile(&pile)
// Uncomment this to showsave the finalimage pileto ina the consolefile after the recursive algorithm has ended.
//draw_pilewrite_pile(&pile)
}).unwrap().join();
}</lang>
 
'''Output:'''
<pre>
▒░▒
░░ ░░
▒░▒
</pre>
Anonymous user