rule110 exampel

This commit is contained in:
2025-06-03 14:21:30 +02:00
parent cebc3d1822
commit d8f2ff28db
2 changed files with 39 additions and 4 deletions

38
examples/rule110.zr Normal file
View 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))

View File

@@ -1,5 +1,4 @@
func run_test[x: String] : I64
// TODO: escape sequences
printf("\033[93mBuilding %s...\033[0m", x)
let cmd: String = concat("./target/release/zern examples/", x)
@@ -23,6 +22,4 @@ func main[] : I64
let files: Array = OS.listdir("examples/")
for i in 0:Array.size(files)
let file: String = Array.nth(files, i)
run_test(file)
free(file)
run_test(Array.nth(files, i))