No takers on this one ??? After looking into it, I'm not surprised !! What a problem for a Friday.
I can hear my statistics teacher groan in his grave at my technique, but the following code DOES WORK.
Sub FactorialLoop()
For T = 1 To 654321
MyStr = Format(T, "000000"
For C = 1 To 6
If Mid(MyStr, C, 1) = 0 Then GoTo FailTest ' Toss out zeros
If Mid(MyStr, C, 1) > 6 Then GoTo FailTest ' Toss out > values
' Check for duplicate integers
If Mid(MyStr, 1, 1) = Mid(MyStr, 2, 1) Then GoTo FailTest
If Mid(MyStr, 1, 1) = Mid(MyStr, 3, 1) Then GoTo FailTest
If Mid(MyStr, 1, 1) = Mid(MyStr, 4, 1) Then GoTo FailTest
If Mid(MyStr, 1, 1) = Mid(MyStr, 5, 1) Then GoTo FailTest
If Mid(MyStr, 1, 1) = Mid(MyStr, 6, 1) Then GoTo FailTest
If Mid(MyStr, 2, 1) = Mid(MyStr, 3, 1) Then GoTo FailTest
If Mid(MyStr, 2, 1) = Mid(MyStr, 4, 1) Then GoTo FailTest
If Mid(MyStr, 2, 1) = Mid(MyStr, 5, 1) Then GoTo FailTest
If Mid(MyStr, 2, 1) = Mid(MyStr, 6, 1) Then GoTo FailTest
If Mid(MyStr, 3, 1) = Mid(MyStr, 4, 1) Then GoTo FailTest
If Mid(MyStr, 3, 1) = Mid(MyStr, 5, 1) Then GoTo FailTest
If Mid(MyStr, 3, 1) = Mid(MyStr, 6, 1) Then GoTo FailTest
If Mid(MyStr, 4, 1) = Mid(MyStr, 5, 1) Then GoTo FailTest
If Mid(MyStr, 4, 1) = Mid(MyStr, 6, 1) Then GoTo FailTest
If Mid(MyStr, 5, 1) = Mid(MyStr, 6, 1) Then GoTo FailTest
Next C
R = R + 1 ' Counter
ActiveSheet.Rows(R).Columns(1) = T ' Write result to spreadsheet
Thanks very much also. It saved me from "wracking my brain" in attempting to come up with a solution. Definitely worth another STAR. ...Dale Watson
JV, thanks for that gem. I have been lookin for this for a while. However I need two variables, 1)The option to count the same digit twice (eg, ABCADEF, A SHOULD optionally be included twice), and 2)The length of the string/number varies.
JV, I couldn't modify your solution because I'm afraid that due to the max length and type(alpha), 18 ALPHA-numeric placeholders, your formula kinda a gets outta hand<g>. I tried to place a couple of nested loops but I keep on getting tripped up.
Would that be something like testing 18! = 6,402,373,705,728,000 numbers ? No, actually it would be more, the alpha can be 26 possibilities instead of 10, so 18! is not nearly enough.
You need to know the unique combinations of an 18 digit alpha string, with only 1 character repeating ?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.