Percolation/Bond percolation: Difference between revisions
m
→{{header|Perl 6}}: Remove some superstitious parenthesis, minor code tweaks
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Minor code tweaks) |
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Remove some superstitious parenthesis, minor code tweaks) |
||
Line 593:
say 'Sample percolation at .6';
percolate
.join.say for @bond;
say "\n";
Line 603:
}
sub percolate ( $prob
generate
my @stack;
my $current = [1;0];
Line 612:
if my $dir = direction( $current ) {
@stack.push: $current;
$current = move
}
else {
Line 622:
sub direction( [$x, $y] ) {
( Down if @bond[$y + 1][$x].contains: ' ' ) ||
( Left if @bond[$y][$x - 1].contains: ' ' ) ||
( Right if @bond[$y][$x + 1].contains: ' ' ) ||
( Up if @bond[$y - 1][$x].defined && @bond[$y - 1][$x].contains: ' ' ) ||
DeadEnd
}
Line 640:
}
sub fill ( [$x, $y] ) { @bond[$y;$x].=subst(' ', $water, :g) }
}
|