solved problem 52 again in ruby