Sign in to follow this  
Followers 0
Srex

Should I use array for big tables of outcomes ?

20 posts in this topic

#1 ·  Posted (edited)

atm I have a formula my script does.

it spits out a positive int value

I have 20 values ranging from every 250th number up to 5000

$formularesult = 188*2

$var250
"Red"=1
"Black"=0
"Yellow"=1

$var500
"Red"=0
"Black"=1
"Yellow"=1

My user is likely going to get a random number inbetween, and that's fine, I just want it to use the 'red black yellow' values depending on which of the numbers i closer.

So something like If $formularesult is < 375 Then use 250 table

if $formularesult is >=375 then use 500 table

So in this case it would pick $var500 because the formula is equal to or higher than 375.

Then I would define

red to be 0

black to be 1

and Yellow to be 1

I know it's horrible but it was just a quick and simple example of my problem

But it would have to be huge because there's like 20 tables ($var250 and $var500) and each of those would define the value of 8 variables.

Would this had to be done in a array?
Is there any better/easier/faster way to do it?

Edited by Srex

Share this post


Link to post
Share on other sites



Instead of having 20 different arrays, you could hold all data in a 3 dimensional array.


RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

:huh2:  I do not even understand the question


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

This could be interesting:

 

;declare main array that will hold your values:
dim $mainArray[20]

;set 20 different data on each element of the array (you'll have 20)
$mainArray[0] = _CreateNewObject(1, 0, 1);250
$mainArray[1] = _CreateNewObject(0, 1, 1);500
$mainArray[2] = _CreateNewObject(0, 1, 0);750
$mainArray[3] = _CreateNewObject(0, 1, 0);1000
$mainArray[4] = _CreateNewObject(0, 1, 0);etc...
$mainArray[5] = _CreateNewObject(0, 1, 0)
$mainArray[6] = _CreateNewObject(0, 1, 0)
$mainArray[7] = _CreateNewObject(0, 1, 0)
$mainArray[8] = _CreateNewObject(0, 1, 0)
$mainArray[9] = _CreateNewObject(0, 1, 0)
$mainArray[10] = _CreateNewObject(0, 1, 0)
$mainArray[11] = _CreateNewObject(0, 1, 0)
$mainArray[12] = _CreateNewObject(0, 1, 0)
$mainArray[13] = _CreateNewObject(0, 1, 0)
$mainArray[14] = _CreateNewObject(0, 1, 0)
$mainArray[15] = _CreateNewObject(0, 1, 0)
$mainArray[16] = _CreateNewObject(0, 1, 0)
$mainArray[17] = _CreateNewObject(0, 1, 0)
$mainArray[18] = _CreateNewObject(0, 1, 0)
$mainArray[19] = _CreateNewObject(0, 1, 0)

;-----------------------------------------------------------
;how to pull data out of this?
$randNumber = Random(250, 5000, 1)
$div = Round($randNumber / 250, 0) - 1;
ConsoleWrite("!!!--------------------------------" & @CRLF & ">> Our number is: " & $randNumber & " (div is: " & $div & ", for var " & ($div+1)*250 & ")" & @CRLF & @CRLF)
$readData = _ReadObject($mainArray[$div]);
ConsoleWrite("!> RED: " & @TAB &  $readData[0] & @CRLF)
ConsoleWrite(".> BLACK: " &  @TAB & $readData[1] & @CRLF)
ConsoleWrite("-> YELLOW: " &  @TAB & $readData[2] & @CRLF)
;-----------------------------------------------------------

;Release the resources used by the structure.
_ClearArray($mainArray)

;================================================================================
Func _ReadObject($tSTRUCT1)
    Local $_red = DllStructGetData($tSTRUCT1, "red")
    Local $_black = DllStructGetData($tSTRUCT1, "black")
    Local $_yellow = DllStructGetData($tSTRUCT1, "yellow")
    dim $retArray[3] = [$_red, $_black, $_yellow]
    Return $retArray;
EndFunc

Func _CreateNewObject($_red, $_black, $_yellow)
    Local Const $tagSTRUCT1 = "struct;int red;int black;int yellow;endstruct"
    Local $tSTRUCT1 = DllStructCreate($tagSTRUCT1)
    DllStructSetData($tSTRUCT1, "red", $_red)
    DllStructSetData($tSTRUCT1, "black", $_black)
    DllStructSetData($tSTRUCT1, "yellow", $_yellow)
    Return $tSTRUCT1
EndFunc

Func _ClearArray(ByRef $_array)
    if (UBound($_array) <= 0) Then Return
    For $singleStruct in $_array
        $singleStruct = 0
    Next
    ReDim $_array[0]
EndFunc
1 person likes this

Share this post


Link to post
Share on other sites

Okay sorry guys..

So my user has some inputs based on these inputs user shold get an value of between 100-5200

(He can get above 5500 but then I want to give him an error).

So I made a $var for every 250th number so on starting at 250, 500, 750, 1000 all the way up to 5000.

Inside every $var i have 8 variables which are excactly the same.. However the $vars connected to the main $var changes without a real pattern, I just had to try my way to find them.

So lets say the user gets the result 450 from the formula

I then want it to return one of:

$var250 or $var500 depending on which one is closests.

When I know which one is closer I need it to then define the variables within with the correct value.

And print it to the user. :)

