Skip to content

Instantly share code, notes, and snippets.

@walkermatt
Created October 17, 2015 19:08
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 walkermatt/edcabb2010f7aed82c63 to your computer and use it in GitHub Desktop.
Save walkermatt/edcabb2010f7aed82c63 to your computer and use it in GitHub Desktop.
Mario style pyramids!
; Inspired by
; http://entxtech.blogspot.co.uk/2015/10/how-to-write-more-functional-and.html
; "create a program where you can enter a height in blocks for a mario-like
; pyramid (like the one Mario runs up to reach the flag-pole). Once the height
; is specified, you then build the pyramid using hashes and spaces."
; ## [0,2]
; ## [1,2]
; ### [0,3]
; ## [2,2]
; ### [1,3]
; #### [0,4]
; ## [3,2]
; ### [2,3]
; #### [1,4]
; ##### [0,5]
; ## [4,2]
; ### [3,3]
; #### [2,4]
; ##### [1,5]
; ###### [0,6]
(defn mario [h]
(map #(apply str (concat (repeat %1 " ") (repeat %2 "#"))) (reverse (range 0 h)) (range 2 (+ 2 h))))
; Draw a 12 high pyramid
(doseq [r (mario 12)] (println r))
; ##
; ###
; ####
; #####
; ######
; #######
; ########
; #########
; ##########
; ###########
; ############
; #############
; nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment