Created
October 17, 2015 19:08
-
-
Save walkermatt/edcabb2010f7aed82c63 to your computer and use it in GitHub Desktop.
Mario style pyramids!
This file contains hidden or 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
; 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