From 1a6b1ab083956a2ecc99b7fac3e51d8a1f0f0db5 Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Tue, 13 Dec 2022 19:49:57 +0100 Subject: cl cleanup --- AoC2022/08/solver.lisp | 29 +++++++++++------------------ 1 file 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))) -- cgit v1.2.3