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