Guest User

Untitled

a guest
Jul 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. ​(defn star-seq []
  2. (iterate #(str % "**") "*"))
  3.  
  4. (defn pad [s n]
  5. (let [spaces (repeat (/ (- n (count s)) 2) \space)]
  6. (apply str (concat spaces s))))
  7.  
  8. (defn print-pyramid [n]
  9. (let [stars (take n (star-seq))
  10. width (count (last stars))
  11. padded-stars (map #(pad % width) stars)]
  12. (doseq [row padded-stars]
  13. (println row))))
  14.  
  15. ;; user=> (print-pyramid 10)
  16. ;; *
  17. ;; ***
  18. ;; *****
  19. ;; *******
  20. ;; *********
  21. ;; ***********
  22. ;; *************
  23. ;; ***************
  24. ;; *****************
  25. ;; *******************
Add Comment
Please, Sign In to add comment