Skip to content

Instantly share code, notes, and snippets.

@mveytsman
Last active August 29, 2015 14:11
Show Gist options
  • Save mveytsman/c03eceb1b02e1eeb3903 to your computer and use it in GitHub Desktop.
Save mveytsman/c03eceb1b02e1eeb3903 to your computer and use it in GitHub Desktop.
Sierpinsky Triangle
(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))
@mveytsman
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment