rule110 exampel
This commit is contained in:
38
examples/rule110.zr
Normal file
38
examples/rule110.zr
Normal file
@@ -0,0 +1,38 @@
|
||||
func rule110_step[state: Array] : Array
|
||||
let new_state: Array = Array.new()
|
||||
|
||||
for i in 0:Array.size(state)
|
||||
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 < Array.size(state)
|
||||
right = Array.nth(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
|
||||
// TODO: very leaky
|
||||
let o: String = ""
|
||||
for i in 0:Array.size(state)
|
||||
if Array.nth(state, i)
|
||||
o = concat(o, "#")
|
||||
else
|
||||
o = concat(o, " ")
|
||||
return o
|
||||
|
||||
func main[] : I64
|
||||
let SIZE: I64 = 60
|
||||
|
||||
let state: Array = Array.new()
|
||||
for i in 0:SIZE
|
||||
Array.push(state, false)
|
||||
Array.push(state, true)
|
||||
|
||||
print(to_str(state))
|
||||
for i in 0:SIZE
|
||||
state = rule110_step(state)
|
||||
print(to_str(state))
|
||||
Reference in New Issue
Block a user