solved problem 89 in ruby