Day 07 - Better part 2 solution

This commit is contained in:
aru 2021-12-07 18:16:20 +01:00
parent 74b937f5df
commit 0cacd9883d
1 changed files with 4 additions and 4 deletions

View File

@ -38,10 +38,10 @@
(/ (* cost-base (+ cost-base 1)) 2)))
(defun part2 (data)
(let ((lowest (apply #'min data))
(highest (apply #'max data)))
(loop for x from lowest to highest
minimizing (fuel-cost data x #'compounding-cost))))
(let* ((sum (reduce #'+ data))
(count (length data)))
(min (fuel-cost data (floor sum count) #'compounding-cost)
(fuel-cost data (ceiling sum count) #'compounding-cost))))
(format t "===== Part 1 =====")
(format t "Result: ~A~%~%" (time (part1 *data*)))