in reply to Puzzle: need a more general algorithm
To distribute N categories across M columns as evenly as possible, assuming N >= M, observe that
- (N mod M) columns will contain ((N div M) + 1) categories
- the remaining (M - (N mod M)) columns, if any, will contain (N div M) categories.
Given this, categories can be distributed in one pass.
Update: Oh blast. I may have misread the problem, and confused the "height of the table in rows" with "the aggregate height summed from the @height data".
In Section
Seekers of Perl Wisdom