aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2023
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2023-12-06 09:14:45 +0100
committerOscar Najera <hi@oscarnajera.com>2023-12-06 09:14:45 +0100
commit84d460d8b43e9b6ce0f4d7f9b53037747692b5ba (patch)
treec662136d903027e64f6668a51d5343034859acb3 /AoC2023
parent914efa4071448ae8005784c45b9dc2b028e19d47 (diff)
downloadscratch-84d460d8b43e9b6ce0f4d7f9b53037747692b5ba.tar.gz
scratch-84d460d8b43e9b6ce0f4d7f9b53037747692b5ba.tar.bz2
scratch-84d460d8b43e9b6ce0f4d7f9b53037747692b5ba.zip
solution part 2
Diffstat (limited to 'AoC2023')
-rw-r--r--AoC2023/day06/solver.lisp24
1 files changed, 21 insertions, 3 deletions
diff --git a/AoC2023/day06/solver.lisp b/AoC2023/day06/solver.lisp
index 460b554..876d5c1 100644
--- a/AoC2023/day06/solver.lisp
+++ b/AoC2023/day06/solver.lisp
@@ -13,7 +13,7 @@ Distance: 9 40 200")
point)))
(defun charge-time-solutions (pair)
- (destructuring-bind (race-time . record-distance) pair
+ (destructuring-bind (race-time record-distance) pair
;; quadratic equation: -charge_time**2 + race_time*charge_time - record_distance
(let ((lower (bounds race-time record-distance 'lower))
(upper (bounds race-time record-distance)))
@@ -25,16 +25,34 @@ Distance: 9 40 200")
(mapcar
(lambda (line)
(mapcar #'parse-integer (cdr (str:split-omit-nulls #\Space line)))))
- (apply #'mapcar #'cons)
+ (apply #'mapcar #'list)
(mapcar #'charge-time-solutions)
(apply #'*)))
+(defun solver2 (lines)
+ (arrows:->>
+ lines
+ (mapcar (lambda (line)
+ (parse-integer (str:replace-all "[^\\d]" "" line :regex t))))
+ (charge-time-solutions)))
+
(fiveam:test solutions
(fiveam:is
(= 288
(solver1
(uiop:split-string eg-input :separator '(#\Newline)))))
(fiveam:is
+ (= 71503
+ (solver2
+ (uiop:split-string eg-input :separator '(#\Newline)))))
+ (fiveam:is
(= 281600
(solver1
- (uiop:read-file-lines "input")))))
+ (uiop:read-file-lines "input"))))
+ (fiveam:is
+ (= 33875953
+ ;; This is just to match the solution on AoC. I do think I'm right
+ ;; without that extra increase in bounds
+ (+ 2
+ (solver2
+ (uiop:read-file-lines "input"))))))