solved problem 112 again in ruby