in reply to Puzzle: need a more general algorithm
O.K., I may have misread this problem at first because "height" is somewhat ambigous. If "height" somehow refers to the aggregation of the data, here's another approach.
Given the constraints, I count 10 possible groupings:
So my approach two is to brute force sum the values for each possible combination, and select the one that best meets the criteria about "height".[1][2][3][4,5,6] [1][2][3,4][5,6] [1][2][3,4,5][6] [1][2,3][4][5,6] [1][2,3][4,5][6] [1][2,3,4][5][6] [1,2][3][4][5,6] -- the one you show [1,2][3][4,5][6] [1,2][3,4][5][6] [1,2,3][4][5][6]
Then, assuming that works, I'd generalize an algorithm for generating groupings given number of categories and number of columns. Like the one fglock provides above.
Is this what you're looking for, or does "height" refer to the number of rows in the table?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Puzzle: need a more general algorithm
by dws (Chancellor) on Jul 08, 2002 at 23:49 UTC |
In Section
Seekers of Perl Wisdom