recursive and iterative solutions for 2 pe