Skip to content
Snippets Groups Projects
Commit 4c94d4dd authored by erwan's avatar erwan
Browse files

test: (re-) add the wolfram-cellular-automaton (was sierpinski)

parent 17151687
No related branches found
No related tags found
No related merge requests found
Pipeline #142964 passed with warnings
# Time-stamp: <modified the 03/07/2023 (at 16:22) by Erwan Jahier>
DECO_PATTERN="0-:p.ml"
-include ./Makefile.dot
-include ./Makefile.inc
##############################################################################
# Non-regression tests
test: chain10.gm_test chain10.rdbg-test demo50 clean
# update golden-master tests (if necessary)
utest:
make chain10.ugm_test || echo "chain10 ok"
# usage: make demo50
demo%:
make chain$*.dot
sasa chain$*.dot --synchronous-daemon --length $(shell echo $$(( $* / 2 ))) \
| grep outs | cut -d ' ' -f 2-$* \
| sed -e "s/ //g" | sed -e "s/f/ /g" | sed -e "s/t/▲/g"
clean: genclean
rm -f chain*
../Makefile.dot
\ No newline at end of file
../Makefile.inc
\ No newline at end of file
let potential = None (* None => only -sd, -cd, -lcd, -dd, or -custd are possible *)
let legitimate = None (* None => only silent configuration are legitimate *)
let fault = None (* None => the simulation stop once a legitimate configuration is reached *)
let init_search_utils = None (* To provide to use --init-search *)
../dune2copy
\ No newline at end of file
../dune-project2copy
\ No newline at end of file
(* Time-stamp: <modified the 10/07/2023 (at 11:36) by Erwan Jahier> *)
(* Draw the Sierpinski triangle using Wolfram cellular automata
https://mathworld.wolfram.com/ElementaryCellularAutomaton.html
*)
let rule_nb = 126 (* Sierpinski rule *)
let _ = assert( 0 <= rule_nb && rule_nb <256 )
let rec to_bool_list n = if n = 0 then [] else (n mod 2 = 1)::(to_bool_list (n/2))
let to_array l =
let a = Array.make 8 false in
let ll = List.length l in
List.iteri (fun i b -> a.(i+8-ll) <- b) l; a
let rule_nb_array = rule_nb |> to_bool_list |> List.rev |> to_array
(* For each rule, the next value (of x2) depends its value and the ones of its 2 neighbors *)
let b2i b = if b then 1 else 0
let next x1 x2 x3 =
let index = 7 - ((b2i x1)*4 + (b2i x2)*2 + b2i x3) in
(* Printf.printf "index=%d\n%!" index; *)
rule_nb_array.(index)
let cpt = ref 0
let init_state _ _ =
cpt := (!cpt+1) mod Algo.card();
let res = !cpt = Algo.card() / 2 in (* one cell is true, in the middle *)
(* Printf.printf "cell(%d)=%b\n%!" !cpt res; *)
res
let enable_f x2 nl =
match List.map Algo.state nl with
| [x1; x3] -> if next x1 x2 x3 = not x2 then ["flip"] else []
| _ -> []
let step_f x _ _ = not x
graph ring {
p1 [algo="p.ml"]
p2 [algo="p.ml"]
p3 [algo="p.ml"]
p4 [algo="p.ml"]
p5 [algo="p.ml"]
p6 [algo="p.ml"]
p7 [algo="p.ml"]
p1 -- p2 -- p3 -- p4 -- p5 -- p6 -- p7 -- p1
}
n
n
n
n
wait 3
print_event !e;;
type t = bool
let to_string = (fun s -> Printf.sprintf "%B" s)
let of_string = Some bool_of_string
let copy x = x
let actions = ["flip"]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment