problem 9 in ruby