Elementary cellular automaton/Random number generator: Difference between revisions
Elementary cellular automaton/Random number generator (view source)
Revision as of 23:05, 3 April 2018
, 6 years ago→{{header|Perl 6}}: Include referenced class to make runnable file
No edit summary |
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Include referenced class to make runnable file) |
||
Line 268:
=={{header|Perl 6}}==
<lang perl6>
has $.rule;
has @.cells;
has @.code = $!rule.fmt('%08b').flip.comb».Int;
method gist { "|{ @!cells.map({+$_ ?? '#' !! ' '}).join }|" }
method succ {
self.new: :$!rule, :@!code, :cells(
@!code[
4 «*« @!cells.rotate(-1)
»+« 2 «*« @!cells
»+« @!cells.rotate(1)
]
)
}
}
my Automaton $a .= new: :rule(30), :cells( flat 1, 0 xx 100 );
say :2[$a++.cells[0] xx 8] xx 10;</lang>
|