Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,8 +1,16 @@
|
|||
(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))
|
||||
(let [cyc (cycle [1 n -1 (- n)])]
|
||||
(->> (range (dec n) 0 -1)
|
||||
(mapcat #(repeat 2 %))
|
||||
(cons n)
|
||||
#(mapcat repeat % cyc)
|
||||
(reductions +)
|
||||
(map vector (range 0 (* n n)))
|
||||
(sort-by second)
|
||||
(map first)
|
||||
(clojure.pprint/cl-format true fmt))))
|
||||
(map first)))
|
||||
|
||||
(let [n 5]
|
||||
(clojure.pprint/cl-format
|
||||
true
|
||||
(str " ~{~<~%~," (* n 3) ":;~2d ~>~}~%")
|
||||
(spiral n)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue