solveByRecursion() improved