Skip to content

Commit cb7b98b

Browse files
committed
day12.lisp
1 parent 1334fc7 commit cb7b98b

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

lisp/src/day12.lisp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(in-package #:aoc)
2+
3+
4+
(defun parse-sizes (filename)
5+
(with-open-file (input-stream (aoc:input-path filename))
6+
(loop with acc = '()
7+
for line = (read-line input-stream nil nil)
8+
while line
9+
if (string= "" line)
10+
do (setf acc '())
11+
else
12+
do (push (aoc:integers line) acc)
13+
finally (return acc))))
14+
15+
(defun fitsp (line)
16+
(destructuring-bind (w h &rest amounts) line
17+
(<= (* 9 (reduce #'+ amounts))
18+
(* w h))))
19+
20+
(defun day12 (&optional (filename 12))
21+
(let ((lines (parse-sizes filename)))
22+
(loop for line in lines
23+
count (fitsp line))))

0 commit comments

Comments
 (0)