diff options
author | Oscar Najera <hi@oscarnajera.com> | 2022-12-13 19:49:57 +0100 |
---|---|---|
committer | Oscar Najera <hi@oscarnajera.com> | 2022-12-13 19:49:57 +0100 |
commit | 1a6b1ab083956a2ecc99b7fac3e51d8a1f0f0db5 (patch) | |
tree | b124d0f683d0263de0d469cfe81ad904577194fb /AoC2022 | |
parent | 5e2eaabb759ee78c981925e83bbddfb574880f89 (diff) | |
download | scratch-1a6b1ab083956a2ecc99b7fac3e51d8a1f0f0db5.tar.gz scratch-1a6b1ab083956a2ecc99b7fac3e51d8a1f0f0db5.tar.bz2 scratch-1a6b1ab083956a2ecc99b7fac3e51d8a1f0f0db5.zip |
cl cleanup
Diffstat (limited to 'AoC2022')
-rw-r--r-- | AoC2022/08/solver.lisp | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/AoC2022/08/solver.lisp b/AoC2022/08/solver.lisp index 3cab1c0..32d9977 100644 --- a/AoC2022/08/solver.lisp +++ b/AoC2022/08/solver.lisp @@ -6,26 +6,18 @@ (< -1 y height)) (+ x (* y width))))) -(defun coord-y-minor (width height) - (let ((xminor (coord-x-minor width height))) - (lambda (y x) - (funcall xminor x y)))) - -(defun flatten-data (data) - (apply #'vector - (mapcan (lambda (row) - (map 'list (lambda (x) (- (char-code x) 48)) row)) data))) - (defun forest (data) (let ((width (length (car data))) (height (length data))) - (values (flatten-data data) width height))) + (values width height + (map 'vector + (lambda (x) (- (char-code x) 48)) + (apply #'concatenate 'string data))))) (defun solver-p1 (filename) - (multiple-value-bind (forest-arr width height) (forest (uiop:read-file-lines filename)) + (multiple-value-bind (width height forest-arr) (forest (uiop:read-file-lines filename)) (let ((visibility-mask (make-array (* width height) :initial-element nil)) - (location-x (coord-x-minor width height)) - (location-y (coord-y-minor width height))) + (location-x (coord-x-minor width height))) (flet ((toggle-visibility (major minor location reverse) (let ((range (if reverse (loop for i downfrom (1- minor) to 0 collect i) @@ -36,15 +28,16 @@ for maxh = -1 then (max maxh tree-height) for tree-height = (aref forest-arr (funcall location n m)) when (> tree-height maxh) - do (setf (aref visibility-mask (funcall location n m)) t)))))) + do (setf (aref visibility-mask (funcall location n m)) t))))) + (location-y (y x) (funcall location-x x y))) (toggle-visibility height width location-x nil) (toggle-visibility height width location-x t) - (toggle-visibility width height location-y nil) - (toggle-visibility width height location-y t)) + (toggle-visibility width height #'location-y nil) + (toggle-visibility width height #'location-y t)) (loop for v across visibility-mask counting v)))) (defun solver-p2 (filename) - (multiple-value-bind (forest-arr width height) (forest (uiop:read-file-lines filename)) + (multiple-value-bind (width height forest-arr) (forest (uiop:read-file-lines filename)) (let ((score (make-array (* width height))) (location-x (coord-x-minor width height))) |