solved problem 12 again in ruby