Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Pattern / Combinations

Does anyone know of any algorithms which produce all the possible
combinations of patterns within a string?

Example String = ABCDE

AB, AC, AD, AE, BC, BD, BE, CD, CE, DE
ABC, ABD, ABE, ACD, ACE, ADE, BCD, BCE, CDE
ABCD, ABCE, ABDE, ACDE, BDCE
ABCDE


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Pattern / Combinations

Code by Myrna Larson would be a start.

http://tinyurl.com/q9ko9

Think you would have to run it for each quantity of sub string

once for combinations of 2
once for combinations of 3
and so forth.

--
Regards,
Tom Ogilvy


"Paul W Smith" wrote:

Does anyone know of any algorithms which produce all the possible
combinations of patterns within a string?

Example String = ABCDE

AB, AC, AD, AE, BC, BD, BE, CD, CE, DE
ABC, ABD, ABE, ACD, ACE, ADE, BCD, BCE, CDE
ABCD, ABCE, ABDE, ACDE, BDCE
ABCDE



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Pattern / Combinations

A simple recursive approach seems to work quite well (though
it doesn't give them in alphabetical order):

Option Explicit
Sub main()
ShowCombinations "", "ABCDE"
End Sub

Sub ShowCombinations(strPrefix As String, strMain As String)
If strMain = "" Then
Debug.Print strPrefix
Exit Sub
End If
Dim strFirst As String, strRest As String
strFirst = Left(strMain, 1)
strRest = Mid(strMain, 2)
ShowCombinations strPrefix & strFirst, strRest
ShowCombinations strPrefix, strRest
End Sub



Paul W Smith wrote:
Does anyone know of any algorithms which produce all the possible
combinations of patterns within a string?

Example String = ABCDE

AB, AC, AD, AE, BC, BD, BE, CD, CE, DE
ABC, ABD, ABE, ACD, ACE, ADE, BCD, BCE, CDE
ABCD, ABCE, ABDE, ACDE, BDCE
ABCDE


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Pattern / Combinations

Very Nice!

--
Regards,
Tom Ogilvy


"Andrew Taylor" wrote:

A simple recursive approach seems to work quite well (though
it doesn't give them in alphabetical order):

Option Explicit
Sub main()
ShowCombinations "", "ABCDE"
End Sub

Sub ShowCombinations(strPrefix As String, strMain As String)
If strMain = "" Then
Debug.Print strPrefix
Exit Sub
End If
Dim strFirst As String, strRest As String
strFirst = Left(strMain, 1)
strRest = Mid(strMain, 2)
ShowCombinations strPrefix & strFirst, strRest
ShowCombinations strPrefix, strRest
End Sub



Paul W Smith wrote:
Does anyone know of any algorithms which produce all the possible
combinations of patterns within a string?

Example String = ABCDE

AB, AC, AD, AE, BC, BD, BE, CD, CE, DE
ABC, ABD, ABE, ACD, ACE, ADE, BCD, BCE, CDE
ABCD, ABCE, ABDE, ACDE, BDCE
ABCDE



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Pattern / Combinations

Thank you for this example which is so close to what I require - order is
unimportant.

However how do I amend your code so it only produces doubles and above, no
singles

PWS


"Andrew Taylor" wrote in message
ps.com...
A simple recursive approach seems to work quite well (though
it doesn't give them in alphabetical order):

Option Explicit
Sub main()
ShowCombinations "", "ABCDE"
End Sub

Sub ShowCombinations(strPrefix As String, strMain As String)
If strMain = "" Then
Debug.Print strPrefix
Exit Sub
End If
Dim strFirst As String, strRest As String
strFirst = Left(strMain, 1)
strRest = Mid(strMain, 2)
ShowCombinations strPrefix & strFirst, strRest
ShowCombinations strPrefix, strRest
End Sub



Paul W Smith wrote:
Does anyone know of any algorithms which produce all the possible
combinations of patterns within a string?

Example String = ABCDE

AB, AC, AD, AE, BC, BD, BE, CD, CE, DE
ABC, ABD, ABE, ACD, ACE, ADE, BCD, BCE, CDE
ABCD, ABCE, ABDE, ACDE, BDCE
ABCDE






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Pattern / Combinations

The answer to my question came to me as soon as I posted my request - check
that the length of StrPrefix 1.


"Paul W Smith" wrote in message
...
Thank you for this example which is so close to what I require - order is
unimportant.

However how do I amend your code so it only produces doubles and above, no
singles

PWS


"Andrew Taylor" wrote in message
ps.com...
A simple recursive approach seems to work quite well (though
it doesn't give them in alphabetical order):

Option Explicit
Sub main()
ShowCombinations "", "ABCDE"
End Sub

Sub ShowCombinations(strPrefix As String, strMain As String)
If strMain = "" Then
Debug.Print strPrefix
Exit Sub
End If
Dim strFirst As String, strRest As String
strFirst = Left(strMain, 1)
strRest = Mid(strMain, 2)
ShowCombinations strPrefix & strFirst, strRest
ShowCombinations strPrefix, strRest
End Sub



Paul W Smith wrote:
Does anyone know of any algorithms which produce all the possible
combinations of patterns within a string?

Example String = ABCDE

AB, AC, AD, AE, BC, BD, BE, CD, CE, DE
ABC, ABD, ABE, ACD, ACE, ADE, BCD, BCE, CDE
ABCD, ABCE, ABDE, ACDE, BDCE
ABCDE






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Pattern / Combinations

Very Nice!
I like it also. In other math programs, this is known as "BinarySubsets."
This implementation gives it in reverse order. With 5 items, it goes from
2^5-1 to 1 in Binary form. Other programs use this idea for implementation.
First number is 31, or 11111 in binary, (abcde)
Second number is 30, or 11110 (abcd)
29, 11101 (abce)
etc...
--
Dana DeLouis
Windows XP, Office 2003


"Tom Ogilvy" wrote in message
...
Very Nice!

--
Regards,
Tom Ogilvy


"Andrew Taylor" wrote:

A simple recursive approach seems to work quite well (though
it doesn't give them in alphabetical order):

Option Explicit
Sub main()
ShowCombinations "", "ABCDE"
End Sub

Sub ShowCombinations(strPrefix As String, strMain As String)
If strMain = "" Then
Debug.Print strPrefix
Exit Sub
End If
Dim strFirst As String, strRest As String
strFirst = Left(strMain, 1)
strRest = Mid(strMain, 2)
ShowCombinations strPrefix & strFirst, strRest
ShowCombinations strPrefix, strRest
End Sub



Paul W Smith wrote:
Does anyone know of any algorithms which produce all the possible
combinations of patterns within a string?

Example String = ABCDE

AB, AC, AD, AE, BC, BD, BE, CD, CE, DE
ABC, ABD, ABE, ACD, ACE, ADE, BCD, BCE, CDE
ABCD, ABCE, ABDE, ACDE, BDCE
ABCDE





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
all possible combinations. Gaurav[_4_] Excel Discussion (Misc queries) 4 March 19th 09 06:15 PM
combinations Sonny Excel Discussion (Misc queries) 11 August 26th 07 08:26 PM
Sum of combinations [email protected] Excel Discussion (Misc queries) 3 March 11th 06 05:32 PM
Combinations Don Lloyd Excel Programming 4 June 28th 05 09:01 PM
All combinations Seokho Moon Excel Programming 7 October 22nd 04 10:19 PM


All times are GMT +1. The time now is 08:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"