Auio42TheWin Posted March 2, 2015 Share Posted March 2, 2015 (edited) Hello people! I've tried SO many things, but I just can't wrap my head around this... I don't see how it's possible! How would I have a list of names ("Joe","Tom","Elizabeth","Alexander") and then do a msgbox for each possible pair? for i.e Joe and Tom Joe and Elizabeth Tom and Elizabeth Alexander and Joe Tom and Alexander Like if the list of names were in a notepad document. what do I do? I've searched forever and came upon a few examples of something like this, and I've tried modifying them to do what I want but I can't. Here is one of them. It doesn't do what I want, but it's something like it... i've really tried modifying it to do what I want but I can't. /edit - i modified it a bit to show you the kind of stuff i've tried Run("notepad.exe") WinWaitActive("") Sleep(500) $Letter = StringSplit("Alexander","Elizabeth","Tom","Jerry") Combi("") Func Combi($Str, $MaxLen) Dim $i Send("Combination = " & $Str & @CRLF) ; Sleep(50) Return EndIf For $i = 1 to $Letter[0] Combi($Str & $Letter[$i]) Next EndFunc Edited March 2, 2015 by Auio42TheWin Link to comment Share on other sites More sharing options...
BrewManNH Posted March 2, 2015 Share Posted March 2, 2015 Put them all into an array, like you're doing, and use _ArrayPermute to get all the permutations of the elements of the array. ; Declare a 1-dimensional array, return an Array of permutations #include <Array.au3> Local $aArray[4] = ["Alexander","Elizabeth","Tom","Jerry"] Local $aNewArray = _ArrayPermute($aArray, ",") ;Using Default Parameters _ArrayDisplay($aNewArray, "Array Permuted") Just be warned though, as you add more elements to the array, the longer it's going to take to give you any results and you'll eventually hit a point where you run out of memory. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
SadBunny Posted March 2, 2015 Share Posted March 2, 2015 (edited) That code is broken. (/edit: i mean the code in the OP.) Try this: #include <Array.au3> $letter = StringSplit("Alexander,Elizabeth,Tom,Jerry", ",", 2) For $x In $letter For $y In $letter If StringCompare($x, $y) <> 0 Then ConsoleWrite($x & " and " & $y & @CRLF) EndIf Next Next Note that the code above will list "Tom and Jerry" and "Jerry and Tom" as two separate outcomes. If you don't want that, try: #include <Array.au3> $letter = StringSplit("Alexander,Elizabeth,Tom,Jerry", ",") For $x = 1 to $letter[0] - 1 For $y = $x + 1 to $letter[0] If StringCompare($letter[$x], $letter[$y]) <> 0 Then ConsoleWrite($letter[$x] & " and " & $letter[$y] & @CRLF) EndIf Next Next Edited March 2, 2015 by SadBunny sdfaheemuddin 1 Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
SadBunny Posted March 2, 2015 Share Posted March 2, 2015 Brewman, note that Auio42TheWin (whatever that may mean ) wanted pairs, not a 4-element permutation. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
Auio42TheWin Posted March 2, 2015 Author Share Posted March 2, 2015 .... You guys are so amazing! How do you learn how to write stuff like that? Please tell me. How do you like... put your brain in that state? I sound so dumb, thank you again! Link to comment Share on other sites More sharing options...
SadBunny Posted March 2, 2015 Share Posted March 2, 2015 (edited) I sound so dumb, thank you again! No, you do not sound dumb, you sound inexperienced. Dumb is when you fail to formulate your question carefully and still expect a useful answer. How do you learn how to write stuff like that? Please tell me. How do you like... put your brain in that state? Practice. Lots of practice. It's all a puzzle where you have a large degree of freedom in the workings of the pieces. Edited March 2, 2015 by SadBunny sdfaheemuddin 1 Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
Auio42TheWin Posted March 2, 2015 Author Share Posted March 2, 2015 That code is broken. (/edit: i mean the code in the OP.) Try this: #include <Array.au3> $letter = StringSplit("Alexander,Elizabeth,Tom,Jerry", ",", 2) For $x In $letter For $y In $letter If StringCompare($x, $y) <> 0 Then ConsoleWrite($x & " and " & $y & @CRLF) EndIf Next Next Note that the code above will list "Tom and Jerry" and "Jerry and Tom" as two separate outcomes. If you don't want that, try: #include <Array.au3> $letter = StringSplit("Alexander,Elizabeth,Tom,Jerry", ",") For $x = 1 to $letter[0] - 1 For $y = $x + 1 to $letter[0] If StringCompare($letter[$x], $letter[$y]) <> 0 Then ConsoleWrite($letter[$x] & " and " & $letter[$y] & @CRLF) EndIf Next Next If you wouldn't mind, could you tell me how it works? I've been looking over it and trying to understand it and recreate it. I know what this does : "$letter = StringSplit("Alexander,Elizabeth,Tom,Jerry", ",")" What it does is removes the commas. Link to comment Share on other sites More sharing options...
SadBunny Posted March 2, 2015 Share Posted March 2, 2015 Auio, you don't need to quote the entire post, it clutters the thread. Also, if you do quote, put your normal text outside of the quote box Do you have a specific question about my code? Because it seems pretty straightforward. What is it you have trouble understanding? Roses are FF0000, violets are 0000FF... All my base are belong to you. 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