solve day12 start 13

This commit is contained in:
Peter Tillemans 2024-12-13 06:01:50 +01:00
parent 785f8f382a
commit e74dd696dc
5 changed files with 191 additions and 11 deletions

View file

@ -37,6 +37,7 @@
(:file "2024/day10")
(:file "2024/day11")
(:file "2024/day12")
(:file "2024/day13")
)))
:description "Advent of Code challenges and solutions."
:long-description "Solutions for the AOC challenges."
@ -65,6 +66,7 @@
(:file "2024/day10-test")
(:file "2024/day11-test")
(:file "2024/day12-test")
(:file "2024/day13-test")
)))
:description "Test system for aoc"
:perform (test-op (op c) (symbol-call :parachute :test :aoc/tests)))

View file

@ -5,11 +5,14 @@
#:sample-data2
#:part1
#:part2
#:top-side-p
#:find-same-neighbors
#:get-plant
#:find-region
#:scan-regions
#:top-side-p
#:left-side-p
#:right-side-p
#:bottom-side-p
#:sides
))
@ -112,7 +115,7 @@ MMMISSJEEE
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)) (+ (f garden x y) (cdr d))))))
(setf (gethash id info) (cons (1+ (car d)) (+ (apply f (list garden x y)) (cdr d))))))
)
info))
@ -144,13 +147,32 @@ MMMISSJEEE
(lu (eq id (get-plant garden (1- y) (1- x))))
(up (eq id (get-plant garden (1- y) x)))
(left (eq id (get-plant garden y (1- x)))))
(and (or lu (not up)) (not left))))
(defun right-side-p (garden x y)
(let* ((id (get-plant garden y x))
(ru (eq id (get-plant garden (1- y) (1+ x))))
(up (eq id (get-plant garden (1- y) x)))
(right (eq id (get-plant garden y (1+ x)))))
(and (or ru (not up)) (not right))))
(defun bottom-side-p (garden x y)
(let* ((id (get-plant garden y x))
(lb (eq id (get-plant garden (1+ y) (1- x))))
(bottom (eq id (get-plant garden (1+ y) x)))
(left (eq id (get-plant garden y (1- x)))))
(and (or lb (not left)) (not bottom))))
(defun sides (garden x y)
(+
(if (and (or lu (not left)) (not up)) 1 0) ; top side
(if (and (not left) (not lu)) 1 0) ; left side
)))
(if (top-side-p garden x y) 1 0)
(if (left-side-p garden x y) 1 0)
(if (right-side-p garden x y) 1 0)
(if (bottom-side-p garden x y) 1 0)
))
(defun part2 (data)
(length data))
(format nil "~A" (calculate-costs (calculate-info (scan-regions data) #'si))))
(defun solve-day ()
(format t "part1: ~A~%" (part1 input-data))

42
src/2024/day13.lisp Normal file
View file

@ -0,0 +1,42 @@
(defpackage :aoc/2024/13
(:use :cl :aoc :alexandria :trivia :lla)
(:export
#:sample-data
#:sample-data2
#:part1
#:part2
))
(in-package :aoc/2024/13)
(defun parse-line (line)
line)
(defun parse-input (lines)
(mapcar #'parse-line lines))
(defparameter input-text (first (test-input 2024 13)))
(defparameter input-data (parse-input input-text))
(defparameter sample-text (aoc:split-lines ""))
(defparameter sample-data
(parse-input sample-text))
(defun part1 (data)
nil)
(defun part2 (data)
nil)
(defun solve-day ()
(format t "part1: ~A~%" (part1 input-data))
(format t "part2: ~A~%" (part2 input-data)))
(defun submit ()
(let ((p1 (part1 input-data))
(p2 (part2 input-data)))
(if p1 (submit-part1 2024 13 p1))
(if p2 (submit-part2 2024 13 p2))))

View file

@ -23,7 +23,7 @@
(define-test test-top-side-p
:parent suite-2024-12
(true (top-side-p (make-array '(3 3) :initial-contents '((0 0 0)
(false (top-side-p (make-array '(3 3) :initial-contents '((0 0 0)
(0 0 0)
(0 0 0))) 1 1))
(true (top-side-p (make-array '(3 3) :initial-contents '((1 0 0)
@ -37,7 +37,94 @@
(1 1 1))) 1 1))
(false (top-side-p (make-array '(3 3) :initial-contents '((0 1 0)
(0 1 1)
(1 1 1))) 1 1)))
(1 1 1))) 1 1))
(true (top-side-p (make-array '(3 3) :initial-contents '((0 1 0)
(1 1 1)
(1 1 1))) 1 0))
(false (top-side-p (make-array '(3 3) :initial-contents '((1 1 0)
(1 1 1)
(1 1 1))) 1 0))
)
(define-test test-bottom-side-p
:parent suite-2024-12
(false (bottom-side-p (make-array '(3 3) :initial-contents '((0 0 0)
(0 0 0)
(0 0 0))) 1 1))
(true (bottom-side-p (make-array '(3 3) :initial-contents '((1 1 1)
(1 1 1)
(1 0 0))) 1 1))
(false (bottom-side-p (make-array '(3 3) :initial-contents '((1 1 1)
(1 1 1)
(0 0 0))) 1 1))
(true (bottom-side-p (make-array '(3 3) :initial-contents '((0 0 0)
(0 1 1)
(0 0 0))) 1 1))
(false (bottom-side-p (make-array '(3 3) :initial-contents '((0 1 1)
(0 1 1)
(0 1 0))) 1 1))
(true (bottom-side-p (make-array '(3 3) :initial-contents '((0 1 0)
(1 1 1)
(0 1 0))) 1 2))
(false (bottom-side-p (make-array '(3 3) :initial-contents '((1 1 0)
(1 1 1)
(1 1 1))) 1 2))
)
(define-test test-left-side-p
:parent suite-2024-12
(false (left-side-p (make-array '(3 3) :initial-contents '((0 0 0)
(0 0 0)
(0 0 0))) 1 1))
(true (left-side-p (make-array '(3 3) :initial-contents '((1 1 1)
(0 1 1)
(0 1 1))) 1 1))
(false (left-side-p (make-array '(3 3) :initial-contents '((0 1 1)
(0 1 1)
(1 1 1))) 1 1))
(true (left-side-p (make-array '(3 3) :initial-contents '((0 0 1)
(0 1 1)
(1 1 1))) 1 1))
(false (left-side-p (make-array '(3 3) :initial-contents '((0 1 0)
(1 1 1)
(0 1 1))) 1 1)))
(define-test test-right-side-p
:parent suite-2024-12
(false (right-side-p (make-array '(3 3) :initial-contents '((0 0 0)
(0 0 0)
(0 0 0))) 1 1))
(true (right-side-p (make-array '(3 3) :initial-contents '((1 1 1)
(1 1 0)
(1 1 0))) 1 1))
(false (right-side-p (make-array '(3 3) :initial-contents '((1 1 0)
(1 1 0)
(1 1 1))) 1 1))
(true (right-side-p (make-array '(3 3) :initial-contents '((1 0 0)
(1 1 0)
(1 1 1))) 1 1))
(false (right-side-p (make-array '(3 3) :initial-contents '((0 1 0)
(1 1 1)
(1 1 0))) 1 1)))
(define-test test-sides
(is = 4 (sides (make-array '(3 3) :initial-contents '((0 0 0)
(0 1 0)
(0 0 0))) 1 1))
(is = 1 (sides (make-array '(3 3) :initial-contents '((0 1 0)
(0 1 0)
(0 0 0))) 1 1))
(is = 3 (sides (make-array '(3 3) :initial-contents '((0 0 0)
(0 1 0)
(0 1 0))) 1 1))
(is = 1 (sides (make-array '(3 3) :initial-contents '((0 0 0)
(1 1 0)
(0 0 0))) 1 1))
(is = 3 (sides (make-array '(3 3) :initial-contents '((0 0 0)
(0 1 1)
(0 0 0))) 1 1)) )
(define-test+run test-part1
:parent suite-2024-12

View file

@ -0,0 +1,27 @@
(defpackage :aoc/2024/13/tests
(:use :cl :aoc :aoc/tests :aoc/2024/tests :parachute :aoc/2024/13))
(in-package :aoc/2024/13/tests)
(define-test suite-2024-13
;:parent suite-2024
)
(define-test test-foo
:parent suite-2024-13
)
(define-test test-bar
:parent suite-2024-13
)
(define-test+run test-part1
:parent suite-2024-13
(is equal nil (part1 sample-data)))
(define-test+run test-part2
:parent suite-2024-13
(is equal nil (part2 sample-data)))