Tuesday, April 22, 2008

Ruby Golf: ASCII Sierpinski Triangle

For wide terminals:

ruby -le '64.times{|y|print" "*(63-y),(0..y).map{|x|~y&x>0?" .":" A"}}'

For thin terminals:

ruby -le '33.times{|y|print" "*(32-y),(0..y).map{|x|~y&x>0?" .":" A"}}'

A classic fractal, via Brian Mitchell. I have no idea how it works. In a weird inversion of my usual pattern, I know the math but I can't figure out the code.