Skip to content

Instantly share code, notes, and snippets.

@RaymondKroon
Created February 15, 2015 18:44
Show Gist options
  • Save RaymondKroon/cac5e6f4ebcfe04a3b45 to your computer and use it in GitHub Desktop.
Save RaymondKroon/cac5e6f4ebcfe04a3b45 to your computer and use it in GitHub Desktop.
Spiral
(defn spiral [n]
(let [amounts (drop 1 (mapcat #(repeat 2 %) (range n 0 -1)))
directions (cycle [1 n -1 (- n)])
steps (mapcat (fn [a d] (repeat a d)) amounts directions)
values (reductions + steps)]
values))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment