Crystall Posted July 7, 2009 Posted July 7, 2009 Hello all! At first, I'm sorry of my English. I have an array of strings, e.g. $Array[0]="X" $Array[1]="Y" $Array[2]="Z" And I should make new array of all strings which may concate from this. Something like: $Array[0]="XY" $Array[1]="XZ" $Array[2]="YX" $Array[3]="YZ" $Array[4]="ZX" $Array[5]="ZY" $Array[6]="XYZ" $Array[7]="XZY" ... $Array[Last]="ZYX" Have anyone an idea of how to do that? Hello World!
Szhlopp Posted July 7, 2009 Posted July 7, 2009 (edited) Hello all! At first, I'm sorry of my English. I have an array of strings, e.g. $Array[0]="X" $Array[1]="Y" $Array[2]="Z" And I should make new array of all strings which may concate from this. Something like: $Array[0]="XY" $Array[1]="XZ" $Array[2]="YX" $Array[3]="YZ" $Array[4]="ZX" $Array[5]="ZY" $Array[6]="XYZ" $Array[7]="XZY" ... $Array[Last]="ZYX" Have anyone an idea of how to do that? :EDIT: Oops, mis-read... I've written something that does this... Let me see if I can find it. Edited July 7, 2009 by Szhlopp RegEx/RegExRep Tester!Nerd Olympics - Community App!Login UDFMemory UDF - "Game.exe+753EC" - CE pointer to AU3Password Manager W/ SourceDataFiler - Include files in your au3!--- Was I helpful? Click the little green '+'
Crystall Posted July 7, 2009 Author Posted July 7, 2009 (edited) OK. =) Here is the more detailed (I think) description of what I want: From first array I must get the second. Substrings from the second one shouldn't repeat. Edited July 7, 2009 by Crystall Hello World!
weaponx Posted July 7, 2009 Posted July 7, 2009 This one seems simple on the surface but its a lot trickier than you would expect.
Crystall Posted July 7, 2009 Author Posted July 7, 2009 (edited) Thanks Thanubis, this should be useful for me.But maybe anyone may make an example script, which will do what I describe in first post?Because of night time, I going sleep. Maybe at morning I will join _ArrayCombinations() and _ArrayPermute() and get correct solution =) Edited July 7, 2009 by Crystall Hello World!
Authenticity Posted July 7, 2009 Posted July 7, 2009 This works only for your example and not for something like "W", "X", "Y", "Z" or just "X", "Y". In short, it can't process arbitrary array length: #include <Array.au3> Dim $avArr1[3] = ["X", "Y", "Z"] Dim $avArr2 Dim $sBuff = '' For $i = 0 To UBound($avArr1)-2 For $j = 0 To UBound($avArr1)-1 $sBuff &= _RecursiveDownward(UBound($avArr1)-1-$i) & "|" & _RecursiveUpward($i) & "|" For $k = 1 To UBound($avArr1)-1 $sTmp = $avArr1[$k-1] $avArr1[$k-1] = $avArr1[$k] $avArr1[$k] = $sTmp Next Next Next $avArr2 = StringSplit(StringTrimRight($sBuff, 1), "|", 2) _ArraySort($avArr2) _ArrayDisplay($avArr2) Func _RecursiveUpward($iDepth) If $iDepth < UBound($avArr1)-1 Then Return $avArr1[$iDepth] & _RecursiveUpward($iDepth+1) Else Return $avArr1[$iDepth] EndIf EndFunc Func _RecursiveDownward($iDepth) If $iDepth > 0 Then Return $avArr1[$iDepth] & _RecursiveDownward($iDepth-1) Else Return $avArr1[$iDepth] EndIf EndFunc
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now