logic design flow help needed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Xenophobe

    logic design flow help needed

    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!


  • Pedro Graca

    #2
    Re: logic design flow help needed

    Xenophobe wrote:[color=blue]
    > 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.[/color]

    I suggest you try comp.programmin g where you certainly will get better
    and more detailed methods.


    I'd probably try some thing like this:

    1) query table ordered alphabetically with an extra 'zero' column
    2) iterate the data updating extra column with number of previous
    repetitions, so you get

    apple 0
    apple 1
    apple 2
    banana 0
    orange 0
    orange 1
    pear 0
    peach 0

    2a) reorder by repetitions then name, so you get

    apple 0
    banana 0
    orange 0
    pear 0
    peach 0
    apple 1
    orange 1
    apple 2

    3) 4) and 5) same as yours 3) 4) and 5)
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    • Mike Peters

      #3
      Re: logic design flow help needed

      On 2004-02-26, Xenophobe wrote:[color=blue]
      >
      > 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)
      >[/color]

      Would it not be possible to use two arrays fruitbasket[] and
      fruitnobasket[]?
      [color=blue]
      > 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
      >[/color]
      It would seem to make this part easier.
      [color=blue]
      > The next basket distribution iteration looks like this:
      >
      > basket1: peach
      > basket2: apple
      > basket3: banana
      > basket4: orange
      > basket5: pear
      > apple (no basket)
      >[/color]

      or what about an associative array:
      fruit[b1] = peach
      fruit[b2] = apple
      ..
      ..
      fruit[b5] = pear
      fruit[nb1] = apple
      [color=blue]
      > ...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?
      >[/color]
      As far as the information you've given goes only one query is needed
      unless the data in your table is likely to change at any point in the
      process. It would seem easier to manipulate the array or arrays.

      --
      Mike Peters
      mike [-AT-] ice2o [-DOT-] com
      I am a DevOps and Cloud architecture consultant based in Northumberland in the UK. I provide consultancy on DevOps and private and public cloud solutions. I design and implement continous integration and continuous delivery solutions using Open Source, bespoke and commercial off the shelf software. I can also provide training and tuition for you or your team in DevOps best practices, tooling and solutions, OpenSource software, automation and cloud architecture solutions.

      Comment

      Working...