Skip to content

Instantly share code, notes, and snippets.

(fn [l u]
(let [s (apply str (take-while #(<= % u) (iterate #(* % %) l)))
d (int (Math/ceil (Math/sqrt (count s))))
n (concat (seq s) (repeat (- (* d d) (count s)) \*))
m (loop [m {} sx n
r (if (even? d) (- d 2) (dec d)) c (- d 1)
dr (mapcat #(repeat (* % 2) (if (even? %) -1 1)) (range))
dc (mapcat #(repeat (inc (* % 2)) (if (even? %) 1 -1)) (range))]
(if (empty? sx) m
(recur (assoc m [r c] (first sx)) (rest sx)
(fn [s e]
(let [squares (apply str (take-while #(<= % e) (iterate #(* % %) s)))
filler (drop (count squares) (repeat (#(* % %) (Math/ceil (Math/sqrt (count squares)))) \*))
elements (concat squares filler)
dimension (int (Math/sqrt (count elements)))
cardinal (- (* 2 dimension) 1)
canvas (vec (repeat cardinal ""))
start-pos (* 2 (quot (dec dimension) 2))
path (take (count elements) (mapcat #(repeat (+ 2 (* 2 %)) (if (odd? %) dec inc)) (range)))
balance (fn [c] (#(apply str `(~@% ~@(interpose \ c) ~@%)) (repeat (/ (- cardinal (- (* 2 (count c)) 1)) 2) \ )))]
;; ummels's solution to Squares Squared
;; https://4clojure.com/problem/138
(fn [start end]
(letfn
[(squares [start end]
(take-while #(<= % end) (iterate #(* % %) start)))
(arrange [x]
(let [n (count x)
dim (int (Math/ceil (Math/sqrt n)))
;; ummels's solution to Palindromic Numbers
;; https://4clojure.com/problem/150
(fn [n]
(letfn [(decode [n] (if (< n 10) [n] (conj (decode (quot n 10)) (rem n 10))))
(encode [x] (reduce #(+ (* % 10) %2) 0 x))
(next-pal [n]
(let [N (decode n)
l (count N)
d (quot l 2)