Skip to content

Instantly share code, notes, and snippets.

@ekroon
Last active August 29, 2015 14:15
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 ekroon/43279a583274466629b6 to your computer and use it in GitHub Desktop.
Save ekroon/43279a583274466629b6 to your computer and use it in GitHub Desktop.
sequenced-spiral
(defn spiral [n]
(let [amounts
(drop 1
(interleave
(range n 0 -1)
(range n 0 -1)))
directions
(cycle [[1 0] [0 1] [-1 0] [0 -1]])
steps
(mapcat (fn [a d] (repeat a d)) amounts directions)
coords
(reductions (fn [r v] (map + r v)) steps)
values (map (fn [[x y]] (+ x (* n y))) coords)]
values))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment