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