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