Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View 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)))

View 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))