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