Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrangement of numbers in Excel or any other program 3

Status
Not open for further replies.

tyant

Programmer
Jun 1, 2001
68
AU
I need to arrange 6 numbers in different orders but they can not repeat.

E.g
there are 6 numbers. 1 to 6
6,5,4,3,2,1 is one arrangement
5,4,6,3,2,1 ia another

There is a total of 720 different arrangements
Is there anyway of get all the arrangements
B-)
 
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

FailTest:

Next T

End Sub
 
Thanks alot.
Its not a homework assignment, its just not my field.
Thanks
 
Hi JV,

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.

THANKS!
 
So....... you can modify the code for this, or do you want me to look into it ?

In your 2), what is the maximum length of numeric string?
 
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.

TIA
 
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 ?

Sounds like a tough problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top