Sign in to follow this  
Followers 0
Fossil Rock

Identifying data in any order

6 posts in this topic

I need to identify several data elements, but it will not always be in a particular order. Is there an easy way to check all variations to find a match? Sort of like how a slot machine works, it can figure out whether or not a certain combination is a winner or not.

Example: You have 3 lists - Fruit, Colors and Numbers

Banana

Grape

Lemon

Cherry

Green

Blue

Red

Yellow

5

12

17

30

I'm looking for any combination of Cherry,Red,5 (i.e. 5,Red,Cherry | Red,5,Cherry | Red,Cherry,5 .... and so on and so forth).

I imagine there is a way with an array, but I'm unaware of it.


Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Share this post


Link to post
Share on other sites



MsgBox(0, '', SomeFuncName('5,Red,Cherry'))
MsgBox(0, '', SomeFuncName('Red,5,Cherry'))
MsgBox(0, '', SomeFuncName('Red,Cherry,5'))
MsgBox(0, '', SomeFuncName('Blue,Cherry,5'))

Func SomeFuncName($str)
    If StringInStr($str, 'Cherry') And _
            StringInStr($str, '5') And _
            StringInStr($str, 'Red') _
            Then Return True
    Return False
EndFunc

Share this post


Link to post
Share on other sites

What would your solution look like if there were 100 lists with 100 elements per list?


Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

What would your solution look like if there were 100 lists with 100 elements per list?

Just a simple example with a small array

dim $Array[3] = ["Red", "Cherry", "5"], $Found1, $Found2, $Found3
$1 = "Cherry"
$2 = "Red"
$3 = "5"
For $X = 0 To 2
    If $Array[$X] = $1 Then $Found1 = True
    If $Array[$X] = $2 Then $Found2 = True
    If $Array[$X] = $3 Then $Found3 = True
Next
If $Found1 And $Found2 And $Found3 Then MsgBox(0, "", "Combo Found.")

Even if the order of $Array is changed it should still work. I hope this gives you an idea on how to mod it for your purposes. :)

Edited by P5ych0Gigabyte

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

Even if the order of $Array is changed it should still work. I hope this gives you an idea on how to mod it for your purposes. :)

Thanks, I can see how this could be used to accomplish my goal.

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Share this post


Link to post
Share on other sites

What would your solution look like if there were 100 lists with 100 elements per list?

#region - create the array/items for testing.
#include <Array.au3>  ; only needed for _ArrayDisplay

Global $set1[4] = ['Banana', 'Grape', 'Lemon', 'Cherry']
Global $set2[4] = ['Green', 'Blue', 'Red', 'Yellow']
Global $set3[4] = ['5', '12', '17', '30']
Global $list[100]

For $i = 0 To 99
    $list[$i] = $set1[Random(0, 3, 1) ] & ',' & _
            $set2[Random(0, 3, 1) ] & ',' & _
            $set3[Random(0, 3, 1) ]
Next
#endregion

_ArrayDisplay($list, 'Before Checking')

For $i = 0 To 99
    If SomeFuncName($list[$i]) Then $list[$i] = $list[$i] & '     <<<<<  match here'
Next

_ArrayDisplay($list, 'After Checking')

Func SomeFuncName($str)
    If StringInStr($str, 'Cherry') And _
            StringInStr($str, '5') And _
            StringInStr($str, 'Red') _
            Then Return True
    Return False
EndFunc

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