solved problem 45 again in ruby