Anonymous user
Percolation/Mean cluster density: Difference between revisions
m
→{{header|Tcl}}: Some notes, less obfuscated code
(→Tcl: Added implementation) |
m (→{{header|Tcl}}: Some notes, less obfuscated code) |
||
Line 480:
=={{header|Tcl}}==
Note that the queue (variables <code>q</code> and <code>k</code>) used to remember where to find cells when flood-filling the cluster is maintained as a list ''segment''; the front of the list is not trimmed for performance reasons. (This would matter with very long queues, in which case the queue could be shortened occasionally; ''frequent'' trimming is still slower though, because Tcl backs its “list” datatype with arrays and not linked lists.)
{{works with|Tcl|8.6}}
<lang tcl>package require Tcl 8.6
Line 497 ⟶ 498:
if {[lindex $grid $i $j] == -1} {
incr cl
for {set q [list $i $j];set k
set y [lindex $q
set x [lindex $q [incr k]]
if {[lindex $grid $y $x] != -1} continue
|