solved problem 35 in ruby