solved problem 6 again in ruby