solved problem 7 again in ruby