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