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