One-dimensional cellular automata: Difference between revisions

Content added Content deleted
(→‎{{header|D}}: Add Déjà Vu example)
(→‎{{header|Perl 6}}: slightly shorter + joining output)
Line 2,360: Line 2,360:
=={{header|Perl 6}}==
=={{header|Perl 6}}==


{{works with|Rakudo Star|2010.08}}
{{works with|Rakudo Star|2012.11}}


Short though it is, this solution even detects stability. Z+ is a zip metaop with addition,
Short though it is, this solution even detects stability. Z+ is a zip metaop with addition,
and X== is a cross metaop with equality. (Crossing with a scalar always producing a list of the same length.) We have taken the slight liberty of defining a wraparound universe, but it doesn't matter for this example.
and X== is a cross metaop with equality. (Crossing with a scalar always producing a list of the same length.) We have taken the slight liberty of defining a wraparound universe, but it doesn't matter for this example.
<lang perl6>my @c = <_ #>;
<lang perl6>my @c = <_ #>;
my @array = '_###_##_#_#_#_#__#__'.comb.map: { $_ eq '#' };
my @array = '_###_##_#_#_#_#__#__'.comb »eq» '#';


repeat until @array eqv my @prev {
repeat until @array eqv my @prev {
say @c[@prev = @array];
say @c[@prev = @array].join;
@array = ((@array Z+ @array.rotate(1)) Z+ @array.rotate(-1)) X== 2;
@array = ((@array Z+ @array.rotate(1)) Z+ @array.rotate(-1)) X== 2;
}</lang>
}</lang>