Problem 1 in ruby