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