Iterating through 10! combinations (1 Viewer)

John Big Booty

AWF VIP
Local time
Today, 09:29
Joined
Aug 29, 2005
Messages
8,263
I have ten records each of which can be assigned a value from one to ten, but no two records can hold the same value so there are ten factorial combination.

What I need to do is come up with a procedure to iterate through each of those 10! combinations (yes that's 3,628,800). I'm having trouble getting my head around the logic to do this, so any help or suggestions will be gratefully accepted :eek:

As back ground each record represents a row in a grid and each the value held in that record represents the column in the grid, and the combination of the record and the value it holds will give me the address of a cell in the grid that hold a numeric value.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 09:29
Joined
Jan 20, 2009
Messages
12,851
Random thoughts only :

Use ten variables and iterate through each in nested loops counting down from ten.
The subloops should stop when they get to 1

j = 10
For z = j To 1 Step -1
For y = z -1 To 1 Step -1
etc

intIndex = z*y*x*w*v*u*t*s*r*q

myBigArray(intIndex) = whatever
 

John Big Booty

AWF VIP
Local time
Today, 09:29
Joined
Aug 29, 2005
Messages
8,263
Thanks, I'll have a play with that :)
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 00:29
Joined
Sep 12, 2006
Messages
15,651
JBB - try this thread - the general solution for evaluating combinations and permutations is to use recursion ...

combine n items by taking 1 items and then applying the combine function to the remaining n-1 items.

ie - if you have 10 items, but want to select every group of 6 items from those 10 -
the general formula is n! /( (n-r)! * r! ) - where n is no of items, and r is no to be selected

there is also something in the code/sample library on the same topic, started by ajetrumpet, which I put similar stuff in.

http://www.access-programmers.co.uk/forums/showthread.php?t=205563&highlight=permutations


if you are sure you want every combination, then G's idea will obviously work for this special case.
 
Last edited:

Users who are viewing this thread

Top Bottom