Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
16
Task/Spiral-matrix/Clojure/spiral-matrix-1.clj
Normal file
16
Task/Spiral-matrix/Clojure/spiral-matrix-1.clj
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
(defn spiral [n]
|
||||
(let [cyc (cycle [1 n -1 (- n)])]
|
||||
(->> (range (dec n) 0 -1)
|
||||
(mapcat #(repeat 2 %))
|
||||
(cons n)
|
||||
(mapcat #(repeat %2 %) cyc)
|
||||
(reductions +)
|
||||
(map vector (range 0 (* n n)))
|
||||
(sort-by second)
|
||||
(map first)))
|
||||
|
||||
(let [n 5]
|
||||
(clojure.pprint/cl-format
|
||||
true
|
||||
(str " ~{~<~%~," (* n 3) ":;~2d ~>~}~%")
|
||||
(spiral n)))
|
||||
8
Task/Spiral-matrix/Clojure/spiral-matrix-2.clj
Normal file
8
Task/Spiral-matrix/Clojure/spiral-matrix-2.clj
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(defn spiral-matrix [m n & [start]]
|
||||
(let [row (list (map #(+ start %) (range m)))]
|
||||
(if (= 1 n) row
|
||||
(concat row (map reverse
|
||||
(apply map list
|
||||
(spiral-matrix (dec n) m (+ start m))))))))
|
||||
|
||||
(defn spiral [n m] (spiral-matrix n m 1))
|
||||
Loading…
Add table
Add a link
Reference in a new issue