Got my first selected answer on stackoverflow! I waited several days to post the full solution, in case the competition in question was still running. My hope was that people would down vote his question if that was the case.
My solution isn't elegant, but I thought it was a nice example of a recursive function that goes beyond the factorial function you normally see. Ok, it isn't really a good example of recursion. It is an example of using tail recursion to eliminate mutable variables that you would use in a while loop. Oh well.