Generating sequences of numbers

argowen

New member
Local time
Today, 17:35
Joined
Nov 28, 2008
Messages
7
I'm looking to generate a series of numbers from a range of numbers to find out all the possible out comes for example

number range 1-10
and if we wanted sequences of 3 numbers from the range they would be like

1,2,3
1,2,4
1,2,5
1,2,6
1,2,7
etc

obviously I'm looping to do this via loops but as to actually getting the numbers in that loop I can't think of a way off the top of my head, any input would be useful
 
Last edited:
You could use 3 For/Next loops nested within each other. You could also use a table with those 10 values in it in a query. With the table listed 3 times but with no join, you'd get the Cartesian product.
 
You could use 3 For/Next loops nested within each other. You could also use a table with those 10 values in it in a query. With the table listed 3 times but with no join, you'd get the Cartesian product.
I'm initially thinking it would be easier to do the loops using a 2 Dimensional array that way each permutation of the results would be help in the second portion:
example permutation 3, 5, 6 would deduce to

combination(1, 1) = 3
combination(1, 2) = 5
combination(1, 3) = 6
This way I can work with the loops a little easier.
Essentially if I were to use a number range of 1 - 10; this would theorectically mean that there is a potential 720 unique permutations without repetitions of numbers in each permutation work out as
1st N = 1 in 10, 2nd N = 1 in 9 and 3rd N = 1 in 8 thus
10 * 9 * 8 = 720 (potential number of variations)
As you can see this would need to be automated within a loop cos I'd have to be extremely bored to sit down and work them all out on paper. Besides that if I wish to extend the range say to 1 - 20, and still use 3 numbers that would all be tenfold.
Once again any comments or assistance on this would be greatly appreciated.
Thanks
 
Each number in the range would need a seed, such as

1 = 2
2 = 4
3 = 8
4 = 16
5 = 32
etc

Then you loop though the nominated range

Its a bit like working out how many double, trebles there are in a yankee bet

6 doubles
4 trebles
1 four timer

Each loop you add the seeded numbers together and check if the the summation already exists in the array
If you added the actual numerators together, such as 4+5+6 = 15 likewise 3+5+7 = 15 different permutations but same answers. No way of telling if the permutation exists or not.


So if you did 1 + 2 + 3 = 14
and 1 + 2 + 4 = 22

....
Then when you got to the 2's

2 + 1 + 3 = 14 ... Ah!! already have 14 in my array so skip this permutation.


This is only conjecture and not proven but the logic is correct.

David
 

Users who are viewing this thread

Back
Top Bottom