Solve problem 46 using Ruby.