solved problem 74 in ruby