Percolation/Mean cluster density: Difference between revisions

m
J: fix explanation to match code
(→‎{{header|Tcl}}: added zkl)
m (J: fix explanation to match code)
Line 429:
=={{header|J}}==
 
The first thing this task seems to need is some mechanism of identifying "clusters", using "percolation". We can achieve this by assigning every "1" in a matrix a unique integer value and then defining an operation which combines two numbers - doing nothing unless boththe aresecond one (the one on the right) is non-zero. If they areit bothis non-zero we pick the larger of the two values. <code>(*@[ * >.)</code>
 
Once we have this, we can identify clusters by propagating information in a single direction through the matrix using this operation, rotating the matrix 90 degrees, and then repeating this combination of operations four times. And, finally, by keeping at this until there's nothing more to be done.
6,962

edits