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