Share this post


Link to post
Share on other sites

Even harder to understand!

WHAT do you want to achieve exactly? Is that a kind or color scheme conversion? Are you definitely positive that no algorithm can be used for determining the 3 (or is it 8) values?

Else a simple 2D array could be enough.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

There is no pattern / logic in the values so i cant use an algoritmh sadly. Also it has nothing to do with colors at all red black and yellow was example. I will try to explain it better when Im back at the computer in 30 min

Edited by Srex

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Okay so I will give it another shot.

$Result = $Input1 * $Input2 * $Input3

#cs how I want it to find the correct table
The user input will return something between 1 and 5500
I have tables like this for every 250th number between 250 and 5000
I want it to define the the $Value1-8 FROM the table closest to $Result
#ce

If $Result < 365 Then $Result = $Table250
If $Result >= 365 Then $Result = $Table500

#cs First table 
Hers the first table. In this case I want it to go to $Table250 IF $Result is between 1 and 364 (The reason that it goes so low is that We might see $Result being lower than 125, but its very very very very unlikely, but still.
#ce

$Table250
$Value1 = 4
$Value2 = 7
$Value3 = 3 
$Value4 = 8
$Value5 = 14
$Value6 = 11
$Value7 = 13
$Value8 = 11

#cs Second table
here is an example of another table
this is how it will almost always look for the value.
it will go to this table IF $Result is within (-125 and up to +124)
Of the $TableXXX) 
#ce

$Table500
$Value1 = 454
$Value2 = 75
$Value3 = 31
$Value4 = 84
$Value5 = 143
$Value6 = 114
$Value7 = 132
$Value8 = 114

#cs explaining
So for every table between 500-4500 it will have to go to a certain table if $result is between (-125 and +124;of the Tablevalue
by 'Table value I simply mean the number in my '$Table' Var
its hard for me to explain but tell me if I'm confusing or unclear in any way
#ce

Heres what I want it to do, and how it would look depending on $Result

Iniwrite("Example.ini","Class1","Value1", $Value1)
Iniwrite("Example.ini","Class1","Value2", $Value2)
Iniwrite("Example.ini","Class2","Value3", $Value3)
Iniwrite("Example.ini","Class2","Value4", $Value4)
Iniwrite("Example.ini","Class3","Value5", $Value5)
Iniwrite("Example.ini","Class3","Value6", $Value6)

;so lets say $result is >= 365 then it will write like this:

[Class1]
Value1=454
Value2=75
[Class2]
Value3=31
Value4=84
[Class3]
Value5=143
Value6=114

;Lets say $result is < 365 then it will write like this:
[Class1]
Value1=4
Value2=7
[Class2]
Value3=3
Value4=8
[Class3]
Value5=14
Value6=11

Now I think this should be possible with a Select

But can you do it like this

Func Example()
  Select
    Case $Result < 364 And $Result >= 125 
      $Value1=454
      $Value2=75
      $Value3=31
      $Value4=84
      $Value5=143
      $Value6=114
    Case $Result >= 365 And $Result < 625
      $Value1=4
      $Value2=7
      $Value3=3
      $Value4=8
      $Value5=14
      $Value6=11
    Case Else
     MsgBox(0, "Error", "Something went wrong")
  EndSelect
EndFunc

This should work imo. except I'm not sure how to double check a variable for a value, to test if its

less than X  and greater than or equal to X+250

$Result < x AND >= x+250

But the thing is HOW efficient is it? And is it really bad and time wasteing etc :)

Edited by Srex

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

You're overcomplicating your context.

