RosettaCodeData/Task/Percolation-Bond-percolation/00-TASK.txt

26 lines
1.8 KiB
Plaintext

{{Percolation Simulation}}
Given an <math>M \times N</math> rectangular array of cells numbered <math>\mathrm{cell}[0..M-1, 0..N-1]</math>, assume <math>M</math> is horizontal and <math>N</math> is downwards. Each <math>\mathrm{cell}[m, n]</math> is bounded by (horizontal) walls <math>\mathrm{hwall}[m, n]</math> and <math>\mathrm{hwall}[m+1, n]</math>; (vertical) walls <math>\mathrm{vwall}[m, n]</math> and <math>\mathrm{vwall}[m, n+1]</math>
Assume that the probability of any wall being present is a constant <math>p</math> where
: <math>0.0 \le p \le 1.0</math>
Except for the outer horizontal walls at <math>m = 0</math> and <math>m = M</math> which are always present.
;The task:
Simulate pouring a fluid onto the top surface (<math>n = 0</math>) where the fluid will enter any empty cell it is adjacent to if there is no wall between where it currently is and the cell on the other side of the (missing) wall.
The fluid does not move beyond the horizontal constraints of the grid.
The fluid may move “up” within the confines of the grid of cells. If the fluid reaches a bottom cell that has a missing bottom wall then the fluid can be said to 'drip' out the bottom at that point.
Given <math>p</math> repeat the percolation <math>t</math> times to estimate the proportion of times that the fluid can percolate to the bottom for any given <math>p</math>.
Show how the probability of percolating through the random grid changes with <math>p</math> going from <math>0.0</math> to <math>1.0</math> in <math>0.1</math> increments and with the number of repetitions to estimate the fraction at any given <math>p</math> as <math>t = 100</math>.
Use an <math>M=10, N=10</math> grid of cells for all cases.
Optionally depict fluid successfully percolating through a grid graphically.
Show all output on this page.
<br><br>