aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/08/solver.lisp
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2022-12-13 21:30:16 +0100
committerOscar Najera <hi@oscarnajera.com>2022-12-13 21:30:16 +0100
commit1a046690b59d9f1dc84ee078832e5acbe3450ac9 (patch)
treefda4dc6c135b87c0dff1846b30a43c3fdac989db /AoC2022/08/solver.lisp
parent7b4efed3226d20cb0a971060d43b4914c81fe9fa (diff)
downloadscratch-1a046690b59d9f1dc84ee078832e5acbe3450ac9.tar.gz
scratch-1a046690b59d9f1dc84ee078832e5acbe3450ac9.tar.bz2
scratch-1a046690b59d9f1dc84ee078832e5acbe3450ac9.zip
Documentation
Diffstat (limited to 'AoC2022/08/solver.lisp')
-rw-r--r--AoC2022/08/solver.lisp12
1 files changed, 6 insertions, 6 deletions
diff --git a/AoC2022/08/solver.lisp b/AoC2022/08/solver.lisp
index 3797589..f5a273f 100644
--- a/AoC2022/08/solver.lisp
+++ b/AoC2022/08/solver.lisp
@@ -18,26 +18,26 @@
(defun solver-p1 (filename)
"Count how many trees are visible from the outside.
A tree is visible if all other trees between it and the edge of the grid are shorter."
- (multiple-value-bind (width height forest-arr) (forest (uiop:read-file-lines filename))
- (loop for base across forest-arr
+ (multiple-value-bind (width height forest) (forest (uiop:read-file-lines filename))
+ (loop for base across forest
and p from 0
count (some (lambda (direction)
(loop for l in (line-of-sight direction p width height)
- for tree-height = (aref forest-arr l)
+ for tree-height = (aref forest l)
always (< tree-height base)))
'(right left top bottom)))))
(defun solver-p2 (filename)
"A scenic score is the product of the viewing distance in each direction.
The viewing distance is the lenght until a tree of equal height appears."
- (multiple-value-bind (width height forest-arr) (forest (uiop:read-file-lines filename))
- (loop for base across forest-arr
+ (multiple-value-bind (width height forest) (forest (uiop:read-file-lines filename))
+ (loop for base across forest
and p from 0
maximize (apply #'*
(mapcar
(lambda (direction)
(loop for l in (line-of-sight direction p width height)
- for tree-height = (aref forest-arr l)
+ for tree-height = (aref forest l)
count l until (>= tree-height base)))
'(right left top bottom))))))