From fcc4341237f47647b4347a0eb3ca74c6f5de88d9 Mon Sep 17 00:00:00 2001 From: Matthew Gretton-Dann Date: Wed, 11 Dec 2024 09:17:12 +0000 Subject: [PATCH] Update to use Aoc.pow10 and Aoc.digits10. --- bin/day2407.ml | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/bin/day2407.ml b/bin/day2407.ml index e8050c1..d4ab0cf 100644 --- a/bin/day2407.ml +++ b/bin/day2407.ml @@ -1,20 +1,6 @@ let ints_of_file fname = Aoc.strings_of_file fname |> List.map (Aoc.ints_of_string ~sep:"[: ]+") -(** [log10i i] returns the integer part of [log10 i]. [i] must be greater than - zero. *) -let log10i i = - let rec impl acc = function 0 -> acc | x -> impl (acc + 1) (x / 10) in - assert (i > 0); - impl ~-1 i - -(** [pow10 n] returns [10] raised to the [n]th power. [n] must be non-negative. -*) -let pow10 n = - let rec impl acc = function 0 -> acc | x -> impl (acc * 10) (x - 1) in - assert (n >= 0); - impl 1 n - (** [check_add tgt v] Check to see if [X + v = tgt] is a valid operation. If not returns [None] otherwise returns [Some X]. *) let check_add tgt v = if v > tgt then None else Some (tgt - v) @@ -26,7 +12,7 @@ let check_mul tgt v = if tgt mod v = 0 then Some (tgt / v) else None (** [check_cat tgt v] Check to see if [X || v = tgt] is a valid operation. If not returns [None] otherwise returns [Some X]. *) let check_cat tgt v = - let p = pow10 (1 + log10i v) in + let p = Aoc.pow10 (Aoc.digits10 v) in if tgt mod p = v then Some (tgt / p) else None (** [is_valid_target tgt nums ops] returns [true] if we can reach [tgt] from