solved problem 10 in swift