Skip to content

Commit

Permalink
Fix more tests -- broken after encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
iamFIREcracker committed Jan 12, 2024
1 parent 6a27192 commit 11c4f2e
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 50 deletions.
1 change: 1 addition & 0 deletions package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
:parse-char
:extract-positive-integers
:extract-integers
:extract-forms

:define-solution
:define-test))
Expand Down
14 changes: 7 additions & 7 deletions src/2022/day02.lisp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(defpackage :aoc/2022/02 #.cl-user::*aoc-use*)
(in-package :aoc/2022/02)

(defun parse-moves ()
(defun parse-moves (&optional (strings (uiop:read-file-lines #P"src/2022/day02.txt")))
(flet ((move (v) (ecase v ((a x) 'r) ((b y) 'p) ((c z) 's))))
(loop for (them you) on (uiop:read-file-forms #P"src/2022/day02.txt") by #'cddr
(loop for (them you) in (mapcar #'extract-forms strings)
collect (cons (move them) (move you)))))

(defun win? (you them) (member (list you them) '((r s) (p r) (s p)) :test 'equal))
Expand All @@ -16,9 +16,9 @@
else if (win? you them) sum (+ (move-score you) 6)
else sum (+ (move-score you) 3)))

(defun parse-moves2 ()
(defun parse-moves2 (&optional (strings (uiop:read-file-lines #P"src/2022/day02.txt")))
(flet ((move (v) (ecase v (a 'r) (b 'p) (c 's))))
(loop for (them you) on (uiop:read-file-forms #P"src/2022/day02.txt") by #'cddr
(loop for (them you) in (mapcar #'extract-forms strings)
collect (let ((them (move them)))
(cons
them
Expand All @@ -30,9 +30,9 @@

(defun loses-to (you) (ecase you (r 's) (p 'r) (s 'p)))

(defun solution-run ()
(values (solve (parse-moves))
(solve (parse-moves2))))
(define-solution (2022 02) (strings)
(values (solve (parse-moves strings))
(solve (parse-moves2 strings))))

(define-test (2022 02) (14297 10498))

Expand Down
11 changes: 5 additions & 6 deletions src/2022/day03.lisp
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
(defpackage :aoc/2022/03 #.cl-user::*aoc-use*)
(in-package :aoc/2022/03)

(defun backpacks ()
(mapcar [coerce _ 'list]
(uiop:read-file-lines #P"src/2022/day03.txt")))
(defun backpacks (&optional (strings (uiop:read-file-lines #P"src/2022/day03.txt")))
(mapcar [coerce _ 'list] strings))

(defun item-priority (c)
(1+ (position c "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")))

(defun find-duplicate-item (&rest lists)
(first (reduce #'intersection (cdr lists) :initial-value (car lists))))

(defun solution-run ()
(define-solution (2022 03) (bps backpacks)
(values
(loop for pack in (backpacks)
(loop for pack in bps
for (c1 c2) = (split pack (/ (length pack) 2))
sum (item-priority (find-duplicate-item c1 c2)))
(loop for (b1 b2 b3) on (backpacks) by #'cdddr
(loop for (b1 b2 b3) on bps by #'cdddr
sum (item-priority (find-duplicate-item b1 b2 b3)))))

(define-test (2022 03) (7746 2604))
Expand Down
9 changes: 4 additions & 5 deletions src/2022/day04.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
(in-package :aoc/2022/04)


(defun assignment-pairs ()
(mapcar [extract-positive-integers _]
(uiop:read-file-lines #P"src/2022/day04.txt")))
(defun assignment-pairs (&optional (strings (uiop:read-file-lines #P"src/2022/day04.txt")))
(mapcar [extract-positive-integers _] strings))

(defun solution-run ()
(loop for (a b c d) in (assignment-pairs)
(define-solution (2022 04) (strings)
(loop for (a b c d) in (assignment-pairs strings)
count (or (<= a c d b) (<= c a b d)) into part1
count (or (<= a c b d) (<= a c d b)
(<= c a d b) (<= c a b d)) into part2
Expand Down
12 changes: 6 additions & 6 deletions src/2022/day05.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
(defun top-crates (stacks)
(format nil "~{~A~}" (map 'list #'car (subseq stacks 1))))

(defun part1 ()
(destructuring-bind (stacks moves) (parse-input)
(defun part1 (&optional (input (parse-input)))
(destructuring-bind (stacks moves) input
(loop for (n from to) in moves do
(loop repeat n do (push (pop (aref stacks from)) (aref stacks to)))
finally (return (top-crates stacks)))))

(defun part2 ()
(destructuring-bind (stacks moves) (parse-input)
(defun part2 (&optional (input (parse-input)))
(destructuring-bind (stacks moves) input
(loop for (n from to) in moves do
(loop for a in (reverse (loop repeat n collect (pop (aref stacks from))))
do (push a (aref stacks to)))
finally (return (top-crates stacks)))))

(defun solution-run ()
(values (part1) (part2)))
(define-solution (2022 05) (strings)
(values (part1 (parse-input strings)) (part2 (parse-input strings))))

(define-test (2022 05) ("SVFDLGLWV" "DCVTCVPCL"))

Expand Down
4 changes: 2 additions & 2 deletions src/2022/day06.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
(defun all-distinct (seq)
(= (length (remove-duplicates seq)) (length seq)))

(defun solution-run ()
(values (marker-position 4) (marker-position 14)))
(define-solution (2022 06) (s first)
(values (marker-position 4 s) (marker-position 14 s)))

(define-test (2022 06) (1702 3559))

Expand Down
2 changes: 1 addition & 1 deletion src/2022/day08.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
(loop for jj from (1+ j) below n sum 1 while (smallerp i jj))))))


(defun solution-run (&optional (map (parse-map)))
(define-solution (2022 08) (map parse-map)
(values (part1 map) (part2 map)))

(define-test (2022 08) (1719 590824))
Expand Down
2 changes: 1 addition & 1 deletion src/2022/day10.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(:C "WW8XehlJvZLgDZZk3yiDwgXv7JGnLN3g4qbDgtkHiYS99Uqh71E/5tqoykfUycWKBJe00NrDX/lWZJghCOiDu6xwH9zPR7zKkCfdnTHflfbVEzX3zVmAN5Bp/Gjf3QX5xxT5yKHFDhlGivYHyQDR5kVhqEDdVNp/76M66hYGTb8AdCA13qYaJcRyo3C4JAQ4x3/DSFnEHyTUsoxq/dPTgfsZ3bYNpT66BhsrEh1r0s3lsXxnEznnIkUDG7sW1Hw35c0YeooLpvy575/MSCcQ/NBAUAPFbz8pSSrWidSSyBKq6U6+Vm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S8atyCgJP276WwcQIJG21DMLrt4pVRnd7QqfqWrD+S25T8iyAMwZjeID7n4rmPL7drzEilshoVvHca5XlKaDoKNhUEn2jdnIRIOo7ii1XtsQ+qRhRekP2xoIN4IkmqnX8gY28OkvVO8/U5HGR7LGoLb7mQ=" :I "pja9ckuyvN4Qnq29mwg222ZHxiPG1X3f/RW2do31stA=" :G "0uLYtPRmshMJqHt33qJ4sw==")
5 changes: 4 additions & 1 deletion src/2022/day10.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
(in-package :aoc/2022/10)


(defun solution-run (&optional (program (uiop:read-file-forms #P"src/2022/day10.txt")))
(defun parse-program (&optional (strings (uiop:read-file-lines #P"src/2022/day10.txt")))
(reduce #'nconc (mapcar #'extract-forms strings)))

(define-solution (2022 10) (program parse-program)
(let ((crt (make-array (list 6 40))) (cycle 1) (x 1) (part1 0))
(dolist (token program)
(when (member cycle (list 20 60 100 140 180 220))
Expand Down
40 changes: 20 additions & 20 deletions src/2022/day11.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,22 @@
:throw-if-not-div (parse-number (pop g)))))
monkeys))

(defun solve (&optional (monkeys (parse-monkeys #+#:excluded (uiop:read-file-lines #P"scratch.txt"))))
(bnd1 (counts (make-array (length monkeys) :initial-element 0))
(loop repeat 20 do
(loop for m across monkeys for i from 0 do
(loop until (queue-empty-p (items m)) for wl = (dequeue (items m)) do
(incf (aref counts i))
(bnd1 nwl
(setf nwl (funcall (operation m) wl))
(setf nwl (floor nwl 3))
(if (dividesp (div-by m) nwl)
(enqueue nwl (items (aref monkeys (throw-if-div m))))
(enqueue nwl (items (aref monkeys (throw-if-not-div m)))))))))
(reduce #'* (sort counts #'>) :end 2)))


(solve)
#+#:excluded (defun solve (&optional (monkeys (parse-monkeys #+#:excluded (uiop:read-file-lines #P"scratch.txt"))))
(bnd1 (counts (make-array (length monkeys) :initial-element 0))
(loop repeat 20 do
(loop for m across monkeys for i from 0 do
(loop until (queue-empty-p (items m)) for wl = (dequeue (items m)) do
(incf (aref counts i))
(bnd1 nwl
(setf nwl (funcall (operation m) wl))
(setf nwl (floor nwl 3))
(if (dividesp (div-by m) nwl)
(enqueue nwl (items (aref monkeys (throw-if-div m))))
(enqueue nwl (items (aref monkeys (throw-if-not-div m)))))))))
(reduce #'* (sort counts #'>) :end 2)))


#+#:excluded (solve)

;; I don't know how to use divides anymore (flipped the order of its operands)

Expand All @@ -108,7 +108,7 @@
(enqueue nwl (items (aref monkeys (throw-if-not-div m)))))))))
(reduce #'* (sort counts #'>) :end 2)))

(solve)
#+#:excluded (solve)

;;;

Expand Down Expand Up @@ -164,8 +164,8 @@
(enqueue nwl (items (aref monkeys (throw-if-not-div m)))))))))
(reduce #'* (sort counts #'>) :end 2)))

(defun solution-run ()
(values (solve 20 (parse-monkeys))
(solve 10000 (parse-monkeys) t)))
(define-solution (2022 11) (strings)
(values (solve 20 (parse-monkeys strings))
(solve 10000 (parse-monkeys strings) t)))

(define-test (2022 11) (119715 18085004878))
2 changes: 1 addition & 1 deletion src/2022/day12.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
(aref map i j) 25)
(setf (aref map i j) (- (char-code ch) (char-code #\a)))))))
(list map start end)))
(parse-map)
#+#:excluded (parse-map)
(- (char-code #\b) (char-code #\a))

(defun solve ()
Expand Down
3 changes: 3 additions & 0 deletions src/utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,9 @@
(defun extract-integers (s)
(mapcar #'parse-integer (cl-ppcre:all-matches-as-strings "-?\\d+" s)))

(defun extract-symbols (s)
(mapcar #'read-from-string (cl-ppcre:all-matches-as-strings "\\w+" s)))

;;;; Problems -----------------------------------------------------------------

(defun read-decrypted-problem-input (year day)
Expand Down

0 comments on commit 11c4f2e

Please sign in to comment.