summaryrefslogtreecommitdiff
path: root/src/wallgen.ml
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2022-10-30 03:42:11 +1300
committerJedidiah Barber <contact@jedbarber.id.au>2022-10-30 03:42:11 +1300
commit95ebd2d6acfa744c5e93287cc6385f4f1359376e (patch)
tree87cea8951f3ef00b9ad53679c7fe70c208b0ec62 /src/wallgen.ml
parent3f290e0d6c3ef1435253095de2cf53016855840e (diff)
wallgen and wallsolve working, visualwall partially done, license added
Diffstat (limited to 'src/wallgen.ml')
-rw-r--r--src/wallgen.ml78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/wallgen.ml b/src/wallgen.ml
new file mode 100644
index 0000000..c27f0eb
--- /dev/null
+++ b/src/wallgen.ml
@@ -0,0 +1,78 @@
+
+
+(* Programmed by Jedidiah Barber *)
+(* Licensed under the Sunset License v1.0 *)
+
+
+let usage_msg = "Usage: wallgen [options]"
+let input_seq = ref (Array.make 0 (Z.of_int 0))
+let depth_limit = ref 20
+let use_random = ref false
+
+
+
+let anon_fun item =
+ prerr_endline "Error: Don't know what to do with anonymous argument";
+ exit 2
+
+
+
+let input_immediate items =
+ if Array.length !input_seq > 0
+ then (prerr_endline "Error: Multiple input sequences specified"; exit 2)
+ else try input_seq := Util.read_integer_list items
+ with Util.Not_an_integer s ->
+ prerr_endline ("Error: The argument '" ^ s ^ "' is not an integer");
+ exit 2
+
+let input_from_file filename =
+ if Array.length !input_seq > 0
+ then (prerr_endline "Error: Multiple input sequences specified"; exit 2)
+ else try input_seq := Util.read_sequence_file filename
+ with Util.Not_an_integer s ->
+ prerr_endline ("Error: The item '" ^ s ^ "' from file '" ^ filename ^ "' is not an integer");
+ exit 2
+
+let use_random len =
+ if Array.length !input_seq > 0
+ then (prerr_endline "Error: Multiple input sequences specified"; exit 2)
+ else input_seq := Sequence.random ~len
+
+
+
+let speclist =
+ [("-f", Arg.String input_from_file, "Read input integer sequence from file");
+ ("-i", Arg.String input_immediate, "Integer input sequence with values separated by commas");
+ ("-l", Arg.Set_int depth_limit, "Sets maximum levels to generate, default 20");
+ ("-r", Arg.Int use_random, "Use random input sequence of specified length")]
+
+
+
+module My_Algebra =
+ struct
+ type t = Z.t
+ let zero = Z.zero
+ let one = Z.one
+ let add = Z.add
+ let sub = Z.sub
+ let mul = Z.mul
+ let div = Z.div
+ let to_string = Z.to_string
+ end
+
+module My_Wall = Wall.Make (My_Algebra)
+
+
+
+let _ =
+ if Array.length Sys.argv <= 1 then (Arg.usage speclist usage_msg; exit 1);
+ Arg.parse speclist anon_fun usage_msg;
+ if Array.length !input_seq = 0 then (prerr_endline "Error: No input sequence provided"; exit 2);
+
+ let result = My_Wall.create
+ ~dimx:(Array.length !input_seq)
+ ~dimy:!depth_limit
+ ~init:!input_seq in
+ My_Wall.print result
+
+