Peut-on tout programmer en OCaml?
Règle 110�:
Cellules 111 110 101 100 011 010 001 000
Nouveau centre 0 1 1 0 1 1 1 0
Exemple�:
00000001000
00000011000
00000111000
00001101000
00011111000
00110001000
Règle 110 en OCaml
type cell =T|F
let rule110 triple =match triple with
| (T,T,T) | (T,F,F) | (F,F,F) -> F
| _ -> T
let map3 f l =
let rec aux curl =match curl with
|a:: b:: c:: tl -> f(a,b,c) :: aux (b:: c:: tl)
| [a;b] -> [f(a,b,F)]
| _ -> assert false
in aux (F:: l)
let init = [F;F;F;F;F;F;F;F;F;F;F;F;F;F;F;F;F;F;F;F;F;F;F;F;T]
let rec loop n cur =
List.iter (fun F-> print_char ' ' |T-> print_char 'X')cur;
print_newline ();
if n< 20 then loop (n+1) (map3 rule110 cur)
let _ = loop 0init