advent-of-code-2024

My solutions to AoC 2024
Log | Files | Refs

commit 3311bc2c2ab44d0aa19ca977e2e2715ae6969f2f
parent bc03c52ea7e3331698d0639a1ebee50b38e88e2e
Author: Lukas Henkel <lh@entf.net>
Date:   Fri, 20 Dec 2024 19:57:51 +0100

Optimizations

Diffstat:
Msrc/day-20.lisp | 8++++----
Msrc/utils.lisp | 7++++++-
2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/day-20.lisp b/src/day-20.lisp @@ -27,12 +27,12 @@ with pos = start with last = nil with steps = nil - with task-1 = 0 - with task-2 = 0 - for picoseconds from 0 + with task-1 fixnum = 0 + with task-2 fixnum = 0 + for picoseconds fixnum from 0 do (loop for (pos-2 . picoseconds-2) in steps for distance = (manhattan-distance pos pos-2) - for saved = (- picoseconds (+ picoseconds-2 distance)) + for saved fixnum = (- picoseconds (+ (the fixnum picoseconds-2) distance)) do (when (>= saved 100) (when (<= distance 2) (incf task-1)) diff --git a/src/utils.lisp b/src/utils.lisp @@ -188,9 +188,11 @@ (the fixnum (mod (point-y point-a) (point-y point-divisor))))) -(declaim (inline point-in-bounds-p point-in-map-p)) +(declaim (ftype (function (cons fixnum fixnum) boolean) point-in-bounds-p) + (inline point-in-bounds-p point-in-map-p)) (defun point-in-bounds-p (point width height) (destructuring-bind (x . y) point + (declare (type fixnum x y)) (and (>= x 0) (>= y 0) (< x width) (< y height)))) @@ -228,6 +230,9 @@ (mapcar (curry #'point+ point) *map-neighbours*)) +(declaim (ftype (function (cons cons) fixnum) manhattan-distance) + (inline manhattan-distance)) + (defun manhattan-distance (from to) (+ (abs (- (point-x to) (point-x from)))