Solution to level 6 in Untrusted: http://alex.nisnevich.com/untrusted/