solved problem 16 again in ruby