diff options
| -rw-r--r-- | 2025/ocaml/lib/application/d02p02.ml | 13 | ||||
| -rw-r--r-- | 2025/ocaml/lib/domain/d02p02.ml | 2 |
2 files changed, 5 insertions, 10 deletions
diff --git a/2025/ocaml/lib/application/d02p02.ml b/2025/ocaml/lib/application/d02p02.ml index 26cf109..c936b28 100644 --- a/2025/ocaml/lib/application/d02p02.ml +++ b/2025/ocaml/lib/application/d02p02.ml @@ -19,15 +19,10 @@ let collect_all = List.concat_map (fun range -> Range.collect range) let pp_collection = List.iter (fun c -> Logs.debug (fun m -> m "%s" (ID.pp c))) -(** [rules] is a list of rules that [ID]s must pass to be considered invalid. *) -let rules = - [ (fun id -> String.length (ID.to_string id) mod 2 = 0) - ; (fun id -> - let id' = ID.to_string id in - let id_len = String.length id' in - let left = String.sub id' 0 (id_len / 2) in - let right = String.sub id' (id_len / 2) (id_len / 2) in - String.equal left right ) ] +(** [rules] is a list of rules that denotes any ID returning true from ANY as invalid. *) +let rules = [ + (** a subset of the digits of the whole number up to len/2 is equal to segments of equal length of the remaining string *) +] (** [is_invalid id] is [true] for an [id] that passes all of the rules and is considered invalid. *) let is_invalid = ID.validate rules diff --git a/2025/ocaml/lib/domain/d02p02.ml b/2025/ocaml/lib/domain/d02p02.ml index 725d4b1..d1624b6 100644 --- a/2025/ocaml/lib/domain/d02p02.ml +++ b/2025/ocaml/lib/domain/d02p02.ml @@ -4,7 +4,7 @@ module ID = struct let create num = num - let validate rules id = List.fold_left (fun acc r -> acc && r id) true rules + let validate rules id = List.fold_left (fun acc r -> acc || r id) false rules let incr = ( + ) 1 |
