473,780 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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!
Jul 17 '05 #1
2 2036
Xenophobe wrote:
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.


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 =--
Jul 17 '05 #2
On 2004-02-26, Xenophobe wrote:

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)

Would it not be possible to use two arrays fruitbasket[] and
fruitnobasket[]?
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
It would seem to make this part easier.
The next basket distribution iteration looks like this:

basket1: peach
basket2: apple
basket3: banana
basket4: orange
basket5: pear
apple (no basket)

or what about an associative array:
fruit[b1] = peach
fruit[b2] = apple
..
..
fruit[b5] = pear
fruit[nb1] = apple
...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?

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
http://www.ice2o.com
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
28327
by: Thiko | last post by:
I have a sql server automatic job set up containing 2 steps. First step is an Operating System Command (CmdExec) type job which runs a .bat file which copies across a backup file to this machine. The second step is a Transact -SQL Script (TSQL) type job which runs the RESTORE DATABASE REPLACE command which restores the backup file copied across in step 1. Step 1's advanced option says: On Success Action: Goto Step
2
3549
by: Pete | last post by:
Before I get started with the question, does anyone have a (single) good book recommendation for database design? Not an Access-specific book, but something geared toward helping me figure out *what the user wants*. I've had brief formal education about data flow diagramming, but I'm looking for ... more, now that I'm actually running into problems I think stem from the fact that my users can't explain what they need done, compounded by...
8
1454
by: - | last post by:
Hi to All, To reproduce: The expression: object result = flag ? (long) 0 : (double) 0; always evaluated as a double... see dissassembly to ensure the bad compiled code.
17
2717
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but know nothing about ASP. He can build the design of the pages in HTML with tables, labels, textboxes etc. But then I would need to change them to ASP.net objects and write the code to make the page work (normally I do this as I go - can't do this...
6
2009
by: Simon Harvey | last post by:
Hi everyone, We have a need to make a Windows Forms (2.0) client application that will be installed on our clients site. The data that the application uses needs to be centrally available to a potentially large number of other sites, which would seem to leave us with our traditional approach, or having a central database server on a dedicated server someplace.
15
2581
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to determine who needs to receive the text message then send the message to the address. Only problem is, the employee may receive up to 4 of the same messages because each thread gets the recors then sends the message. I need somehow to prevent...
10
2314
by: Frank van Wensveen | last post by:
Friend, coders, fellow wage slaves, lend my your ears. I believe that in a perfect world the design of a website (or feature on a website) should be totally separated from its design and the data it serves up. I'd like some suggestions on good ways to do this, because in the real world it can be quite difficult. For example, if I'm rummaging around in a MySQL database, the table structure and the code that generates the SQL requests...
5
6028
by: salberts | last post by:
Hi, I am writing an application that has its UI and Logic layers. My initial idea was to launch the two layers on two different threads and manage calls made by the UI to the Logic manually. Which means handling the Sleep/Wakeup of the logic thread all by myself. This looks reasonable to me in the way that the UI and the Logic run separately and only send messages to each other. The main disadvantage of thos method is that I have to...
6
2166
by: traineeirishprogrammer | last post by:
I am currently a real newbe in the world of PHP and webdesign in general. I currently writing my first PHP application. Although unfortunately I did not plan it out. I need to know what is the best way to design web applications. Just a few tips will do. Maybe if I show you all an example (not finished) this may help you to understand what I mean a little better. <? require_once('../config/Dbconnector.php');
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9931
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.