solved problem 5 again in ruby