commit bfc7b808e5c96da582de3d72e273fd1cbee57686
parent 7cc8e9d818053d66ee14d8f381d953ace100a7f0
Author: Lukas Henkel <lh@entf.net>
Date: Sat, 7 Dec 2024 07:42:22 +0100
Inline some math
Diffstat:
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/day-7.lisp b/src/day-7.lisp
@@ -3,24 +3,31 @@
(:export #:day-7))
(in-package #:aoc/day-7)
+(declaim (inline number-digits combine)
+ (ftype (function (fixnum) fixnum) number-digits)
+ (ftype (function (fixnum fixnum) fixnum) combine))
+
(defun number-digits (number)
(if (zerop number)
1
(1+ (floor (log number 10)))))
(defun combine (num-1 num-2)
- (+ (* num-1 (expt 10 (number-digits num-2))) num-2))
+ (+ (the fixnum (* num-1
+ (the fixnum (expt 10 (number-digits num-2)))))
+ num-2))
(defun test-value-valid-p (test-value numbers &optional combine-op)
(labels ((%solve (test-value numbers combine-op current)
+ (declare (type fixnum current test-value))
(if (null numbers)
(= current test-value)
(if (> current test-value)
nil
(or (%solve test-value (cdr numbers) combine-op
- (+ current (car numbers)))
+ (+ current (the fixnum (car numbers))))
(%solve test-value (cdr numbers) combine-op
- (* current (car numbers)))
+ (* current (the fixnum (car numbers))))
(and combine-op
(%solve test-value (cdr numbers) combine-op
(combine current (car numbers)))))))))