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