Solve problem 10 using Ruby.