solved day19
This commit is contained in:
parent
ae69d78d64
commit
57f4a063d6
2 changed files with 22 additions and 28 deletions
|
@ -1,4 +1,3 @@
|
|||
|
||||
(defpackage :aoc/2024/19
|
||||
(:use :cl :aoc :alexandria :trivia :lla)
|
||||
(:export
|
||||
|
@ -54,7 +53,7 @@ bbrgwb"))
|
|||
(terminates nil))
|
||||
(loop
|
||||
for towel in towels
|
||||
if (emptyp towel
|
||||
if (emptyp towel)
|
||||
do (setf terminates t)
|
||||
else
|
||||
do (setf (gethash (char towel 0) towel-tree)
|
||||
|
@ -66,7 +65,7 @@ bbrgwb"))
|
|||
((< (length a) (length b)) t)
|
||||
((> (length a) (length b)) nil)
|
||||
(t (string-lessp a b)))
|
||||
))))
|
||||
)))
|
||||
(loop
|
||||
for k being the hash-keys in towel-tree
|
||||
for v being the hash-values in towel-tree
|
||||
|
@ -75,7 +74,7 @@ bbrgwb"))
|
|||
(make-node
|
||||
:name word
|
||||
:terminates terminates
|
||||
:next towel-tree)))
|
||||
:next towel-tree))))
|
||||
|
||||
(defun show-tree (tree &optional (depth 0))
|
||||
(loop
|
||||
|
@ -154,11 +153,10 @@ bbrgwb"))
|
|||
collect pattern))
|
||||
|
||||
(defun possible-patterns (towels pattern)
|
||||
(multiple-value-bind (is-valid found)
|
||||
(multiple-value-bind (n found)
|
||||
(gethash pattern *possible-patterns*)
|
||||
(format t "~A ~A ~A~%" pattern is-valid found)
|
||||
(if found
|
||||
(if is-valid 1 0)
|
||||
n
|
||||
(setf (gethash pattern *possible-patterns*)
|
||||
(if (emptyp pattern)
|
||||
1
|
||||
|
@ -175,7 +173,11 @@ bbrgwb"))
|
|||
(format nil "~A" (length (valid-patterns onsen))))
|
||||
|
||||
(defun part2 (data)
|
||||
(length data))
|
||||
(reset-patterns)
|
||||
(format nil "~A"
|
||||
(loop for p in (onsen-patterns data)
|
||||
for n = (possible-patterns (onsen-towels data) p)
|
||||
sum n)))
|
||||
|
||||
(defun solve-day ()
|
||||
(format t "part1: ~A~%" (part1 input-data))
|
||||
|
|
|
@ -64,21 +64,13 @@
|
|||
|
||||
)
|
||||
|
||||
|
||||
|
||||
(define-test test-bar
|
||||
:parent suite-2024-19
|
||||
)
|
||||
|
||||
|
||||
|
||||
(define-test+run test-part1
|
||||
:parent suite-2024-19
|
||||
(is equal "6" (part1 sample-data)))
|
||||
|
||||
(define-test+run test-part2
|
||||
:parent suite-2024-19
|
||||
(is equal nil (part2 sample-data)))
|
||||
(is equal "16" (part2 sample-data)))
|
||||
|
||||
(defun run-tests ()
|
||||
(test 'suite-2024-19))
|
||||
|
|
Loading…
Reference in a new issue