Solved problem 11 in ruby