solved problem 11 in ruby