Percolation/Mean cluster density: Difference between revisions

m
(added Mathematica solution)
Line 873:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>(*Calculate C_n / n^2 for n=1000, 2000, ..., 10 000*)
(*Calculate C_n / n^2 for n=1000, 2000, ..., 10 000*)
In[1]:= Table[N[Max@MorphologicalComponents[
RandomVariate[BernoulliDistribution[.5], {n, n}],
Line 884 ⟶ 883:
 
(*Show a 15x15 matrix with each cluster given an incrementally higher number, Colorize instead of MatrixForm creates an image*)
In[3]:= MorphologicalComponents[RandomChoice[{0, 1}, {15, 15}], CornerNeighbors -> False] // MatrixForm</lang>
</lang>
 
 
{{out}}
<pre>Out[1]= {0.066339, 0.06568, 0.0656282, 0.0658778, 0.0657444, 0.0658455, 0.06578, 0.0657307, 0.0658186, 0.0657963}
<pre>
Out[1]= {0.066339, 0.06568, 0.0656282, 0.0658778, 0.0657444, 0.0658455, 0.06578, 0.0657307, 0.0658186, 0.0657963}
Out[2]= 0.06582 +- 0.00006
Out[3]= (1 1 0 2 2 2 2 2 0 0 2 2 2 2 0
Line 906 ⟶ 903:
0 0 0 7 7 7 7 0 17 0 14 14 14 0 0
0 18 0 7 7 0 0 0 0 0 0 0 0 19 0
0 0 0 0 7 0 0 20 0 0 21 21 0 0 22)</pre>
</pre>
 
 
=={{header|Nim}}==
1,111

edits