summaryrefslogtreecommitdiff
path: root/2025/ocaml/lib/domain
diff options
context:
space:
mode:
Diffstat (limited to '2025/ocaml/lib/domain')
-rw-r--r--2025/ocaml/lib/domain/d02p02.ml33
-rw-r--r--2025/ocaml/lib/domain/d02p02.mli36
2 files changed, 69 insertions, 0 deletions
diff --git a/2025/ocaml/lib/domain/d02p02.ml b/2025/ocaml/lib/domain/d02p02.ml
new file mode 100644
index 0000000..725d4b1
--- /dev/null
+++ b/2025/ocaml/lib/domain/d02p02.ml
@@ -0,0 +1,33 @@
+module ID = struct
+ (** *)
+ type t = int
+
+ let create num = num
+
+ let validate rules id = List.fold_left (fun acc r -> acc && r id) true rules
+
+ let incr = ( + ) 1
+
+ let to_int id = id
+
+ let to_string = string_of_int
+
+ let pp id = "ID=" ^ string_of_int id
+end
+
+module Range = struct
+ type t = ID.t * ID.t
+
+ let create (id1, id2) = (ID.create id1, ID.create id2)
+
+ let rec collect range = collect_range_aux [] range
+
+ and collect_range_aux lst (id1, id2) =
+ match id1 <= id2 with
+ | false ->
+ lst
+ | true ->
+ collect_range_aux (id1 :: lst) (ID.incr id1, id2)
+
+ let pp (id1, id2) = "(L" ^ ID.pp id1 ^ ", R" ^ ID.pp id2 ^ ")"
+end
diff --git a/2025/ocaml/lib/domain/d02p02.mli b/2025/ocaml/lib/domain/d02p02.mli
new file mode 100644
index 0000000..55665fe
--- /dev/null
+++ b/2025/ocaml/lib/domain/d02p02.mli
@@ -0,0 +1,36 @@
+module ID : sig
+ (** [t] is a ID within a range *)
+ type t
+
+ val create : int -> t
+ (** [create num] is an ID [t] *)
+
+ val validate : (t -> bool) list -> t -> bool
+ (** [validate rules id] is [true] if the [id] passes all rule checks *)
+
+ val incr : t -> t
+ (** [incr id] is the next [id] in the sequence *)
+
+ val to_int : t -> int
+ (** [to_int id] is an integer representation of [id] *)
+
+ val to_string : t -> string
+ (** [to_string id] is an string representation of [id] *)
+
+ val pp : t -> string
+ (** [pp id] is a pretty string representing [id] *)
+end
+
+module Range : sig
+ (** [t] is a range of values *)
+ type t
+
+ val create : int * int -> t
+ (** [create (s, e)] is a range starting at [s] and ending at [e]. *)
+
+ val collect : t -> ID.t list
+ (** [collect r] is a list containing all elements within the range (inclusive). *)
+
+ val pp : t -> string
+ (** [pp r] is a pretty string representing [r] *)
+end