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