Files
zern/examples/rule110.zr
2025-07-29 18:53:38 +02:00

39 lines
946 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 = state[i-1]
let center: Bool = state[i]
let right: Bool = false
if i + 1 < state_len
right = 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 state[i]
c.putchar('#')
else
c.putchar(' ')
io.print("")
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)