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