my attempt at the final problem of this: http://www.hpcodewars.org/past/cw17/problems/2014HPCodeWarsFinalProblemsPost.pdf