rewrite Ex3 and add a recursion solution to Ex3