Adding solution to problem 10 in ruby