solved problem 49 again in ruby