first draft answer for problem 3 in ruby