Jump to content

One-dimensional cellular automata: Difference between revisions

→‎{{header|Perl 6}}: slightly shorter + joining output
(→‎{{header|D}}: Add Déjà Vu example)
(→‎{{header|Perl 6}}: slightly shorter + joining output)
Line 2,360:
=={{header|Perl 6}}==
 
{{works with|Rakudo Star|20102012.0811}}
 
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.
<lang perl6>my @c = <_ #>;
my @array = '_###_##_#_#_#_#__#__'.comb.map: { $_ »eq» '#' };
 
repeat until @array eqv my @prev {
say @c[@prev = @array].join;
@array = ((@array Z+ @array.rotate(1)) Z+ @array.rotate(-1)) X== 2;
}</lang>
1,934

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.