solved problem 3 again in ruby