Skip to content

Commit

Permalink
2023/04 refactoring
Browse files Browse the repository at this point in the history
- Replace some ugly combination of BND + DOLIST + INCF, with
  a (hopefully) simpler DOLIST+ + ENUMERATE
- Replace DOTIMES + 1+, with DORANGEI
  • Loading branch information
iamFIREcracker committed Dec 8, 2023
1 parent 16e5857 commit 84a8239
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/2023/day04.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,20 @@
(extract-positive-integers yours)))))

(defun card-points (s) (ash 1 (1- (length (winning-numbers s)))))
#+#:excluded (card-points "Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53")

(mapcar #'card-points (uiop:read-file-lines #P"src/2023/day04.txt"))
(reduce #'+ *)
20667


(defun part2 (&optional (strings (uiop:read-file-lines #P"src/2023/day04.txt")))
(bnd* ((cards-count (make-array (length strings) :initial-element 1))
(curr -1))
(bnd1 (cards-count (make-array (length strings) :initial-element 1))
(looping
(dolist (s strings)
(incf curr)
(dolist+ ((curr s) (enumerate strings))
(bnd* ((current-card-count (aref cards-count curr)))
(sum! current-card-count)
(dotimes (i (length (winning-numbers s)))
(incf (aref cards-count (+ curr i 1)) current-card-count)))))))
(part2)
5833065
(dorangei (i 1 (length (winning-numbers s)))
(incf (aref cards-count (+ curr i)) current-card-count)))))))


(define-solution (2023 04) (strings)
(values (reduce #'+ strings :key #'card-points)
(part2)))

(define-test (2023 04) (20667 5833065))

0 comments on commit 84a8239

Please sign in to comment.