Day 07 - Better part 2 solution
This commit is contained in:
parent
74b937f5df
commit
0cacd9883d
|
@ -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*)))
|
||||
|
|
Reference in New Issue