solved problem 28 in ruby