One-dimensional cellular automata: Difference between revisions
Content added Content deleted
(→{{header|Oz}}: add Perl 6 entry) |
|||
Line 1,231: | Line 1,231: | ||
Gen. 9: __##________________ |
Gen. 9: __##________________ |
||
</pre> |
</pre> |
||
=={{header|Perl 6}}== |
|||
{{works with|Rakudo Star|2010.08}} |
|||
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]; |
|||
@array = ((@array Z+ @array.rotate(1)) Z+ @array.rotate(-1)) X== 2; |
|||
}</lang> |
|||
Output: |
|||
<lang>_###_##_#_#_#_#__#__ |
|||
_#_#####_#_#_#______ |
|||
__##___##_#_#_______ |
|||
__##___###_#________ |
|||
__##___#_##_________ |
|||
__##____###_________ |
|||
__##____#_#_________ |
|||
__##_____#__________ |
|||
__##________________</lang> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |