Created
November 30, 2010 18:33
-
-
Save raek/722136 to your computer and use it in GitHub Desktop.
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
(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