Skip to content

Instantly share code, notes, and snippets.

@emezeske
Forked from l1x/spiral.clj
Created August 30, 2012 05:30
Show Gist options
  • Select an option

  • Save emezeske/3522797 to your computer and use it in GitHub Desktop.

Select an option

Save emezeske/3522797 to your computer and use it in GitHub Desktop.
(ns spiral)
(def matrix1 [[1 2 3][8 9 4][7 6 5]])
(def matrix2 [[1 2 3 4][12 13 14 5][11 16 15 6][10 9 8 7]])
(defn spiral-print [matrix result]
(let [[row & rows] (seq matrix)]
(if (seq rows)
(recur
(reverse (apply map vector rows))
(concat result row))
result)))
(spiral-print matrix1 [])
(spiral-print matrix2 [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment