Algorithm for you brainiacs...

  • Thread starter Thread starter FinishRich2025
  • Start date Start date
F

FinishRich2025

I am trying to break a list of up to 50 words into groups of up to
5.
Here is the example list:
Quantity Group 1 Group 2 Group 3 Group 4 Group 5 Group 6 Group 7
1 1
2 2
3 3
4 4
5 5
6 3 3
7 4 3
8 4 4
9 5 4
10 5 5
11 4 4 3
12 4 4 4
13 5 4 4
14 5 5 4
15 5 5 5
16 4 4 4 4
17 5 4 4 4
18 5 5 4 4
19 5 5 5 4
20 5 5 5 5
21 5 4 4 4 4
22 5 5 4 4 4
23 5 5 5 4 4
24 5 5 5 5 4
25 5 5 5 5 5
26 5 5 4 4 4 4
27 5 5 5 4 4 4
28 5 5 5 5 4 4
29 5 5 5 5 5 4
30 5 5 5 5 5 5
31 5 5 5 4 4 4 4
32 5 5 5 5 4 4 4
33 5 5 5 5 5 4 4
34 5 5 5 5 5 5 4
35 5 5 5 5 5 5 5

As you can see, I don't want a bunch of full groups (of 5) and groups
of 1 or 2. I want to even them out as much as possible.

I know there must be a mathmatical pattern to this, so if anyone can
point me in the right direction, I would greatly appreciate it. For
now, I am just going to write a bunch of case statements.

Thanks !!
 
Right off, I'm not seeing a consistent "rule" until after you hit Qty = 12.
Before that, it looks like a group could have 3 or 4 or 5.

Have you considered using a more consistent rule? Maybe something like:

* minimum of 3 in a group (add another if less than 3)
* add 1 to the 'next' group after previous group hits 3
* when all groups have 3, start over and add 1 to each group
* when all groups have 4, start over and add 1 to each group

Just a thought...

--

Regards

Jeff Boyce
Microsoft Access MVP

Disclaimer: This author may have received products and services mentioned in
this post. Mention and/or description of a product or service herein does
not constitute endorsement thereof.

Any code or psuedocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
Unfortunately, I am not making the rules. As it is, I figured I would
have to use seperate entries up to 11, then it looks like there is a
pattern. I am just using case statements for each one now. I thought
that if someone figured it out I would change it later so I could
handle an unlimited number of groups and have cleaner code.

Thanks !!
 
Back
Top