There's a very simple iterative method.
There's an even simpler recursive method.

Recursion is good for certain things... IMHO it's easier to use a recursive solution here... but hey, we're all entitled to our opinion .

U.