Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sirpengi
Created September 13, 2013 20:21
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 sirpengi/6555581 to your computer and use it in GitHub Desktop.
Save sirpengi/6555581 to your computer and use it in GitHub Desktop.
diagonal sum in clojure
(ns diagonal-sum)
(defn ds-step [[v prev step]]
[(+ v (* 4 prev) (* 10 step)) (+ prev (* 4 step)) (+ step 2)])
(defn ds-seq []
(map first (iterate ds-step [1 1 2])))
(println (take 10 (ds-seq)))
;(1 25 101 261 537 961 1565 2381 3441 4777)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment