39 lines
1004 B
Plaintext
39 lines
1004 B
Plaintext
func rule110_step[state: Array] : Array
|
|
let new_state: Array = []
|
|
let state_len: I64 = array.size(state)
|
|
|
|
for i in 0..state_len
|
|
let left: Bool = false
|
|
if i - 1 >= 0
|
|
left = array.nth(state, i - 1)
|
|
let center: Bool = array.nth(state, i)
|
|
let right: Bool = false
|
|
if i + 1 < state_len
|
|
right = array.nth(state, i + 1)
|
|
|
|
array.push(new_state, !((!left & !center & !right) | (left & !center & !right) | (left & center & right)))
|
|
|
|
return new_state
|
|
|
|
func print_state[state: Array]: Void
|
|
for i in 0..array.size(state)
|
|
if array.nth(state, i)
|
|
io.print_char('#')
|
|
else
|
|
io.print_char(' ')
|
|
io.println("")
|
|
|
|
func main[] : I64
|
|
let SIZE: I64 = 60
|
|
|
|
let state: Array = []
|
|
for i in 0..SIZE
|
|
array.push(state, false)
|
|
array.push(state, true)
|
|
|
|
print_state(state)
|
|
for i in 0..SIZE
|
|
state = rule110_step(state)
|
|
print_state(state)
|
|
|
|
array.free(state) |