commit 1af7fd644bbac6ad0c08078a59d37b095fbeca10
parent dfca954de59ae6453cfc4e6aa21316dbe790a432
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)))))))))