advent-of-code-2024

My solutions to AoC 2024
Log | Files | Refs

commit 1c66b8395d9ad2fb312abfddcdb6968f5db793d4
parent 84cfbdb3d8ce96e8b91070e3ca11113167c361c6
Author: Lukas Henkel <lh@entf.net>
Date:   Sat,  7 Dec 2024 07:42:22 +0100

Inline some math

Diffstat:
Msrc/day-7.lisp | 13++++++++++---
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)))))))))