question 2 solved inelegently, come back with better solution
solution to question 3 - could be improved by recursion