Percolation/Bond percolation: Difference between revisions

Content added Content deleted
(→‎{{header|Perl 6}}: Add Perl 6 example)
m (→‎{{header|Perl 6}}: Minor code tweaks)
Line 588:
my $grid = 10;
my $geom = $grid - 1;
my $prob;
my $water = '▒';
 
Line 633 ⟶ 632:
my ( $x, $y ) = @cur;
given $dir {
when Up { fill([$x,--$y]);.&fill fill([$x,--$y])xx 2 }
when Down { fill([$x,++$y]);.&fill fill([$x,++$y])xx 2 }
when Left { fill([--$x,$y]);.&fill fill([--$x,$y])xx 2 }
when Right { fill([++$x,$y]);.&fill fill([++$x,$y])xx 2 }
}
[$x, $y]
Line 648 ⟶ 647:
my $sp = ' ';
append @bond, [flat '│', ($sp, ' ') xx $geom, $sp, '│'],
[flat '├', (h(), '┬') xx $geom, h(), '┤'];
append @bond, [flat '│', ($sp, v()) xx $geom, $sp, '│'],
[flat '├', (h(), '┼') xx $geom, h(), '┤'] for ^$geom;
append @bond, [flat '│', ($sp, v()) xx $geom, $sp, '│'],
[flat '├', (h(), '┴') xx $geom, h(), '┤'],
[flat '│', ($sp, ' ') xx $geom, $sp, '│'];
 
sub h () { rand < $prob ?? $sp !! '───' }
sub v () { rand < $prob ?? ' ' !! '│' }
}</lang>
{{out}}