Consider using the % operator.
Recursion in this instance is very poor, because there is no clear exit condition and it may take a very long time (and thus a large amount of stack - perhaps too much) before you get the result you want.
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Offline 7,164 posts
since Dec 2005