|
-
Feb 7th, 2007, 02:58 PM
#1
Thread Starter
Lively Member
array permutation
hi,
i have a tricky problem. i have for example three arrays of different dimestion
A =[1,2,3,4]
B=[5,6,7]
C=[8,9]
i would like to generate all the different combinations of values in these arrays and the values inside the array should not be repeated.
e.g. the resultset should be
1,5,8
2,5,8
3,5,8
4,5,8
1,6,8
2,6,8
3,6,8
4,6,8
1,7,8
2,7,8
3,7,8
4,7,8
1,5,9
2,5,9
3,5,9
4,5,9
1,6,9
2,6,9
3,6,9
4,6,9
1,7,9
2,7,9
3,7,9
4,7,9
any idea how to do this for any number N of arrays?
Thanks!!
-
Feb 7th, 2007, 03:07 PM
#2
Re: array permutation
VB Code:
Dim A(1 To 4) As String
Dim B(5 To 7) As String
Dim C(8 To 9) As String
A(1) = "1"
A(2) = "2"
A(3) = "3"
A(4) = "4"
B(5) = "5"
B(6) = "6"
B(7) = "7"
C(8) = "8"
C(9) = "9"
For x = 1 To 4
For y = 5 To 7
For z = 8 To 9
Debug.Print A(x) & "," & B(y) & "," & C(z)
Next
Next
Next
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Feb 8th, 2007, 02:42 AM
#3
Thread Starter
Lively Member
Re: array permutation
Thanks for the input i figured out how to do it for a small number of cases by using FOR loops. but how would you do it if you have N arrays without having to write N FOR loops?
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|