Algorithm HELP!

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2007
Posts: 6
Reputation: student101110 is an unknown quantity at this point 
Solved Threads: 0
student101110 student101110 is offline Offline
Newbie Poster

Algorithm HELP!

 
0
  #1
Nov 29th, 2007
Hi guys. Im a student and i have a problem in finding the right procedure to solve my problem. Giving a set of numbers that will find their combination for a given value. For example 1st digit will be the size and the 2nd digit will be the qty.:

Size qty
10 10
20 10
30 10
40 10
50 10
60 10
70 10
80 10
90 10
100 10

the problem will be, I’ll find the 1 to 5 combinations to have a sum of 100:
the answers will be like the following:


100 10
90+10 10
80+20 10
70+30 10
40+60 10
50+50 5

the answers is only 1 and 2 combinations. I would like to create a procedure that will compute up to 5 combinations and will check the qty is still available for combining into another size. the problem is my function becomes very slow when im trying to manipulate it using string handling functions. Any input that will enlighten my mind will be a great help. Thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 47
Reputation: locsin is an unknown quantity at this point 
Solved Threads: 0
locsin locsin is offline Offline
Light Poster

Re: Algorithm HELP!

 
0
  #2
Nov 29th, 2007
Please specify the total number of sequence (ex.. 1 to totalnumberofsequence) if the total number of sequence is base on the input try this systax

Dim input as integer
dim algo as integer
dim cnt as integer
dim combo as integer

'no of sequence
algo = 0
for cnt = 1 to input
algo = algo + input
? algo, input
next cnt

'finding the combination
cnt = 0
combo = algo
algo = algo - input
while combo = algo
cnt = cnt + 1
combo = (algo + input)
input = input + input

loop

' cnt is the total number of combination
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 6
Reputation: student101110 is an unknown quantity at this point 
Solved Threads: 0
student101110 student101110 is offline Offline
Newbie Poster

Re: Algorithm HELP!

 
0
  #3
Dec 2nd, 2007
thanks for the input locsin. i already created a function that will loop (1 to 5 comb) to combine the given set of numbers. the problem is im having trouble with getting the difference of the qty. for example:

---------------------------------------
combination requirement= 400

size 100+90+80+70+60

qty respectively 10,9,8,7,6

ANS:

6 set for 100+90+80+70+60

qty respectively 4,3,2,1,0

---------------------------------------

this sample is easy to compute coz of theres no redundant size have been combined. the next example will be a little bit of complicated:

----------------------------------------
combination requirement= 400

size 100+100+90+80+30

qty respectively 10,10,11,12,13

ANS:

5 sets for 100+100+90+80+30

qty respectively 0,0,6,7,8
------------------------------------------

the problem is, am having trouble with getting the difference of the qty. for now, im using a string handling function for computation of combinations but reducing the qty is my main problem using that function( ex. sorting the qty and determining the lowest qty to be the set size). can someone suggest an idea that will help me to solve my problem? thanks all.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 6
Reputation: student101110 is an unknown quantity at this point 
Solved Threads: 0
student101110 student101110 is offline Offline
Newbie Poster

Re: Algorithm HELP!

 
0
  #4
Dec 2nd, 2007
btw, im using a two dimensional array to manipulate my string. is there any function in vb that i can store my var and automaticaly sort them?
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 6
Reputation: student101110 is an unknown quantity at this point 
Solved Threads: 0
student101110 student101110 is offline Offline
Newbie Poster

Re: Algorithm HELP!

 
0
  #5
Dec 6th, 2007
up
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC