Sign in to follow this  
Followers 0
Auio42TheWin

Two words from a list, all combos.

8 posts in this topic

#1 ·  Posted (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 by Auio42TheWin

Share this post


Link to post
Share on other sites



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 Gude
How 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

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by SadBunny
1 person likes this

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

Brewman, note that Auio42TheWin (whatever that may mean :D ) wanted pairs, not a 4-element permutation.


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

.... 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?  :geek:

I sound so dumb, thank you again! 

Share this post


Link to post
Share on other sites

#6 ·  Posted (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?   :geek:

 

Practice. Lots of practice. It's all a puzzle where you have a large degree of freedom in the workings of the pieces.

Edited by SadBunny
1 person likes this

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

 

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.

Share this post


Link to post
Share on other sites

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.

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