Solve problem 5 using Ruby.