problem 3 in ruby