summaryrefslogtreecommitdiff
path: root/2025/ocaml/lib/domain/d02p01.ml
diff options
context:
space:
mode:
authorDJ O'Leary <dijitol@proton.me>2025-12-03 03:31:23 +0100
committerDJ O'Leary <dijitol@proton.me>2025-12-03 03:31:23 +0100
commita2e648c2c7dc9bce7cd371b695f174181f9284dc (patch)
tree53632f095fc947f35a84427ba0c6e11158bc43ed /2025/ocaml/lib/domain/d02p01.ml
parent893440696a4f14f323e80c739e78fc9ee3bda8ea (diff)
feat(2025d2p1): solve day 2 part 1
Diffstat (limited to '2025/ocaml/lib/domain/d02p01.ml')
-rw-r--r--2025/ocaml/lib/domain/d02p01.ml33
1 files changed, 33 insertions, 0 deletions
diff --git a/2025/ocaml/lib/domain/d02p01.ml b/2025/ocaml/lib/domain/d02p01.ml
new file mode 100644
index 0000000..725d4b1
--- /dev/null
+++ b/2025/ocaml/lib/domain/d02p01.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