This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) \ )))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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) |
NewerOlder