Subj : Re: efficient way of processing m combinations of n numbers in p sets To : comp.programming From : Willem Date : Tue Aug 16 2005 12:02 pm Mike wrote: ) Hi, ) ) ) I am trying to process all combinations of 6 sets of numbers (using ) VB). The ) minimum number in each set will be 2 and the maximum number is ) ) The way I am running it at the moment is 6 nested for loops as in the ) following: ) ) ) The problem I have is that as soon the maximum number is set too high ) or the increment is too low, the number of calculations increases ) exponentially and the pc freezes. Ideally I am looking to perform ) these types of calculations in under 2 seconds. The ideal ranges would ) be from 2 to 50 in each set with an increment of 0.1, so 2, 2.1, ) 2.2....up to 50. Have you worked out how many calculations that would be ? A range from 2 to 50 with steps of 0.1 would mean roughly 500 different numbers. With 6 different ranges that's 500 to the power of 6, or about fifteen quadrillion calculations. To do that in under two seconds, you would have to do fifteen million calculations per nanosecond. ) I would be really grateful if someone could offer some advice on how to ) perform these calculations in a more efficient manner. For example, ) would placing all possibilities into an array first and then performing ) calculations at the end offer any improvements? No. It would degrade performance considerably. ) My final question is would it be possible to vary the number of for ) loops involved e.g. in the above example, if I only had 3 sets of ) numbers I would only need 3 for loops to work through all of the ) possibilities. Yes, that's possible. Make a single while-loop that works like an odometer, updating the innermost variable, and when that reaches the maximum, reset it and update the nextmost and so on. But what kind of calculations do you want to do ? The number of combinations is untangible for any serious range. SaSW, Willem -- Disclaimer: I am in no way responsible for any of the statements made in the above text. For all I know I might be drugged or something.. No I'm not paranoid. You all think I'm paranoid, don't you ! #EOT .