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