refactor problem 18
solve problem 67