Hello,
In a spreadsheet I have 4 categories running vertically with 4 items in each -16 cells. (They're excersies that are grouped by type) So what I've attempted to do is create a random selector of exercises; one from each group. It will initiate using the Seconds portion of the Now function -this I did not include. My initial thought was to take 4 factorial x 4 factorial for a total of 576 permutations, but I'm not interested in all possible sequences within a combination, only the unique selection as a whole. For example; Push Up, Pull Up, Dip and Sit Up would be one unique combination and I'm not concerned with order. And so I think factorial includes order.
Anyway, what I came up with was 256 discrete combinations by comparing two groups at a time for 16 possible combinations(disregarding order), then compared those 16 versus second group of 16. Initially I tried to code it as one big ugly set of For Nexts, but realized it was an enormously daunting task.
The following works, but I wonder if anyone has a different take on combination algorithms.
Thanks.......Mickey
Dim PartCmb1(32), PartCmb2(256), Some1(4), Some2(4), Some3(4), Some4(4), Some5(4)
Dim i As Integer, j As Integer, k As Integer, m As Integer
For j = 1 To 4
Some1(j) = Worksheets("Exercise").Range("B" & j).Value
Some2(j) = Worksheets("Exercise").Range("B" & j + 4).Value
Some3(j) = Worksheets("Exercise").Range("B" & j + 8).Value
Some4(j) = Worksheets("Exercise").Range("B" & j + 12).Value
Next
k = 1
For i = 1 To 4
For j = 1 To 4
PartCmb1(k) = Some1(i) & ", " & Some2(j)
k = k + 1
Next j
Next i
For i = 1 To 4
For j = 1 To 4
PartCmb1(k) = Some3(i) & ", " & Some4(j)
k = k + 1
Next j
Next i
''''Combines fist two groups
j = 16
m = 1
For k = 1 To 16
For i = 1 To 16
PartCmb2(m) = PartCmb1(i) & ", " & PartCmb1(j)
m = m + 1
Next i
j = j + 1
Next k
For m = 1 To 256
Cells(m, 6).Value = PartCmb2(m)
Next
In a spreadsheet I have 4 categories running vertically with 4 items in each -16 cells. (They're excersies that are grouped by type) So what I've attempted to do is create a random selector of exercises; one from each group. It will initiate using the Seconds portion of the Now function -this I did not include. My initial thought was to take 4 factorial x 4 factorial for a total of 576 permutations, but I'm not interested in all possible sequences within a combination, only the unique selection as a whole. For example; Push Up, Pull Up, Dip and Sit Up would be one unique combination and I'm not concerned with order. And so I think factorial includes order.
Anyway, what I came up with was 256 discrete combinations by comparing two groups at a time for 16 possible combinations(disregarding order), then compared those 16 versus second group of 16. Initially I tried to code it as one big ugly set of For Nexts, but realized it was an enormously daunting task.
The following works, but I wonder if anyone has a different take on combination algorithms.
Thanks.......Mickey
Dim PartCmb1(32), PartCmb2(256), Some1(4), Some2(4), Some3(4), Some4(4), Some5(4)
Dim i As Integer, j As Integer, k As Integer, m As Integer
For j = 1 To 4
Some1(j) = Worksheets("Exercise").Range("B" & j).Value
Some2(j) = Worksheets("Exercise").Range("B" & j + 4).Value
Some3(j) = Worksheets("Exercise").Range("B" & j + 8).Value
Some4(j) = Worksheets("Exercise").Range("B" & j + 12).Value
Next
k = 1
For i = 1 To 4
For j = 1 To 4
PartCmb1(k) = Some1(i) & ", " & Some2(j)
k = k + 1
Next j
Next i
For i = 1 To 4
For j = 1 To 4
PartCmb1(k) = Some3(i) & ", " & Some4(j)
k = k + 1
Next j
Next i
''''Combines fist two groups
j = 16
m = 1
For k = 1 To 16
For i = 1 To 16
PartCmb2(m) = PartCmb1(i) & ", " & PartCmb1(j)
m = m + 1
Next i
j = j + 1
Next k
For m = 1 To 256
Cells(m, 6).Value = PartCmb2(m)
Next