I'm having a brain freeze on how to go about creating the logic for
evenly distributing a group of items in rotation through multiple
iterations. I'm particularly looking for logic flow help and not
necessarily syntax examples.
Let's say we have a database table with the following pieces of fruit:
apple
apple
banana
orange
pear
peach
First off, I need to move any duplicate pieces of fruit to the end of
the list:
apple
banana
orange
pear
peach
apple
Note the second apple goes to the back of the line.
Now let's say there's 5 baskets to distribute the fruit in. Each basket
can only contain one unique piece of fruit at a time. So on the first
iteration the baskets look like this:
basket1: apple
basket2: banana
basket3: orange
basket4: pear
basket5: peach
apple (no basket)
I now need to shift every piece of unique fruit up by one, bringing the
5th piece to the front of the line. Note that second apple stills stays
at the back of the line because it's a duplicate.
peach
apple
banana
orange
pear
apple
The next basket distribution iteration looks like this:
basket1: peach
basket2: apple
basket3: banana
basket4: orange
basket5: pear
apple (no basket)
....and so on. The second apple would only be added to the rotation if 1)
one of the pieces of fruit gets eaten (deleted) OR 2) a sixth basket is
added to the rotation.
Here's the flow.
1) query table for data, ORDER BY fruit (alphabetically )
2) loop through recordset array and move any duplicates to the back
(exp. compare 1 with 2, if 2 equals 1, move 2 to the end)
3) distribute fruit in baskets
4) move fruit 1 to the back, but ahead of the duplicates
5) go to step 3
How much of the sorting (and resorting) requirements can be done in the
query? Would it be easier to re-query on each iteration or manipulate
the existing recordset array?
Any input would be greatly appreciated.
Thanks!
evenly distributing a group of items in rotation through multiple
iterations. I'm particularly looking for logic flow help and not
necessarily syntax examples.
Let's say we have a database table with the following pieces of fruit:
apple
apple
banana
orange
pear
peach
First off, I need to move any duplicate pieces of fruit to the end of
the list:
apple
banana
orange
pear
peach
apple
Note the second apple goes to the back of the line.
Now let's say there's 5 baskets to distribute the fruit in. Each basket
can only contain one unique piece of fruit at a time. So on the first
iteration the baskets look like this:
basket1: apple
basket2: banana
basket3: orange
basket4: pear
basket5: peach
apple (no basket)
I now need to shift every piece of unique fruit up by one, bringing the
5th piece to the front of the line. Note that second apple stills stays
at the back of the line because it's a duplicate.
peach
apple
banana
orange
pear
apple
The next basket distribution iteration looks like this:
basket1: peach
basket2: apple
basket3: banana
basket4: orange
basket5: pear
apple (no basket)
....and so on. The second apple would only be added to the rotation if 1)
one of the pieces of fruit gets eaten (deleted) OR 2) a sixth basket is
added to the rotation.
Here's the flow.
1) query table for data, ORDER BY fruit (alphabetically )
2) loop through recordset array and move any duplicates to the back
(exp. compare 1 with 2, if 2 equals 1, move 2 to the end)
3) distribute fruit in baskets
4) move fruit 1 to the back, but ahead of the duplicates
5) go to step 3
How much of the sorting (and resorting) requirements can be done in the
query? Would it be easier to re-query on each iteration or manipulate
the existing recordset array?
Any input would be greatly appreciated.
Thanks!
Comment