hello to all
I am working an a project that requires me to work with a very large number of tables, each showing ALL of the permutations of of 10 distinct positive integers. Each table has 10! = 3,628,800 records (because the 1st value can be selected in 10 ways, the 2nd in 9 ways, the 3rd in 8 ways, etc.)
I use SQL to generate the records and INSERT them INTO a table, analyse the results, delete the records, then repeat with the next set of 10 distinct positive integers. To fill the table with its 3,628,800 records takes me just over 6 minutes of computing time. For what its worth, I'm using SQL as below. (Because of space limitations, I'm showing how the SQL would look if there were only 5 positive integers to work with, not 10.)
Here is my question. Since every set of permutations is based on 10 distinct values, I should be able to fill one table, then complete ALL other tables by using SUBSTITUTION. For example ...
if Tbl1 is based on the values 2, 6, 23, 1, 78, 33, 44, 55, 66, 77,
and Tbl2 is based on the values 8, 9, 12, 13, 14, 3, 65 ,54 ,43 ,32...
... then I should be able to build Tbl1's 3,628,800 records, then produce Tbl2 by substituting all values of 2 in Tbl1 with 8, all values of 6 with 9, all values of 23 with 12, etc.
This could be a gigantic time saver, but I don't know how to do bulk replacements. In any given table, each value occurs 10! times, so this goes way beyond the limits of a Window's Search/Replace. Does anyone have any suggestions as to a good way to proceed?
Thank you for any thoughts
Vicky C.
A further thought: It might even be best to compute a master permutation table using, say, the 10 values... -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, and then fill all the actual working tables by substitution. But I'm really stuck on how to do bulk replacements???
I am working an a project that requires me to work with a very large number of tables, each showing ALL of the permutations of of 10 distinct positive integers. Each table has 10! = 3,628,800 records (because the 1st value can be selected in 10 ways, the 2nd in 9 ways, the 3rd in 8 ways, etc.)
I use SQL to generate the records and INSERT them INTO a table, analyse the results, delete the records, then repeat with the next set of 10 distinct positive integers. To fill the table with its 3,628,800 records takes me just over 6 minutes of computing time. For what its worth, I'm using SQL as below. (Because of space limitations, I'm showing how the SQL would look if there were only 5 positive integers to work with, not 10.)
Code:
'Actual code uses 10 values, not 5
INSERT INTO tbl_Perms
SELECT DISTINCT Q.V4, Q.V3, Q.V2, Q.V1, Q.V0
FROM
(
SELECT T4.V AS V4, T3.V AS V3, T2.V AS V2, T1.V AS V1, T0.V AS V0
FROM tbl_Vals AS T4, tbl_Vals AS T3, tbl_Vals AS T2, tbl_Vals AS T1, tbl_Vals AS T0
WHERE
(
(T4.V<>T3.V And T4.V<>T2.V And T4.V<>T1.V And T4.V<>T0.V) And
(T3.V<>T2.V And T3.V<>T1.V And T3.V<>T0.V) And
(T2.V<>T1.V And T2.V<>T0.V) And
(T1.V<>T0.V)
)
) AS Q
ORDER BY Q.V4, Q.V3, Q.V2, Q.V1, Q.V0;
Here is my question. Since every set of permutations is based on 10 distinct values, I should be able to fill one table, then complete ALL other tables by using SUBSTITUTION. For example ...
if Tbl1 is based on the values 2, 6, 23, 1, 78, 33, 44, 55, 66, 77,
and Tbl2 is based on the values 8, 9, 12, 13, 14, 3, 65 ,54 ,43 ,32...
... then I should be able to build Tbl1's 3,628,800 records, then produce Tbl2 by substituting all values of 2 in Tbl1 with 8, all values of 6 with 9, all values of 23 with 12, etc.
This could be a gigantic time saver, but I don't know how to do bulk replacements. In any given table, each value occurs 10! times, so this goes way beyond the limits of a Window's Search/Replace. Does anyone have any suggestions as to a good way to proceed?
Thank you for any thoughts
Vicky C.
A further thought: It might even be best to compute a master permutation table using, say, the 10 values... -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, and then fill all the actual working tables by substitution. But I'm really stuck on how to do bulk replacements???