solved problem 13 in ruby