Percolation/Site percolation: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Adds trial numbers) |
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Fix some white space issues) |
||
Line 1,024: | Line 1,024: | ||
sub direction([$x,$y]) { |
sub direction([$x,$y]) { |
||
my @neighbors = |
|||
(Down if @site[$y + 1][$x] deq $pore), |
|||
(Left if @site[$y][$x - 1] deq $pore), |
|||
(Right if @site[$y][$x + 1] deq $pore), |
|||
(Up if @site[$y - 1][$x] deq $pore); |
(Up if @site[$y - 1][$x] deq $pore); |
||
@neighbors.shift or DeadEnd |
|||
} |
} |
||
sub move ($dir, @cur) { |
sub move ($dir, @cur) { |
||
my ($x,$y) = @cur; |
|||
given $dir { |
|||
when Up { @site[--$y][$x] = $water } |
|||
when Down { @site[++$y][$x] = $water } |
|||
when Left { @site[$y][--$x] = $water } |
|||
when Right { @site[$y][++$x] = $water } |
|||
} |
|||
} |
|||
[$x,$y]; |
|||
} |
} |
||
}</lang> |
}</lang> |