Percolation/Bond percolation: Difference between revisions

m
→‎{{header|Perl 6}}: Remove some superstitious parenthesis, minor code tweaks
m (→‎{{header|Perl 6}}: Minor code tweaks)
m (→‎{{header|Perl 6}}: Remove some superstitious parenthesis, minor code tweaks)
Line 593:
 
say 'Sample percolation at .6';
percolate( .6);
.join.say for @bond;
say "\n";
Line 603:
}
 
sub percolate ( $prob = .6 ) {
generate ( $prob );
my @stack;
my $current = [1;0];
Line 612:
if my $dir = direction( $current ) {
@stack.push: $current;
$current = move( $dir, $current )
}
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) }
}
 
10,333

edits