One-dimensional cellular automata: Difference between revisions
Content added Content deleted
m (→{{header|Perl 6}}: precisions about the choice of the rule number.) |
m (→{{header|Perl 6}}: adding wp link and fixing indent) |
||
Line 2,360: | Line 2,360: | ||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
We'll make a general algorithm capable of computing any cellular automata as defined by Stephen Wolfram's famous book [[wp:A new kind of Science|A new kind of Science]]. The rule currently proposed for this task is rule 0b01101000 = 104 but it is not particularly interesting so instead we'll show the automata defined by rule n°90, which shows a [[wp:Sierpinski Triangle|Sierpinski Triangle]]-like figure. |
We'll make a general algorithm capable of computing any cellular automata as defined by [[wp:Stephen Wolfram|Stephen Wolfram]]'s famous book ''[[wp:A new kind of Science|A new kind of Science]]''. The rule currently proposed for this task is rule 0b01101000 = 104 but it is not particularly interesting so instead we'll show the automata defined by rule n°90, which shows a [[wp:Sierpinski Triangle|Sierpinski Triangle]]-like figure. |
||
<lang perl6>class Automata { |
<lang perl6>class Automata { |
||
Line 2,371: | Line 2,371: | ||
self.new: :$.code, :cells( |
self.new: :$.code, :cells( |
||
self.mapping{ |
self.mapping{ |
||
4 «*« @.cells.rotate(-1) |
4 «*« @.cells.rotate(-1) |
||
Z+ 2 «*« @.cells |
Z+ 2 «*« @.cells |
||
Z+ @.cells.rotate(1) |
Z+ @.cells.rotate(1) |