Skip to content

Instantly share code, notes, and snippets.

@raek
Created November 30, 2010 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raek/722136 to your computer and use it in GitHub Desktop.
Save raek/722136 to your computer and use it in GitHub Desktop.
​(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)
;; *
;; ***
;; *****
;; *******
;; *********
;; ***********
;; *************
;; ***************
;; *****************
;; *******************
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment