Last active
August 29, 2015 14:11
-
-
Save mveytsman/c03eceb1b02e1eeb3903 to your computer and use it in GitHub Desktop.
Sierpinsky Triangle
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
(defn sierpinsky [n] | |
(if (= 0 n) | |
["*"] | |
(let [down (sierpinsky (- n 1)) | |
space (apply str (repeat (Math/pow 2 (- n 1)) " "))] | |
(concat (map #(apply str space % space) down) | |
(map #(clojure.string/join " " (repeat 2 %)) down))))) | |
(map println (sierpinsky 4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Port of this http://rosettacode.org/wiki/Sierpinski_triangle#Haskell