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