Percolation/Mean cluster density: Difference between revisions

Content added Content deleted
(Added Kotlin)
m (→‎{{header|Kotlin}}: Minor adjustments including removal of superfluous whitespace)
Line 721: Line 721:


fun makeMap(p: Double) {
fun makeMap(p: Double) {
val thresh = (p * RAND_MAX).toInt()
val thresh = (p * RAND_MAX).toInt()
ww = w * w
ww = w * w
var i = ww
var i = ww
Line 737: Line 737:
val s = map[k++]
val s = map[k++]
val c = if (s < ALEN) ALPHA[1 + s] else '?'
val c = if (s < ALEN) ALPHA[1 + s] else '?'
print(" $c")
print(" $c")
}
}
println()
println()
Line 765: Line 765:
var k = 0.0
var k = 0.0
for (i in 0 until n) {
for (i in 0 until n) {
makeMap(p)
makeMap(p)
k += countClusters().toDouble() / ww
k += countClusters().toDouble() / ww
}
}
Line 778: Line 778:
showCluster()
showCluster()


println("\np = 0.5, iter = 5:")
println("\np = 0.5, iter = 5:")
w = 1 shl 2
w = 1 shl 2
while (w <= 1 shl 13) {
while (w <= 1 shl 13) {
Line 787: Line 787:
}</lang>
}</lang>


Sample output:
{{out}}
<pre>
<pre>
width = 15, p = 0.5, 23 clusters:
width = 15, p = 0.5, 23 clusters: