Skip to content

Instantly share code, notes, and snippets.

@icambron
Created April 3, 2015 06:29
Show Gist options
  • Save icambron/369d568bf6d5478e59b8 to your computer and use it in GitHub Desktop.
Save icambron/369d568bf6d5478e59b8 to your computer and use it in GitHub Desktop.
free samples
(defn eat-well [vendors]
(loop [[[item & others] newest older oldest] [vendors 0 0 0]]
(if item
(recur [others (+ item (max older oldest)) newest older])
(max newest older oldest))))
(eat-well [1 4 3 12 4 3 3 4])
@icambron
Copy link
Author

icambron commented Apr 3, 2015

Alex's formulation is equivalent but slightly nicer; it just does the max one step earlier.

(defn eat-well [vendors]
  (loop [[[item & others] exclude include] [vendors 0 0]]
    (if item
      (recur [others (+ item include) (max include exclude)])
      (max include exclude))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment