BrianTheLibrarian Posted July 5, 2019 Share Posted July 5, 2019 Hello, I'm generating recipes. I've generated a list of all possible combinations of 2, 3, 4 and 5 ingredients , and I have a list of all the percents that would be usable. I've put together the following code, but with the 4s and 5s there are like 7 billion combinations. Is there a faster way to generate the combinations? expandcollapse popup;78k elements _FileReadToArray(@ScriptDir &"\all-percents.csv", $percents, Default, ",") ; 100k elements _FileReadToArray(@ScriptDir &"\all-combinations.csv", $combos, Default, ",") ; text files that the soap recipes will be written to Local $allRecipes = @ScriptDir & "\all-recipes.txt" for $z = 1 to $combos[0][0]-1 $arrayLen = 0 ; this counts all the elements in the line of the array (2, 3, 4, 5) and stores the number in $arrayLen for $e = 0 to 5 if $combos[$z][$e] = "" Then ; if it is blank, exit the loop ExitLoop Else $arrayLen = $arrayLen + 1 EndIf Next Switch $arrayLen Case 1 for $i = 0 to 0 ; write the names & percents $write = $combos[$z][0]& "," & $percents[$i][0] FileWriteLine($allRecipes, $write) Next Case 2 ; on the list of percents 1 through 380 is the list of 2 numbers that add to 100 for $i = 1 to 380 $write = $combos[$z][0]& "," & $percents[$i][0] & "," & $combos[$z][1] & "," & $percents[$i][1] FileWriteLine($allRecipes, $write) Next Case 3 ; array elements that match the 3 number combinations that add to 100 for $i = 380 to 3800 $write = $combos[$z][0]& "," & $percents[$i][0] & "," & $combos[$z][1]& "," & $percents[$i][1] & "," & $combos[$z][2]& "," & $percents[$i][2] FileWriteLine($allRecipes, $write) Next Case 4 ; array elements that match the 4 number combinations that add to 100 for $i = 3801 to 23177 $write = $combos[$z][0]& "," & $percents[$i][0] & "," & $combos[$z][1]& "," & $percents[$i][1] & "," & $combos[$z][2]& "," & $percents[$i][2]& "," & $combos[$z][3]& "," & $percents[$i][3] FileWriteLine($allRecipes, $write) Next Case 5 ; array elements that match the 5 number combinations that add to 100 for $i = 23178 to 100673 $write = $combos[$z][0]& "," & $percents[$i][0] & "," & $combos[$z][1]& "," & $percents[$i][1] & "," & $combos[$z][2]& "," & $percents[$i][2]& "," & $combos[$z][3]& "," & $percents[$i][3]& "," & $combos[$z][4]& "," & $percents[$i][4] FileWriteLine($allRecipes, $write) Next EndSwitch Next Link to comment Share on other sites More sharing options...
Aelc Posted July 5, 2019 Share Posted July 5, 2019 (edited) hey can you post an example file? i actually dont get it - seems rly complicated for an easy function but i didnt really understand what you want would help to understand it EDIT: I mean there are so much undefinied numbers i actually don't know where they come from in your For next loops Edited July 5, 2019 by Aelc why do i get garbage when i buy garbage bags? Link to comment Share on other sites More sharing options...
Network_Guy Posted July 5, 2019 Share Posted July 5, 2019 u can change :- Local $allRecipes = @ScriptDir & "\all-recipes.txt" to Local $allRecipes=fileopen( @ScriptDir & "\all-recipes.txt",2) and add fileclose to the end of the script :- fileclose($allRecipes) Link to comment Share on other sites More sharing options...
BrianTheLibrarian Posted July 5, 2019 Author Share Posted July 5, 2019 Sure so for example you would have the letters A through L and all permutations of them in. So you would have: a,b a,c a,d .... a,a,b a,a,c .... and so forth all the way through the 5 combinations of the ingredients. Now the percent file has all the percents in increments of 5 like 5, 95 10, 90 etc all the way up to the 5 combinations of percents. The script goes through and merges them together. So the final output would look like a, 5, b, 95 a, 10, b, 80 etc... and once it goes through all the 2 number combinations for the 2 letter combinations it repeats it for the next set of letters. Then the 3 letters / 3 numbers, 4 letters / 4 numbers, 5 letters/ 5 numbers. a, 5, c, 95 a, 10, c, 80 ... a, 5, d, 95 which the above script works, except that it is going to take something like 2 months running 24/7 to generate all the combinations. Link to comment Share on other sites More sharing options...
Nine Posted July 5, 2019 Share Posted July 5, 2019 Have you tried @Network_Guy suggestion ? It's going to save you a lot... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (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 Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
BrianTheLibrarian Posted July 5, 2019 Author Share Posted July 5, 2019 10 minutes ago, Nine said: Have you tried @Network_Guy suggestion ? It's going to save you a lot... I just did. Wow..... yeah major improvement. Thanks a TON @Network_Guy! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 5, 2019 Moderators Share Posted July 5, 2019 BrianTheLibrarian, Just why are you doing this massive exercise in combining "ingredients"? What exactly are you going to do with this multitude of different "recipes"? M23 P.S. And just to be absolutely clear - this is the Mod team determining the legality of the thread, so everyone else please keep out. Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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