Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn star-seq []
- (iterate #(str % "**") "*"))
- (defn pad [s n]
- (let [spaces (repeat (/ (- n (count s)) 2) \space)]
- (apply str (concat spaces s))))
- (defn print-pyramid [n]
- (let [stars (take n (star-seq))
- width (count (last stars))
- padded-stars (map #(pad % width) stars)]
- (doseq [row padded-stars]
- (println row))))
- ;; user=> (print-pyramid 10)
- ;; *
- ;; ***
- ;; *****
- ;; *******
- ;; *********
- ;; ***********
- ;; *************
- ;; ***************
- ;; *****************
- ;; *******************
Add Comment
Please, Sign In to add comment