solved problem 24 again in ruby