solved problem 47 again in ruby