day-25.lisp (1231B)
1 (defpackage #:aoc/day-25 2 (:use #:cl #:aoc/utils) 3 (:export 4 #:key-fits-p 5 #:day-25)) 6 (in-package #:aoc/day-25) 7 8 (defun heightmap (map) 9 (loop for x from 0 below (input-map-width map) 10 collect (loop for y from 0 below (input-map-height map) 11 when (char= (map-cell map (cons x y)) #\#) 12 sum 1))) 13 14 (defun parse-input (input) 15 (loop with locks = nil 16 with keys = nil 17 with max-height = 0 18 for map = (make-map input) 19 until (null map) 20 for height = (input-map-height map) 21 when (> height max-height) 22 do (setf max-height height) 23 if (char= (map-cell map (cons 0 0)) #\.) 24 do (push (heightmap map) keys) 25 else 26 do (push (heightmap map) locks) 27 finally (return (values locks keys max-height)))) 28 29 (defun key-fits-p (lock key max-height) 30 (loop for lock-v in lock 31 for key-v in key 32 always (<= (+ lock-v key-v) max-height))) 33 34 (defun day-25 (input) 35 (multiple-value-bind (locks keys max-height) 36 (parse-input input) 37 (loop for lock in locks 38 sum (loop for key in keys 39 when (key-fits-p lock key max-height) 40 sum 1))))