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