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