-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2ec0f2
commit ef3b882
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
(defpackage :aoc/2023/06 #.cl-user::*aoc-use*) | ||
(in-package :aoc/2023/06) | ||
|
||
(defun parse-records (&optional (strings (uiop:read-file-lines #P"src/2023/day06.txt"))) | ||
(destructuring-bind (times records) strings | ||
(mapcar #'list | ||
(parse-positive-integers times) | ||
(parse-positive-integers records)))) | ||
|
||
(defun max-distance (time hold) | ||
(* hold (- time hold))) | ||
|
||
(defun count-wins (input) | ||
(destructuring-bind (time record) input | ||
(looping | ||
(dorangei (hold 0 time) | ||
(count! (> (max-distance time hold) record)))))) | ||
|
||
(defun massage-input (&optional (strings (uiop:read-file-lines #P"src/2023/day06.txt"))) | ||
(mapcar [remove-if-not #'digit-char-p _] strings)) | ||
|
||
|
||
(define-solution (2023 06) (strings) | ||
(values (reduce #'* (parse-records strings) :key #'count-wins) | ||
(bnd1 (strings (massage-input strings)) | ||
(reduce #'* (parse-records strings) :key #'count-wins)))) | ||
|
||
(define-test (2023 06) (220320 34454850)) |