solved problem 34 in ruby