40 lines
925 B
Plaintext
40 lines
925 B
Plaintext
func rule110_step[state: Array] : void
|
|
new_state := []
|
|
|
|
for i in 0..state->size
|
|
left := false
|
|
if i - 1 >= 0
|
|
left = state->nth(i - 1)
|
|
center : bool = state->nth(i)
|
|
right := false
|
|
if i + 1 < state->size
|
|
right = state->nth(i + 1)
|
|
|
|
new_state->push(!((!left && !center && !right) || (left && !center && !right) || (left && center && right)))
|
|
|
|
mem.copy(new_state->data, state->data, state->size * 8)
|
|
new_state->free()
|
|
|
|
func print_state[state: Array]: void
|
|
for i in 0..state->size
|
|
if state->nth(i)
|
|
io.print_char('#')
|
|
else
|
|
io.print_char(' ')
|
|
io.println("")
|
|
|
|
func main[] : i64
|
|
SIZE := 60
|
|
|
|
state := []
|
|
for i in 0..SIZE
|
|
state->push(false)
|
|
state->push(true)
|
|
|
|
print_state(state)
|
|
for i in 0..SIZE
|
|
rule110_step(state)
|
|
print_state(state)
|
|
|
|
state->free()
|