2013-04-11 01:07:29 -07:00
|
|
|
(defn spiral [n]
|
2015-02-20 00:35:01 -05:00
|
|
|
(let [cyc (cycle [1 n -1 (- n)])]
|
|
|
|
|
(->> (range (dec n) 0 -1)
|
|
|
|
|
(mapcat #(repeat 2 %))
|
|
|
|
|
(cons n)
|
2017-09-23 10:01:46 +02:00
|
|
|
(mapcat #(repeat %2 %) cyc)
|
2015-02-20 00:35:01 -05:00
|
|
|
(reductions +)
|
|
|
|
|
(map vector (range 0 (* n n)))
|
2013-04-11 01:07:29 -07:00
|
|
|
(sort-by second)
|
2015-02-20 00:35:01 -05:00
|
|
|
(map first)))
|
|
|
|
|
|
|
|
|
|
(let [n 5]
|
|
|
|
|
(clojure.pprint/cl-format
|
|
|
|
|
true
|
|
|
|
|
(str " ~{~<~%~," (* n 3) ":;~2d ~>~}~%")
|
|
|
|
|
(spiral n)))
|