commit 3311bc2c2ab44d0aa19ca977e2e2715ae6969f2f from: Lukas Henkel date: Fri Dec 20 18:57:51 2024 UTC Optimizations commit - bc03c52ea7e3331698d0639a1ebee50b38e88e2e commit + 3311bc2c2ab44d0aa19ca977e2e2715ae6969f2f blob - eee65c5dd9a1a6560f80c4e73d7c4f1d519fec7d blob + a7c96b311575ae7317750f2b650687979b2366cc --- src/day-20.lisp +++ 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)) blob - 8d9cb790806b0b4492d45670206eaaa30475b759 blob + be66e9605bf005fc2c9f1c6a8b45b4a2062376a7 --- src/utils.lisp +++ 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)))