Code tidy up for 2024 day 21.

This commit is contained in:
2024-12-21 16:18:45 +00:00
parent 50420e84c4
commit 7debbf7acb
3 changed files with 68 additions and 96 deletions

View File

@@ -99,3 +99,5 @@ let memoize memo f value =
let x = f value in
Hashtbl.add memo value x;
x
let rec apply_n n fn arg = if n <= 0 then arg else apply_n (n - 1) fn (fn arg)

View File

@@ -35,6 +35,10 @@ val memoize : ('a, 'b) Hashtbl.t -> ('a -> 'b) -> 'a -> 'b
is used to cache results, so repeated calls with the same [value] will not
call [f] again. *)
val apply_n : int -> ('a -> 'a) -> 'a -> 'a
(** [apply_n n fn arg] is equivalent to [(fn (fn ... (fn (fn arg))))] where [fn]
is called [n] times.*)
(** Module representing a pair of integers, useful for Set.Make *)
module IntPair : sig
type t = int * int