Radiohead22 1 Posted February 9, 2020 Share Posted February 9, 2020 #include<array.au3> Local $aArray[8] = ['A-1', 'A-2', 'B-1', 'B-2', 'C-1', 'C-2', 'D-1', 'D-2'] Local $aNewArray = _ArrayCombinations($aArray, 4, ' / ') _ArrayDisplay($aNewArray) Greetings to the whole forum, I'm trying to create combinations without repetition. I would like to avoid repeating the same letter even if with a different number in the same line EXAMPLE: OK: A-1 / B-1 / C-1 / D-1 / NO: A-1 / A-2 / C-1 / D-1 / ---------------------------------------- OK: A-1 / B-2 / C-1 / D-2 / NO: A-1 / C-1 / D-1 / D-2 / ---------------------------------------- Could some good soul help me out? Link to post Share on other sites
Nine 1,515 Posted February 9, 2020 Share Posted February 9, 2020 Try this : Global $aArray[8] = ['A-1', 'A-2', 'B-1', 'B-2', 'C-1', 'C-2', 'D-1', 'D-2'] Combi("",-1,4) Func Combi($Str, $Pos, $MaxLen) if StringLen($Str) = $MaxLen*6 Then ConsoleWrite("Combination = " & $Str & @CRLF) Return EndIf For $i = $Pos+1 to UBound($aArray)-1 If StringInStr ($Str, StringLeft ($aArray[$i],2)) Then ContinueLoop Combi($Str & $aArray[$i] & " / ",$i,$MaxLen) Next EndFunc Not much of a signature but working on it... Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search content in au3 files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector GIF Animation (cached) Screen Scraping Link to post Share on other sites
Radiohead22 1 Posted February 9, 2020 Author Share Posted February 9, 2020 Thanks Nine always kind, it works fine but how do I change _consolewrite () to _Excel_RangeWrite? With _ArrayDisplay don't run. I also need to study it a bit to understand how to adapt it to different types of arrays or arrays greater than 8. Anyway thanks again for your help. Link to post Share on other sites
Nine 1,515 Posted February 9, 2020 Share Posted February 9, 2020 #include <Array.au3> Global $aArray[8] = ['A-1', 'A-2', 'B-1', 'B-2', 'C-1', 'C-2', 'D-1', 'D-2'] Global $aFinal[0] Combi("",-1,4) Func Combi($Str, $Pos, $MaxLen) if StringLen($Str) = $MaxLen*6 Then _ArrayAdd ($aFinal,$Str) Return EndIf For $i = $Pos+1 to UBound($aArray)-1 If StringInStr ($Str, StringLeft ($aArray[$i],2)) Then ContinueLoop Combi($Str & $aArray[$i] & " / ",$i,$MaxLen) Next EndFunc _ArrayDisplay ($aFinal) You can increase the size of the $aArray without any problem. If you change the content of the array then the if...continueLoop must be modified accordingly. Not much of a signature but working on it... Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search content in au3 files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector GIF Animation (cached) Screen Scraping Link to post Share on other sites
Radiohead22 1 Posted February 9, 2020 Author Share Posted February 9, 2020 I tried: _Excel_RangeWritE($oWorkbook, Default, $Str, "A1") OR _Excel_RangeWritE($oWorkbook, Default, $Str, "A1:A16") OR _Excel_RangeWritE($oWorkbook, Default, $Str & @CRLF, "A1") but always writes the same column on the same line Link to post Share on other sites
Nine 1,515 Posted February 9, 2020 Share Posted February 9, 2020 Use the array I just created in 3rd post... Not much of a signature but working on it... Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search content in au3 files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector GIF Animation (cached) Screen Scraping Link to post Share on other sites
Radiohead22 1 Posted February 9, 2020 Author Share Posted February 9, 2020 #include<array.au3> #include <Excel.au3> $file1 = @ScriptDir & '\Combinazioni.xlsx' Local $oExcel = _Excel_Open() Local $oWorkbook = _Excel_BookOpen($oExcel, $file1) Global $aArray[9] = ['A-1', 'A-2', 'B-1', 'B-2', 'C-1', 'C-2', 'D-1', 'D-2', 'CIAO'] Global $aFinal[0] Combi("",-1,4) Func Combi($Str, $Pos, $MaxLen) if StringLen($Str) = $MaxLen*6 Then _ArrayAdd ($aFinal,$Str) Return EndIf For $i = $Pos+1 to UBound($aArray)-1 If StringInStr ($Str, StringLeft ($aArray[$i],2)) Then ContinueLoop Combi($Str & $aArray[$i] & " / ",$i,$MaxLen) Next EndFunc _Excel_RangeWritE($oWorkbook, Default, $aFinal & @CRLF, "A1") Now on excel it works perfectly but I don't understand how to increase the array, maybe I'm too stupid :D Link to post Share on other sites
Nine 1,515 Posted February 9, 2020 Share Posted February 9, 2020 Like I said you can increase the size of the array respecting the same pattern X-N. If you change the pattern like you did, you need to change the continueLoop condition. Not much of a signature but working on it... Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search content in au3 files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector GIF Animation (cached) Screen Scraping Link to post Share on other sites
Radiohead22 1 Posted February 9, 2020 Author Share Posted February 9, 2020 Global $aArray[10] = ['A-1', 'A-2', 'B-1', 'B-2', 'C-1', 'C-2', 'D-1', 'D-2', 'CIAO-1', 'CIAO-2'] Global $aFinal[0] Combi("",-1,4) Func Combi($Str, $Pos, $MaxLen) if StringLen($Str) = $MaxLen*6 Then _ArrayAdd ($aFinal,$Str) Return EndIf For $i = $Pos+1 to UBound($aArray)-1 ;~ If StringInStr ($Str, StringLeft ($aArray[$i],3)) Then ContinueLoop ;~ If StringInStr ($Str, StringLeft ($aArray[$i],10)) Then ContinueLoop If StringInStr ($Str, StringLeft ($aArray[$i],4)) Then ContinueLoop Combi($Str & $aArray[$i] & " / ",$i,$MaxLen) Next EndFunc ;~ _Excel_RangeWritE($oWorkbook, Default, $aFinal & @CRLF, "A1") _ArrayDisplay ($aFinal) Yes and thank you for your patience. I can't understand how, I'm doing a thousand tests Link to post Share on other sites
Nine 1,515 Posted February 9, 2020 Share Posted February 9, 2020 (edited) #include <Array.au3> Global $aArray[10] = ['A-1', 'A-2', 'B-1', 'B-2', 'C-1', 'C-2', 'D-1', 'D-2', 'CIAO-1', 'CIAO-2'] Global $aFinal[0] Combi("",-1,0,4) Func Combi($Str, $Pos, $Count, $MaxLen) if $Count = $MaxLen Then _ArrayAdd ($aFinal,$Str) Return EndIf For $i = $Pos+1 to UBound($aArray)-1 If StringInStr($Str,StringLeft ($aArray[$i],StringInStr($aArray[$i],"-"))) Then ContinueLoop Combi($Str & $aArray[$i] & " / ",$i,$Count+1,$MaxLen) Next EndFunc _ArrayDisplay ($aFinal) Ok, made a couple of changes to make it work with now a count instead of StrLen Edited February 9, 2020 by Nine remove -1 in condition pixelsearch 1 Not much of a signature but working on it... Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search content in au3 files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector GIF Animation (cached) Screen Scraping Link to post Share on other sites
Radiohead22 1 Posted February 9, 2020 Author Share Posted February 9, 2020 Ahahahaha look what i was doing: If StringInStr ($Str, "-", 1, -1, StringLeft ($aArray[$i], -1)) Then ContinueLoop your example works perfectly thanks for your patience Link to post Share on other sites
Radiohead22 1 Posted February 9, 2020 Author Share Posted February 9, 2020 Do you have any idea how I can increase the number of combinations in a row? es. from: Combi ( "", - 1,0,4) to Combi ( "", - 1,0,5) in an array of 8. The _ArrayCombinations function does this but does it with duplicates Link to post Share on other sites
Nine 1,515 Posted February 9, 2020 Share Posted February 9, 2020 Not with me (seems you got a space between -1) : Not much of a signature but working on it... Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search content in au3 files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector GIF Animation (cached) Screen Scraping Link to post Share on other sites
Radiohead22 1 Posted February 9, 2020 Author Share Posted February 9, 2020 4 combinations without spaces for row Link to post Share on other sites
Radiohead22 1 Posted February 9, 2020 Author Share Posted February 9, 2020 5 combinations without spaces for row Link to post Share on other sites
Nine 1,515 Posted February 9, 2020 Share Posted February 9, 2020 Normal you only got 4 types, you cannot get any row with 5 max !!! Not much of a signature but working on it... Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search content in au3 files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector GIF Animation (cached) Screen Scraping Link to post Share on other sites
Radiohead22 1 Posted February 9, 2020 Author Share Posted February 9, 2020 Ok thank you Nine Link to post Share on other sites
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