Skip to content

Instantly share code, notes, and snippets.

@kindlychung
Created January 15, 2015 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kindlychung/1b10842c22236427ac9c to your computer and use it in GitHub Desktop.
Save kindlychung/1b10842c22236427ac9c to your computer and use it in GitHub Desktop.
(defn tri*
"Generates lazy sequence of triangular numbers"
([] (tri* 0 1))
([sum n]
(let [new-sum (+ sum n)]
(cons new-sum (lazy-seq (tri* new-sum (inc n))))
))
)
(defn tri1*
"Generates lazy sequence of triangular numbers"
([] (tri1* 0 1))
([sum n]
(let [new-sum (+ sum n)]
(cons new-sum (lazy-seq (recur new-sum (inc n))))
))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment