Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Puzzle: need a more general algorithm

by dws (Chancellor)
on Jul 08, 2002 at 20:57 UTC ( #180323=note: print w/replies, xml ) Need Help??

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:

[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]
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".

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
    Here's an observation that might lead to a quick way to determine unique bucket combinations.

    The set of bucket sizes above is the union of two sets: the set of all unique arrangements of (1 1 1 3), and the set of all unique arrangements of (1 1 2 2). The sum of the numbers is equal to the number of catagories. This can be generalized to cover different numbers of buckets and different numbers of categories.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://180323]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (1)
As of 2023-03-22 18:55 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.