Solved 9 in ruby