all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
8
Task/Spiral-matrix/Clojure/spiral-matrix.clj
Normal file
8
Task/Spiral-matrix/Clojure/spiral-matrix.clj
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(defn spiral [n]
|
||||
(let [fmt (str " ~{~<~%~," (* n 3) ":;~2d ~>~}~%")
|
||||
counts (cons n (mapcat #(repeat 2 %) (range (dec n) 0 -1)))
|
||||
ones-and-ns (mapcat #(repeat %1 %2) counts (cycle [1 n -1 (- n)]))]
|
||||
(->> (map vector (range 0 (* n n)) (reductions + ones-and-ns))
|
||||
(sort-by second)
|
||||
(map first)
|
||||
(clojure.pprint/cl-format true fmt))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue