Elementary cellular automaton: Difference between revisions
m
→{{header|Sidef}}: modified the code to work with Sidef 2.30
m (J: show a bit more) |
m (→{{header|Sidef}}: modified the code to work with Sidef 2.30) |
||
Line 1,503:
method init {
rule = sprintf("%08b", rule).
}
method next {
var previous = cells.map{_}
var len = previous.len
cells[] =
previous.range.map { |i|
4*previous[i-1 % len] +
Line 1,515:
previous[i+1 % len]
}
]
}
method to_s {
cells.map { _ ? '#' : ' ' }.join
}
}
var size = 20
var arr = size.of(0)
arr[size/2] = 1
var auto = Automaton(90, arr)
(size/2).times {
print "|#{auto}|\n"
auto.next
}</lang>
{{out}}
|