Code Golf: New Year Tree

Let's celebrate geeky New Year by drawing New Year Tree using Clojure!


Write a program which prints New Year Tree to console.
Source code should take as small number of characters as possible.

I came up with the following tree rules:

So, the function signature is following:

(fn [level ratio])


(fn[l r](let[p print n println e range m(reduce + 2(e(+ l 1)))
f(fn[w n](dotimes[i n](p(if(fn? w)(w)w))))d #(f(fn[]
(if(<(rand)r)\o\ ))%)](f" "m)(n\★)(doseq[b(e l)h(e(+ b 3))
:let[u(quot(*(+ b 1)b)2)a(=(+ b 2)h)t(+ h h u u 1)]]
(f\ (- m h u 1))(p\/)(cond(and(=(+ b 1)l)a)(f"_"t)
a(do(p\_)(d(- t 2))(p\_))1(d t))(n\\))
(dotimes[i 2](f\ (- m 1))(n"| |"))))

348 characters in Clojure.


P.S. Later I realized we could reuse symmetry property of the tree to make program more compact.

mishadoff 07 January 2016
blog comments powered by Disqus