http://www.perlmonks.org?node_id=180296


in reply to Puzzle: need a more general algorithm

Three possibilities:
  1. More columns than categories
  2. Equal
  3. More categories than columns
The first is insoluble. The second is trivial. The third is interesting.

In the third, just combine neighboring categories into a "super-category" and re-evaluate.

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.