solutoins for problems 8-10. 10 could be faster