Files
zern/examples/rule110.zr
2025-07-26 13:21:37 +02:00

38 lines
988 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 to_str[state: Array]: String
let out: String = malloc(array.size(state))
for i in 0..array.size(state)
if state[i]
str.set(out, i, '#')
else
str.set(out, i, ' ')
return out
func main[] : I64
let SIZE: I64 = 60
let state: Array = []
for i in 0..SIZE
array.push(state, false)
array.push(state, true)
io.print(to_str(state))
for i in 0..SIZE
state = rule110_step(state)
io.print(to_str(state))