Created
August 29, 2012 04:13
-
-
Save l1x/3506753 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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] | |
(let [ [row & rows] (seq matrix)] | |
(doseq [el row] (print (str " " el))) | |
(when (seq rows) | |
(->> rows (apply map vector) reverse recur)))) | |
(spiral-print matrix1) | |
(spiral-print matrix2) |
(defn spiral
[matrix]
(let [[row & rows] (seq matrix)]
(doseq [el row] (print el))
(when (seq rows)
(->> rows (apply map vector) reverse recur))))
;; Evil version
(->> rows
(apply map vector)
reverse
recur
(when (seq rows))
(let [[row & rows] (seq matrix)] (doseq [el row] (print el)))
(defn spiral [matrix]))
This is really tricky :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[[1 2 3] [[4 5] [[6 7] [[8]
[8 9 4] -> [9 6] -> [9 8]] -> [9]] -> [[9]]
[7 6 5]] [8 7]]