Move memoize to the Aoc library.

This commit is contained in:
2024-12-19 11:53:59 +00:00
parent 4f963e0f98
commit aaa031e6c6
3 changed files with 17 additions and 15 deletions

View File

@@ -90,3 +90,11 @@ let pow10 n =
let rec impl acc = function 0 -> acc | x -> impl (acc * 10) (x - 1) in
assert (n >= 0);
impl 1 n
let memoize memo f value =
match Hashtbl.find_opt memo value with
| Some x -> x
| None ->
let x = f value in
Hashtbl.add memo value x;
x