Solve problem 8 using Ruby.