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))
|
||||||
5
test.zr
5
test.zr
@@ -1,5 +1,4 @@
|
|||||||
func run_test[x: String] : I64
|
func run_test[x: String] : I64
|
||||||
// TODO: escape sequences
|
|
||||||
printf("\033[93mBuilding %s...\033[0m", x)
|
printf("\033[93mBuilding %s...\033[0m", x)
|
||||||
let cmd: String = concat("./target/release/zern examples/", x)
|
let cmd: String = concat("./target/release/zern examples/", x)
|
||||||
|
|
||||||
@@ -23,6 +22,4 @@ func main[] : I64
|
|||||||
|
|
||||||
let files: Array = OS.listdir("examples/")
|
let files: Array = OS.listdir("examples/")
|
||||||
for i in 0:Array.size(files)
|
for i in 0:Array.size(files)
|
||||||
let file: String = Array.nth(files, i)
|
run_test(Array.nth(files, i))
|
||||||
run_test(file)
|
|
||||||
free(file)
|
|
||||||
Reference in New Issue
Block a user