Elementary cellular automaton: Difference between revisions
Content added Content deleted
m (→{{header|Java}}: move image) |
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Include referenced class to make runnable file) |
||
Line 1,267: | Line 1,267: | ||
Using the <tt>Automaton</tt> class defined at [[One-dimensional_cellular_automata#Perl_6]]: |
Using the <tt>Automaton</tt> class defined at [[One-dimensional_cellular_automata#Perl_6]]: |
||
<lang perl6> |
<lang perl6>class Automaton { |
||
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 @padding = 0 xx 10; |
|||
my Automaton $a .= new: |
my Automaton $a .= new: |