solved problem 30 in ruby