a recursive solution