solved problem 30 in swift