Sign in to follow this  
Followers 0
Steveiwonder

_ArrayPermute() with Repetition?

8 posts in this topic

#1 ·  Posted (edited)

Howdy,

Currently _ArrayPermute() doesn't support repetition. Has anyone found a way around this? Created their own UDF of some kind?

If you dont understand what i mean by repetition its like this..

Local $chars[2]
$chars[0] = "a"
$chars[1] = "b"

$combinations = _ArrayPermute($chars, "")
$permArray = _ArrayDisplay($combinations)

That would result in an array with the following:

ab

ba

With repetition the array would be like this..

ab

aa ;repeated

ba

bb ;repeated

pretty simple right?

Current Problem:

If you have the $chars array with more elements, like a,b,c,d,e,f,g,h,i,j,k then WITH repetition you end up with one damb huge array. Actually alot bigger than autoit can currently handle.

Repetition may not of been implented because of the array size limitation i'm not sure, but has anyone found a way around it?

I've tried and failed.

thanks

Steve

Edited by Steveiwonder

They call me MrRegExpMan

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Maybe this will give you some answers:

MsgBox(0, "","Maximum count of different combinations in string ABCDEFG  is: " & @CRLF & _Combinations("ABCDEFG"))

Func _Combinations($string)
    Local $result = StringLen($string)
    For $i = ($result - 1) To 1 Step -1
        $result *= $i
    Next
    Return $result
EndFunc
Edited by Godless

_____________________________________________________________________________

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

It would all depend on the string size tbh.... which i didnt really mention.

If i want to know all possible combinations of a string length with is 6 characters long.

Characters to choose from: a,b,c,d,e,f,g

String Len: 6

Code would be

Local $stringLen = 6
Local $chars[7] = ["a", "b", "c", "d", "e", "f", "g"]
$PossiblePermutations = UBound($chars)^$stringLen
MsgBox(0, "Possible Permutations", $PossiblePermutations & " WITH Repetition")

Which is 117649

However, the problem is - How to generate a list of these permutations WITH repetition..

S

Edited by Steveiwonder

They call me MrRegExpMan

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Here it is:

Local $stringLen = 6
Local $chars[7] = ["a", "b", "c", "d", "e", "f", "g"]
$PossiblePermutations = UBound($chars)^$stringLen
MsgBox(0, "Possible Permutations", $PossiblePermutations & " WITH Repetition")

$AllComb = _AllCombinations($chars, UBound($chars), $stringLen)

$path = @DesktopDir & '\combinations.txt'
$file = FileOpen($path, 2)
FileWrite($file, $AllComb)
FileClose($file)
MsgBox(0, '', "Ready" & @CRLF & "Open: " & $path)
ShellExecute($path)

Func _AllCombinations(ByRef $x,$b,  $l, $s='')
; $x : array with items
; $b : Ubound($x)
; $l : resultlength
;{{ $s : internmal use }}
    ; Author: ProgAndy
    Local Static $t=''
    If $l = 0 Then
        $t &= $s &@CRLF
        Return
    EndIf
    For $i = 0 To $b-1
        _AllCombinations($x, $b, $l-1, $s&$x[$i])
    Next
    If Not $s Then
        Local $y=StringTrimRight($t,2) ; remove last CRLF
        $t=''
        Return $y
    EndIf
EndFunc
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

It would all depend on the string side tbh.... which i didnt really mention.

If i want to know all possible combinations of a string length with is 6 characters long.

Characters to choose from: a,b,c,d,e,f,g

String Len: 6

Code would be

Local $stringLen = 6
Local $chars[7] = ["a", "b", "c", "d", "e", "f", "g"]
$PossiblePermutations = UBound($chars)^$stringLen
MsgBox(0, "Possible Permutations", $PossiblePermutations & " WITH Repetition")

Which is 117649

However, the problem is - How to generate a list of these permutations WITH repetition..

S

It's just a counting exercise. If you had instead the numbers 0 to 5, ie a base 6 numbering system, then the maximum value you can represent is the maximum number of combinations. So you just count, Start with 0 and count up to 5555555, and for each position the letter is Asc(Chr('a') + number). So, for example

0000000 = aaaaaaa

1234567 = abcdefg

For each position there is a choice of 6 characters to choose from, so the total number of combinations is 6^7 which is 279936, so I think your 117649 is wrong.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

He has a set of 7 characters per position and 6 positions. 117649 is correct.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

He has a set of 7 characters per position and 6 positions. 117649 is correct.

Ooops! I can't count :(


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

ProgAndy, awsome - absolutly awsome.

Thanks alot.

You should of seen my attempts it was 40+lines i was obviously taking the wrong route.

This should be added to _ArrayPermute with an addition 0/1 parameter for repetition


They call me MrRegExpMan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0