mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
20 lines
629 B
OCaml
20 lines
629 B
OCaml
|
|
(** Display the graph of the collatz conjecture, starting from the given int *)
|
|
|
|
let g = LazyGraph.map
|
|
~edges:(fun () -> [])
|
|
~vertices:(fun i -> [`Label (string_of_int i)])
|
|
LazyGraph.collatz_graph
|
|
|
|
let collatz n filename =
|
|
Format.printf "print graph to %s@." filename;
|
|
let out = open_out filename in
|
|
let fmt = Format.formatter_of_out_channel out in
|
|
LazyGraph.Dot.pp ~name:"collatz" g fmt (Enum.singleton n);
|
|
Format.pp_print_flush fmt ();
|
|
close_out out
|
|
|
|
let _ =
|
|
if Array.length Sys.argv < 3
|
|
then (Format.printf "use: collatz num file@."; exit 0)
|
|
else collatz (int_of_string Sys.argv.(1)) Sys.argv.(2)
|