solved problem 22 again in ruby