Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun masses-from-file (filepath)
- (with-open-file (handle filepath)
- (loop for line = (read-line handle nil nil)
- while line
- collect (parse-integer line))))
- (defun fuel-for-mass (n)
- (- (floor (/ n 3))
- 2))
- (defun total-fuel-for-mass (a b)
- (cond
- ((< (fuel-for-mass b) 0) 0)
- (t (+ (+ a (fuel-for-mass b))
- (total-fuel-for-mass 0 (fuel-for-mass b))))))
- (write (reduce #'total-fuel-for-mass
- (masses-from-file "../input")
- :initial-value 0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement