Skip to content

Instantly share code, notes, and snippets.

@ato
Created November 4, 2009 23:57
Show Gist options
  • Save ato/226530 to your computer and use it in GitHub Desktop.
Save ato/226530 to your computer and use it in GitHub Desktop.
(defn esj-problem
[n limit s]
(if-not (seq s) ; reached end of input?
(when-not (zero? n) ; if there's anything left-over return it
(list n))
(if (>= n limit) ; have we reached the limit?
(lazy-seq ; if so, spit out a new output
(cons n (esj-problem 0 limit s)))
; haven't reached limit, gobble some more input
(recur (+ n (first s)) limit (next s)))))
(esj-problem 0 10 [1 4 8 73 2 4 1 8 9])
# => (13 73 15 9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment