solved day 12 part 1
This commit is contained in:
parent
a3d25c257f
commit
b3518e5195
3 changed files with 35 additions and 12 deletions
|
@ -39,7 +39,7 @@ MIIIIIJJEE
|
|||
MIIISIJEEE
|
||||
MMMISSJEEE
|
||||
"))
|
||||
|
||||
(defparameter sample-data (parse-input sample-text))
|
||||
|
||||
(defun get-plant (plants y x)
|
||||
(if (array-in-bounds-p plants y x)
|
||||
|
@ -72,7 +72,6 @@ MMMISSJEEE
|
|||
do (progn
|
||||
(setf (aref seen y x) t)
|
||||
(setf queue (cdr queue)))
|
||||
do (format t "x: ~A, y: ~A, queue: ~A, neighbors: ~A~%" x y queue neighbors)
|
||||
do (loop for p in neighbors
|
||||
unless (aref seen (cdr p) (car p))
|
||||
do (push p queue))
|
||||
|
@ -87,27 +86,53 @@ MMMISSJEEE
|
|||
for y from 0 below (array-dimension plants 1)
|
||||
do (loop
|
||||
for x from 0 below (array-dimension plants 0)
|
||||
do (format t "~A,")
|
||||
if (< (aref garden-map y x) 0)
|
||||
for r = (aref garden-map y x)
|
||||
if (< r 0)
|
||||
do (let ((id (incf region-id)))
|
||||
(loop
|
||||
for region in (find-region plants x y)
|
||||
for x = (car region)
|
||||
for y = (cdr region)
|
||||
do (setf (aref garden-map y x) id)))))
|
||||
garden-map))
|
||||
|
||||
(defun circumference (garden x y)
|
||||
(let ((id (aref garden y x)))
|
||||
(- 4
|
||||
(if (eq id (get-plant garden (1- y) x)) 1 0)
|
||||
(if (eq id (get-plant garden (1+ y) x)) 1 0)
|
||||
(if (eq id (get-plant garden y (1- x))) 1 0)
|
||||
(if (eq id (get-plant garden y (1+ x))) 1 0)
|
||||
)))
|
||||
|
||||
(defun calculate-info (garden)
|
||||
(let ((info (make-hash-table)))
|
||||
(loop
|
||||
for y from 0 below (array-dimension garden 1)
|
||||
do (loop
|
||||
for x from 0 below (array-dimension garden 0)
|
||||
do (let* ((id (aref garden y x))
|
||||
(d (gethash id info (cons 0 0))))
|
||||
(setf (gethash id info) (cons (1+ (car d)) (+ (circumference garden x y) (cdr d))))))
|
||||
)
|
||||
info))
|
||||
|
||||
|
||||
(defun calculate-costs (info)
|
||||
(loop for k being the hash-keys in info
|
||||
for v being the hash-values in info
|
||||
sum (* (car v) (cdr v))))
|
||||
|
||||
|
||||
(defun fence-cost (plants)
|
||||
(loop for region being the hash-values of (scan-garden plants)
|
||||
sum (let ((info (cdr region))) (* (car info) (cdr info)))))
|
||||
|
||||
(defparameter sample-data
|
||||
(parse-input sample-text))
|
||||
|
||||
(defun part1 (data)
|
||||
nil)
|
||||
(format nil "~A" (calculate-costs (calculate-info (scan-regions data)))))
|
||||
|
||||
(defun part2 (data)
|
||||
nil)
|
||||
(length data))
|
||||
|
||||
(defun solve-day ()
|
||||
(format t "part1: ~A~%" (part1 input-data))
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
(defparameter *aoc-url* "https://adventofcode.com")
|
||||
|
||||
|
||||
(defparameter *cookie-jar*
|
||||
(cl-cookie:make-cookie-jar
|
||||
:cookies (list
|
||||
|
@ -25,7 +24,6 @@
|
|||
:domain ".adventofcode.com"
|
||||
:secure-p t))))
|
||||
|
||||
|
||||
(defun split-lines (s)
|
||||
(cl-ppcre:split "\\n" s))
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
(define-test+run test-part1
|
||||
:parent suite-2024-12
|
||||
(is equal nil (part1 sample-data)))
|
||||
(is equal "1930" (part1 sample-data)))
|
||||
|
||||
(define-test+run test-part2
|
||||
:parent suite-2024-12
|
||||
|
|
Loading…
Reference in a new issue