Your first problem is selecting the closest "table" (let's put it that way for now) closest to an increment of 250.

Then you want retrieve the 8 values associated to this range.

This is close to what you tell us, or at least what I understand from your postings:

Local Const $Ranges = [ _
    [4, 7, 3, 8, 14, 11, 13, 11], _    ; this is for 1..124
    [454, 75, 31, 84, 143, 114, 132, 114], _    ; this is for 125..374
    [], _    ; this is for 375..624
    [], _    ; this is for 625..874
    [], _    ; this is for 875..1124
    [], _    ; this is for 1125..1374
    [], _    ; this is for 1375..1624
    [], _    ; this is for 1625..1874
    [], _    ; this is for 1875..2124
    [], _    ; this is for 2125..2374
    [], _    ; this is for 2375..2624
    [], _    ; this is for 2625..2874
    [], _    ; this is for 2875..3124
    [], _    ; this is for 3125..3374
    [], _    ; this is for 3375..3874
    [], _    ; this is for 3875..4124
    [], _    ; this is for 4125..4374
    [], _    ; this is for 4375..4624
    [], _    ; this is for 4625..4874
    [], _    ; this is for 4875..5124
    [] _    ; this is for 5125..5200
]

; obtain $result somehow
Local $result = Random(-125, 5500, 1)

; check $result bounds
If $result < 1 Then $result = 1
If $result > 5200 Then
    MsgBox(0, "", "Result out of range; aborting.")
    Exit
EndIf

Local $range = Round($result / 250)
; Now $range[$range][0] to $range[$range][7] are the 8 values associated with result
Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

if i got it right - it should be something like this :

try different $formularesult

$formularesult = 120

Local $variableDelta = 250
Local $varArray [8][8] =[[0,0,0,0,0,0,0,1], _
                         [0,0,0,0,0,0,1,0], _
                         [0,0,0,0,0,1,0,0], _
                         [0,0,0,0,1,0,0,0], _
                         [0,0,0,1,0,0,0,0], _
                         [0,0,1,0,0,0,0,0], _
                         [0,1,0,0,0,0,0,0], _
                         [1,0,0,0,0,0,0,0]]

Local $Value_1, $Value_2, $Value_3, $Value_4, $Value_5, $Value_6, $Value_7, $Value_8


If $formularesult > $variableDelta * UBound($varArray) Then
    MsgBox(64,"out of bonds","Error")
    Exit
EndIf


$iValueSet = int(Round($formularesult/$variableDelta,0))

For $i = 0 To UBound($varArray,2)-1
    Assign("Value_"&$i+1,$varArray [$iValueSet][$i])
Next

MsgBox(64, "Chosen ValueSet",   "$Value_1="&$Value_1& @crlf & _
                                "$Value_2="&$Value_2& @crlf & _
                                "$Value_3="&$Value_3& @crlf & _
                                "$Value_4="&$Value_4& @crlf & _
                                "$Value_5="&$Value_5& @crlf & _
                                "$Value_6="&$Value_6& @crlf & _
                                "$Value_7="&$Value_7& @crlf & _
                                "$Value_8="&$Value_8)
Edited by Iczer

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Okay so the max value on the result is actually fairly uncapped maybe 10-20k

But it gets worse at around 4k so at around 5200-5500 i want to throw an error for now.

Yes its within (-125 to +124) but when the lowest table is 250 i either need it to go down to 1 or give error if below 125 but again here the lowest realistic result i have seen is like 300-ish

Thanks for all the help i will look at all the suggestions

Edited by Srex

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

 

if i got it right - it should be something like this :

try different $formularesult

$formularesult = 120

Local $variableDelta = 250
Local $varArray [8][8] =[[0,0,0,0,0,0,0,1], _
                         [0,0,0,0,0,0,1,0], _
                         [0,0,0,0,0,1,0,0], _
                         [0,0,0,0,1,0,0,0], _
                         [0,0,0,1,0,0,0,0], _
                         [0,0,1,0,0,0,0,0], _
                         [0,1,0,0,0,0,0,0], _
                         [1,0,0,0,0,0,0,0]]

Local $Value_1, $Value_2, $Value_3, $Value_4, $Value_5, $Value_6, $Value_7, $Value_8


If $formularesult > $variableDelta * UBound($varArray) Then
    MsgBox(64,"out of bonds","Error")
    Exit
EndIf


$iValueSet = int(Round($formularesult/$variableDelta,0))

For $i = 0 To UBound($varArray,2)-1
    Assign("Value_"&$i+1,$varArray [$iValueSet][$i])
Next

MsgBox(64, "Chosen ValueSet",   "$Value_1="&$Value_1& @crlf & _
                                "$Value_2="&$Value_2& @crlf & _
                                "$Value_3="&$Value_3& @crlf & _
                                "$Value_4="&$Value_4& @crlf & _
                                "$Value_5="&$Value_5& @crlf & _
                                "$Value_6="&$Value_6& @crlf & _
                                "$Value_7="&$Value_7& @crlf & _
                                "$Value_8="&$Value_8)

This is PEFECT DUDE <33333333

thanks man I sadly don't think I would be able to replicate it for now. But i will def try hard to understand it 100%

I tested it and it does what I want:)!

Can't thank you enough.

Can I use this inside a func?

Edited by Srex

Share this post


Link to post
Share on other sites

Post above edited.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Post above edited.

 

Saw you did the excact same actually sorry :)

Actually some of the stuff in yours seem to be easier to understand for me

I don't really understand what this part does 100%

$iValueSet = int(Round($formularesult/$variableDelta,0))

For $i = 0 To UBound($varArray,2)-1
    Assign("Value_"&$i+1,$varArray [$iValueSet][$i])
Next
Edited by Srex

Share this post


Link to post
Share on other sites

 

Saw you did the excact same actually sorry

No, read again!

In the other code, Int(Round( is superfluous since Round( will return an integer. Then accessing array elements by indices is much better than using 8 separate variables.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

No, read again!

In the other code, Int(Round( is superfluous since Round( will return an integer. Then accessing array elements by indices is much better than using 8 separate variables.

Well All I know is that the code posted does excactly what I want. I might've explained myself poorly I'm not sure.

I will look at yours and test which one I like better and then select BA, thanks.

Is it best to use this inside my func or outside?

Share this post


Link to post
Share on other sites

It all depends: if you need it once, put it inline but use a function if it's ran at several places.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

It all depends: if you need it once, put it inline but use a function if it's ran at several places.

 

Okay thanks!

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