5 Replies - 3687 Views - Last Post: 16 September 2009 - 10:01 AM Rate Topic: -----

#1 sbrijnath  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-September 09

All Unique Combinations of any array of numbers

Posted 14 September 2009 - 02:31 AM

Does anyone have a fast porcedure to list all unique combinations of any array of letters / numbers. For example, 5 letters will generate 2^5 = 32 unique combinations.....
Is This A Good Question/Topic? 0
  • +

Replies To: All Unique Combinations of any array of numbers

#2 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: All Unique Combinations of any array of numbers

Posted 14 September 2009 - 06:23 AM

Multiple nested for loops is what you are looking for...
Dim N1 As Integer, N2 As Integer,..., N5 As Integer
Dim MyArray(1 To 10) As String, MyString As String
Dim L As Integer, U As Integer
'...
L = LBound(MyArray)
U = UBound(MyArray)

For N1= L To U
  For N2 = N1 + 1 To U
	For N3 = N2 + 1 To U
	  '...



Just an example on how to get started...



Good Luck
Was This Post Helpful? 0
  • +
  • -

#3 sbrijnath  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-September 09

Re: All Unique Combinations of any array of numbers

Posted 15 September 2009 - 03:09 AM

View Postvb5prgrmr, on 14 Sep, 2009 - 05:23 AM, said:

Multiple nested for loops is what you are looking for...
Dim N1 As Integer, N2 As Integer,..., N5 As Integer
Dim MyArray(1 To 10) As String, MyString As String
Dim L As Integer, U As Integer
'...
L = LBound(MyArray)
U = UBound(MyArray)

For N1= L To U
  For N2 = N1 + 1 To U
	For N3 = N2 + 1 To U
	  '...



Just an example on how to get started...



Good Luck

Was This Post Helpful? 0
  • +
  • -

#4 sbrijnath  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-September 09

Re: All Unique Combinations of any array of numbers

Posted 15 September 2009 - 08:55 PM

Thanks very much for this. The issue I have is with the exponential time aspect of this code. It works well for upto n =10 but then slows dramatically. Is there code anywhere that is optimized for (say) n =20 or 30 ?

Regards
Was This Post Helpful? 0
  • +
  • -

#5 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: All Unique Combinations of any array of numbers

Posted 16 September 2009 - 07:31 AM

No not really, but you can get the same results from a recursive call that I have heard is faster but have never tested it.



Good Luck
Was This Post Helpful? 0
  • +
  • -

#6 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: All Unique Combinations of any array of numbers

Posted 16 September 2009 - 10:01 AM

it is faster but i dont know if you dont got an error of stack overflow. but with 30 dont think it will happen i use it for something like that.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1