One-dimensional cellular automata: Difference between revisions
m
→{{header|Julia}}
Line 3,031:
=={{header|Julia}}==
=== functional ===
<syntaxhighlight lang="julia">
automaton(g) =
struct Automaton g₀::BitVector end▼
for i ∈ 0:9
println(join(alive ? '#' : '_' for alive ∈ g))
g = ([false; g[1:end-1]] .+ g .+ [g[2:end]; false]) .== 2
end
automaton([c == '#' for c ∈ "_###_##_#_#_#_#__#__"])
</syntaxhighlight>
=== iterable struct ===
<syntaxhighlight lang="julia">
Base.iterate(a::Automaton, g = a.g₀) =
g,
Base.show(io::IO, a::Automaton) = for g in Iterators.take(a, 10)
|