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