Jump to content
czardas

ArrayWorkshop

Recommended Posts

czardas

EXAMPLES

Fruit Machine

#include <Array.au3>
#include <MsgBoxConstants.au3>
#include 'ArrayWorkshop.au3'

; Example - Fruit Machine
Local $aWheel = ['strawberry', 'cherries', 'melon', 'pomegranate', 'lemon', '7', 'bell', 'BAR', '$']
Local $aFruitMachine = $aWheel ; one dimensional array to start with
For $i = 2 To 3 ; add some more wheels
    _ArrayAttach($aFruitMachine, $aWheel, 2) ; concatenation employed in the second dimension - this is too easy!
Next

For $i = 1 To 5 ; now let's give it a few spins
    _ShuffleArray($aFruitMachine, 2, True) ; shuffle regions of the second dimension with $bFruitMachineStyle set to True
    MsgBox($MB_OK, "Fruit Machine", "[" & $aFruitMachine[0][0] & "] [" & $aFruitMachine[0][1] & "] [" & $aFruitMachine[0][2] & "]")
Next

_ArrayDisplay($aFruitMachine, "Fruit Machine")

Shuffle Columns in a 2D Array

#include <Array.au3>
#include 'ArrayWorkshop.au3'

; Shuffle columns within a 2D array
Local $aTable = [['zero','one','two','three','four','five','six','seven'], _
                 [ 0,    1,    2,    3,      4,     5,     6,    7], _
                 [' ',  'a',  'b',  'c',    'd',   'e',   'f',  'g']]
_ArrayDisplay($aTable, 'before')

_ShuffleArray($aTable, 2) ; standard shuffle in the 2nd dimension [$bFruitMachineStyle = False]
_ArrayDisplay($aTable, 'after')

PreDim Example

#include <Array.au3>
#include 'ArrayWorkshop.au3'

; Example - push all dimensions up one level
Local $aData = ['Header 1','Header 2','Header 3','Header 4','Header 5','Header 6']
_ArrayDisplay($aData, "Original 1D")

_Predim($aData, 2, True) ; push the 1st dimension up one level to the 2nd dimension
_ArrayDisplay($aData, "1D to 2D push")

_Predim($aData, 1, True) ; revert everything back to the way it was
_ArrayDisplay($aData, "2D to 1D push reversed")

Unique Tables - Stacked

#include <MsgBoxConstants.au3>
#include 'ArrayWorkshop.au3'

; Test - Test for uniqueness occurring in the 3rd dimension
MsgBox($MB_OK, 'Msg', 'Keep your eye on the console.', 5)

Local $aGrid[3][3] = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] ; start with a 2-dimensional template

; stack 100 tables using concatenation in the third dimension
Local $aStack = $aGrid, $aTable ; $aTable = temporary array

For $i = 1 To 99
    $aTable = $aGrid ; copy 2D template
    $aTable[Random(0, 2, 1)][Random(0, 2, 1)] = 'X' ; create subtle variety in each table

    ; stack each table
    _ArrayAttach($aStack, $aTable, 3) ; 2D concatenation in the 3rd dimension - [table row][table col][index]

    ; OR stack the tables differently ==> [index][table row][table col]
    ; _PreDim($aTable, 3, True) ; this line should ideally be placed before the loop
    ; _ArrayAttach($aStack, $aTable)
Next

; NB. if you modify the code above, you will also need to modify the code below

ConsoleWrite('$aStack contains ' & UBound($aStack, 3) & ' tables' & _
' with a total of ' & 3 * 3 * UBound($aStack, 3) & ' fields' & @LF)

ConsoleWrite('finished staking tables' & @LF & 'starting timer in 1 second' & @LF & @LF)

Sleep(1000)
Local $iTimer = TimerInit()

; remove duplicate tables
_ArrayUniqueXD($aStack, Default, 3) ; tests for uniqueness in the third dimension
$iTimeDiff = TimerDiff($iTimer)

ConsoleWrite('$aStack now contains ' & UBound($aStack, 3) & ' unique tables' & _
' with a total of ' & 3 * 3 * UBound($aStack, 3) & ' fields ;)' & @LF)
ConsoleWrite('Time Taken - ' & $iTimeDiff & ' ms' & @LF & @LF)

If MsgBox($MB_YESNO, 'Prompt', 'Write the results to console?') = $IDNO Then Exit

; write the unique tables within the 3D Array to the console
For $3 = 0 To UBound($aStack, 3) - 1
    For $1 = 0 To UBound($aStack, 1) - 1
        For $2 = 0 To UBound($aStack, 2) - 1
            ConsoleWrite($aStack[$1][$2][$3])
        Next
        ConsoleWrite(@LF)
    Next
    ConsoleWrite(@LF)
Next

 

Edited by czardas
  • Like 1

Share this post


Link to post
Share on other sites
czardas

New version - BETA release, although it should be stable. More examples to follow.

Testing _ArrayAttach() - 9 Dimensions (quite mad really)

#include <MsgBoxConstants.au3>
#include 'ArrayWorkshop.au3'

; Test - Attach a string to a 1D array in the 9th dimension

Local $aArray = ["hello "]
_ArrayAttach($aArray, "world", 9) ; attach data [added functionality]

Local $sMsg = ""
For $1 = 0 To 0
    For $9 = 0 To 1
        $sMsg &= $aArray[$1][0][0][0][0][0][0][0][$9]
    Next
Next

MsgBox($MB_OK, "9D Read Out", $sMsg)

Testing _DeleteDimension()

#include <Array.au3>
#include 'ArrayWorkshop.au3'

; Test 3 - delete any dimension
Local $aArray[3][1][3] = [[[1,2,3]],[[4,5,6]],[[7,8,9]]]

_DeleteDimension($aArray, 2) ; delete the 2nd dimension from a 3D array
_ArrayDisplay($aArray, '2nd dimension deleted') ; no data loss here [Ubound($aArray, 2) = 1]

 

Edited by czardas

Share this post


Link to post
Share on other sites
UEZ

@czardas can you pack your UDF and the examples into a zip archive please?

 

Thx.


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
czardas

 @UEZ I have put all the examples in a single file and added an attachment to the first post. Thanks for looking. :)

  • Like 1

Share this post


Link to post
Share on other sites
UEZ

Looks very impressive!

Thanks for sharing.

  • Like 1

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
spudw2k

Neat stuff.  I wasn't clear on what the _PreDim function was doing at first.  It "looked" like a transposition.  I used a fun Dynamic Array Enumerate function I made used to visualize and understand it.  I noticed it also "seems" to only support up-to 7 dimensions, leaving the original array unchanged.

Local $aData = ['Header 1', 'Header 2', 'Header 3']
_DynEnumArray($aData)

_Predim($aData, 5, True)
_DynEnumArray($aData)

_Predim($aData, 7, True)
_DynEnumArray($aData)

_Predim($aData, 8, True)
_DynEnumArray($aData)

Func _DynEnumArray($arr)
    Local $arrDims[1][2]=[["ElementIdx","ElementCount"]]   ;Create an Array to Track Dimensions and Elements
    For $x = 1 to UBound($arr,0)
        ReDim $arrDims[$x+1][2]
        $arrDims[$x][0]=0
        $arrDims[$x][1]=UBound($arr,$x)
    Next
    Do   ;Loop Through Array Elements
        $var = "$arr"
        For $x = 1 to UBound($arrDims)-1
            $var &= "[" & $arrDims[$x][0] & "]"
        Next
        ConsoleWrite($var & " " & Execute($var) & @CRLF)  ;Output Subscript and Value

        $arrDims[UBound($arrDims)-1][0] += 1   ;Increment Last Dimension Element
        For $y = UBound($arrDims)-2 To 1 Step -1   ;Increment Dimension Element
            If $arrDims[$y+1][0] = $arrDims[$y+1][1] Then
                $arrDims[$y+1][0]=0
                $arrDims[$y][0]+=1
            EndIf
        Next

    Until $arrDims[1][0]=$arrDims[1][1]
    Return ConsoleWrite(@CRLF)
EndFunc

 

Edited by spudw2k
  • Like 1

Share this post


Link to post
Share on other sites
czardas
6 hours ago, spudw2k said:

Neat stuff.  I wasn't clear on what the _PreDim function was doing at first.  It "looked" like a transposition.  I used a fun Dynamic Array Enumerate function I made to visualize and understand it.  I noticed it also "seems" to only support up-to 7 dimensions, leaving the original array unchanged.

Thanks. :) The alpha version I posted a few days ago only worked for up to 7 dimensions. I just ran your test with 9 dimensions (the current limit) and it seems fine.

Trying to visualize multidimensional arrays always used to give me a bit of a headache. I'm sure there's nothing particularly new here, and  It's only through the insights I have gained from others that I came to the choices that I made. It's too early to tell how useful the UDF might be. Two dimensions is enough for most typical applications and there are some really great functions already in Array.au3 (much improved recently by @Melba23).

I'm glad people like it. :thumbsup:

Share this post


Link to post
Share on other sites
spudw2k
1 minute ago, czardas said:

Thanks. :) The alpha version I posted a few days ago only worked for up to 7 dimensions. I just ran your test with 9 dimensions (the current limit) and it seems fine.

Ah, I didn't catch the code update; got it.  Once again, cool stuff.

  • Like 1

Share this post


Link to post
Share on other sites
czardas

This UDF is starting to take shape. I have added three new functions _DeleteDimension(), _ExtractRegion() and _SearchArray(). The example below shows the intended use of all of three functions. This covers a small flexible subset of those features I consider programmatically useful, and particularly relevant to my own projects. Who wants to mess about trying to get all that array syntax right when you can just let a function do most of the tedious work for you?

Fruit Cube

#include <Array.au3>
#include <MsgBoxConstants.au3>
#include 'ArrayWorkshop.au3'

; Example 4 - Fruit Cube [3D Search = cherries]

; create a 3D array of fruit machines
Local $aWheelNum1 = ['strawberry', 'cherries', 'melon', 'pomegranate', 'lemon'] ; 1D array
Local $aWheelNum2 = ['7', 'bell', 'BAR', '$'] ; not so many cherries in this one huh!

Local $aFruitMachine = $aWheelNum1 ; start with a 1D array
For $i = 2 To 5 ; add some more 1D arrays
    _ArrayAttach($aFruitMachine, $aWheelNum2, 2) ; 1D concatenation employed in the 2nd dimension
Next

; it's easier to set indices for each machine to the first dimension
_Predim($aFruitMachine, 3, True) ; convert 2D to 3D - push current dimensions up one level

Local $aFruitCube = $aFruitMachine ; continue cube construction using the 3D array
For $i = 2 To 10 ; add some more fruit machines [10 in total]
    _ArrayAttach($aFruitCube, $aFruitMachine) ; 3D concatenation employed in the 1st dimension
Next

_ShuffleArray($aFruitCube, 0) ; shuffle the array - ignoring dimension bounds to mix things up a little bit

Local $aSearchResults = _SearchArray($aFruitCube, 'cherries') ; search through 1st dimensional indeces [for cherries]
MsgBox($MB_OK, "cherries", UBound($aSearchResults) & ' matches found in 10 fruit machines') ; machines containing cherries

For $i = 0 To UBound($aSearchResults) -1 ; loop through the search results
    $aFruitMachine = _ExtractRegion($aSearchResults, 1, $i) ; extract each machine [3D]
    _DeleteDimension($aFruitMachine, 1) ; delete the 1st dimension for _ArrayDisplay() [no data loss here ==> Ubound($aFruitMachine, 1) = 1]
    _ArrayDisplay($aFruitMachine, 'machine ' & $i +1 & ' contains cherries') ; now we are back to 2D, so we can check everything's working
Next

 

Edited by czardas

Share this post


Link to post
Share on other sites
czardas

New version uploaded - see first post. No new functions - just two bug fixes.

Spoiler

Bugfix 1. _ArrayAttach() hanging with 1D array output. - Fixed
Bugfix 2. _ExtractRegion() hanging with 1D array output. - Fixed

 

Edited by czardas

Share this post


Link to post
Share on other sites
czardas

New function added - _ArraySortXD() -  version 0.2.0-beta (see 1st post). You'll need your waders to get through this one. Because of the complexity, I decided a short tutorial was in order (see below). The function can sort numeric decimal strings of any magnitude. There is only one float which can be larger than a decimal string, and that is infinity. When sorting numeric decimal strings, comparisons are also made between integers and floats.

Like most of the other functions in this thread, _ArraySortXD() works for up to nine dimensions in every sense. You can sort array regions based on item positions within vectors associated with any available dimension. The function aims to be robust and competitive (holding its own against its predecessor), and it is designed to assist in the construction of complex engines requiring multidimensional arrays. Credit is due to the authors of the original _ArraySort() function, and a full list of influential contributors will be added in due course. Have fun!

;============================================================
; _ArraySortXD Tutorial
;============================================================

#include <Array.au3>
#include <MsgBoxConstants.au3>
#include 'ArrayWorkshop.au3'

; Before continuing...
MsgBox($MB_OK, "Important!", "Be sure to read the title on each display.")

;============================================================
; 1. Let's start with 1 dimensional arrays.
;============================================================
Local $aNames = ["corgano", "Rex", "czardas", "trancexx", "iamtheky", "Bowmore", "Chimp", "mikell", "jchd", "argumentum", _
"kcvinu", "Jfish", "spudw2k", "qwert", "soft4pedia", "BrewManNH", "mLipok", "jaberwacky", "Danyfirex", "guinness", "UEZ"]
_ArraySortXD($aNames) ; default algorithm is lexical
_ArrayDisplay($aNames, "1. after sorting")

;============================================================
; 2. Now let's sort the list descending.
;============================================================
_ShuffleArray($aNames) ; mix up the names again
_ArrayDisplay($aNames, "2a. after shuffling")
Local $iAlgo = 1 ; sort descending
_ArraySortXD($aNames, Default, $iAlgo) ; default dimension = 1
_ArrayDisplay($aNames, "2b. reverse sort")

;============================================================
; 3. Sorting a range.
;============================================================
Local $iStart = 5, $iStop = 15
$iAlgo = 0
_ShuffleArray($aNames) ; mix up the names again
_ArraySortXD($aNames, Default, $iAlgo, $iStop, $iStart) ; $iStop and $iStart in the default dimension
_ArrayDisplay($aNames, "3. sort range " & $iStart & " to " & $iStop)

;============================================================
; 4. Sorting numbers lexically.
;============================================================
Local $aIntegers = [10, 2, 9, 300, 64, 123, 100, 20, -5, -23, -19, 801, -5007, -1, -63, -64, -65]
_ArraySortXD($aIntegers) ; lexical sorting
_ArrayDisplay($aIntegers, "4. integers lexical") ; Not exactly what you would expect?

;============================================================
; 5. Sorting numbers numerically.
;============================================================
$iAlgo = 2
_ArraySortXD($aIntegers, Default, $iAlgo) ; numeric sorting
_ArrayDisplay($aIntegers, "5. integers numeric") ; that's more like it!

;============================================================
; 6. Aplhanumeric sort.
;============================================================
_ArrayAttach($aNames, $aIntegers) ; first concatenate names with integers
_ShuffleArray($aNames) ; mix up the data once again
$iAlgo = 4 ; alphanumeric
_ArraySortXD($aNames, Default, $iAlgo) ; alphanumeric sorting
_ArrayDisplay($aNames, "6. alphanumeric")

;============================================================
; 7. Sorting in 2 dimensions.
;============================================================
Local $aAlphaNumeric = _
[['one','two','three','four','five','six','seven','eight','nine','ten'], _
['I','II','III','IV','V','VI','VII','VIII','IX','X'], _
[1,2,3,4,5,6,7,8,9,10], _
['a','b','c','d','e','f','g','h','i','j'], _
['alpha','beta','gamma','delta','epsilon','zeta','eta','theta','iota','kappa'], _
['First','Second','Third','Fourth','Fifth','Sixth','Seventh','Eighth','Ninth','Tenth']]
_ArrayDisplay($aAlphaNumeric, '7a. before sorting')

_ArraySortXD($aAlphaNumeric) ; Sort rows lexically.
_ArrayDisplay($aAlphaNumeric, '7b. default lexical sort on the first column')

Local $iCol = 5
$iAlgo = 1 ; reverse sort
$iStart = 1 ; ignores the first row
$iStop = Default
_ArraySortXD($aAlphaNumeric, Default, $iAlgo, $iStop, $iStart, $iCol) ; Sort on col 5, starting from row 1
_ArrayDisplay($aAlphaNumeric, '7c. reverse sort on column 5 - ignoring the 1st row')

;============================================================
; 8. Sorting in the 2nd dimension.
;============================================================
Local $iDimension = 2 ; instead of sorting rows you can also sort columns
Local $iRow = 4 ; the row to use to sort the columns [1st dimension sub-index]
$iStart = 0 ; starting from the first column
$iStop = 6 ; only sort the first seven columns
$iAlgo = Default
_ArraySortXD($aAlphaNumeric, $iDimension, $iAlgo, $iStop, $iRow, $iStart)
_ArrayDisplay($aAlphaNumeric, '8a. sort the first seven columns on row 4')

$iRow = 2 ; the row to use to sort the columns [1st dimension sub-index]
$iStop = Default ; sort all columns (or rows)
_ArraySortXD($aAlphaNumeric, $iDimension, $iAlgo, $iStop, $iRow, $iStart)
_ArrayDisplay($aAlphaNumeric, '8b. all columns sorted on row 2')

;============================================================
; 9. More advanced numeric sorting.
;============================================================
Local $aDecimals = ['1.000000000000001', '43276590764538761097', '39830476429748701118', '11111111154321098705', '1.0000000000000009999', _
'222222222222222222222', '97611223222222', '890732597342782900543227', '-9', '-0.00000000000000000005', '7023', '300000000000', '8243097852349', _
'56423189049', '76596234001.876485335', '766545374390.0987455323', '820594000000000043', '2313414538342121.0000000654', '-4523', '10000000876655555557', _
'22222222222222222222', '0.000000000000543', '-0.000000000007625', '999999999', '99999998', '-99999998', '200000000', '-1.0', '.0005']
_ArrayDisplay($aDecimals, '9a. randomly typed numeric strings')

$iAlgo = BitOR(2, 256) ; sort numbers and decimal strings
$iDimension = Default ; 1st dimension
_ArraySortXD($aDecimals, $iDimension, $iAlgo)
_ArrayDisplay($aDecimals, '9b. numeric strings sorted by magnitude')

Local $aMoreNumbers = [(1/3)*10^20, 1/0, 1.23456789^200, -1/0, 1.94447653276963*10^-70, -1^.5, 1.0e-16, 13^6]
_ArrayAttach($aMoreNumbers, $aDecimals) ; concatenate
_ShuffleArray($aMoreNumbers)
_ArrayDisplay($aMoreNumbers, '9c. mixed numeric data types')

_ArraySortXD($aMoreNumbers, $iDimension, $iAlgo)
_ArrayDisplay($aMoreNumbers, '9d. mixed numeric data sorted')

;============================================================
; 10. Maintain original sequence for non-sorted items.
;============================================================
$iAlgo = BitOR(1, 2, 256, 512) ; descending, numeric, include decimal strings and maintain the original sequence for unsorted items
_ArrayAttach($aNames, $aMoreNumbers) ; concatenate ($aNames was sorted ascending earlier)
_ArrayDisplay($aNames, '10a. before numeric descending')

_ArraySortXD($aNames, $iDimension, $iAlgo)
_ArrayDisplay($aNames, '10b. unsorted items appear in the original sequence')

 

Edited by czardas

Share this post


Link to post
Share on other sites
iamtheky

Can you show me an example where

1)  you have a 4x4 3D cube

2) you sort the 3x3 cube inside the 4x4, leaving the 'outside' jumbled while the inside is sorted. 

(I know this sounds eerily similar to one of your super secret scripts, but shhh they will never know)

I think that will give me the best picture of a '3D range sort'.

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
czardas

I'm not quite sure what you mean by a 4x4 3D cube. Let's think of it like this: you have some cubes joined together in the fourth dimension. Let's say the first item in each cube is some kind of identifier positioned at element [X][0][0][0]. You can sort the cubes on the value of their identifiers within the range x = 1 To x = 10. Alternatively x could be in a different dimension and the identifier at another location like this: [2][3][x][8]. Does that make any sense?

Read the description in the function header and try sorting tables in 3D, or something not too complicated to figure it out. Then you can try for higher dimensions. I'll add some 3D/4D examples shortly. Not right now, I'm completely bushed after writing that.

Edited by czardas

Share this post


Link to post
Share on other sites
iamtheky

http://www.ebay.com/itm/like/161187154878?lpid=82&chn=ps&ul_noapp=true

 

now if even the ones on the inside of the rubiks cube had stickers: could you sort those sides and leave the outside jumbled?

(and i guess it a 2 sided cube that resides on the inside of a 4sided  cube..)

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
czardas

@iamtheky There are some functions yet to be included in this UDF. They will enable you to peel away the outer layer to get at the 3D core. The array could later be reconstructed using _ArrayAttach(). Perhaps not the most direct solution, but stripping functions are far simpler to write.

Share this post


Link to post
Share on other sites
czardas

As promised: an example of sorting the contents of a 3D array. I hadn't tested more than two dimensions when I posted version 0.2.0-beta yesterday, and I was a bit worried it might not work. Thank goodness it did. :sweating: I have tried to make this an easy example.

Example: Foul Play in the English Premiership

#include <Array.au3>
#include <ArrayWorkshop.au3>

; stats for the English premiership home games 2014-2015
Local $aHomeGames = [["","Fouls","Yellow Cards","Red Cards"],["Arsenal",179,27,1],["Aston Villa",191,28,4],["Burnley",212,33,0], _
["Chelsea",200,36,1],["Crystal Palace",270,26,2],["Everton",185,27,0],["Hull",229,28,3],["Leicester",225,20,2],["Liverpool",190,29,2], _
["Man City",234,35,1],["Man United",223,31,1],["Newcastle",208,33,1],["QPR",222,36,1],["Southampton",232,23,2],["Stoke",240,33,0], _
["Sunderland",218,45,1],["Swansea",195,25,1],["Tottenham",219,37,1],["West Brom",197,34,1],["West Ham",204,33,1]]
_ArrayDisplay($aHomeGames, 'Home Games')

; stats for the English premiership away games 2014-2015
Local $aAwayGames = [["","Fouls","Yellow Cards","Red Cards"],["Arsenal",218,36,2],["Aston Villa",205,41,2],["Burnley",203,34,0], _
["Chelsea",223,42,3],["Crystal Palace",234,35,1],["Everton",233,40,3],["Hull",228,34,4],["Leicester",176,28,5],["Liverpool",255,43,2], _
["Man City",144,34,3],["Man United",223,42,2],["Newcastle",231,55,0],["QPR",216,28,1],["Southampton",197,30,2],["Stoke",221,34,2], _
["Sunderland",243,38,2],["Swansea",246,52,2],["Tottenham",187,37,1],["West Brom",219,26,2],["West Ham",247,36,6]]
_ArrayDisplay($aAwayGames, 'Away Games')

; now let's make this a 3D cuboid
Local $aCuboid = $aHomeGames ; create a 2D template
_ArrayAttach($aCuboid, $aHomeGames, 3) ; stack tables [3D]
_ArrayAttach($aCuboid, $aAwayGames, 3) ; ditto

; calculate the total number of fouls, yellow cards and red cards for games played home and away
For $i = 1 To UBound($aCuboid) -1 ; loop through the teams
    For $j = 1 To 3 ; [fouls, yellow cards, red cards]
        $aCuboid[$i][$j][0] = $aCuboid[$i][$j][1] + $aCuboid[$i][$j][2] ; add two values from each 3D region
    Next
Next

; THE (VERY FIRST) 3D TEST
; sort the 3D array from the highest to the lowest number of fouls (home and away)
_ArraySortXD($aCuboid, 1, 2+1, -1, 1, 1) ; this is just an example

; let's check to see if _ArraySortXD actually works [^^]
; because we stacked the tables in a certain way, we can delete the 3rd dimension and check the result with _ArrayDisplay
_DeleteDimension($aCuboid, 3) ; other methods can also be used to check the contents of the first table in the 3D stack
_ArrayDisplay($aCuboid, 'Dirtiest Premiership Team in 2015')

Regarding the suggestion by @iamtheky above, the complication of limiting array regions in every dimension would involve additional stop parameters (for up to nine dimensions) and have a negative impact on speed. It's actually more complicated than that. Nice idea though!

Edited by czardas
  • Like 1

Share this post


Link to post
Share on other sites
iamtheky

That is a clean example too, gives me hope for understanding the workshop!

  • Like 1

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
stealthmsgr

Thanks millions czardas for posting this on arrays. I'm new into the array area and this should prove to be a great learning tool. I have a small project that I'm working on if you could take a look and let me know how to solve it. I believe an array would be best. As a newbie into arrays perhaps you could give me some pointers. I'll give you some detail if you have time to look it over.

 

 

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

  • Similar Content

    • Dzenan03
      By Dzenan03
      I want to make a while loop, that creates variables based on a array. For thist I created the array $iDsO with the number and the name of folders in an other folder. Every folder has a different name an I want to create variables(arrays) for each folder that show me all the files in that folder. For example: I have the Folder \Folder1. In it there are the Folders \1, \2, \3. In 1, 2 and 3 there are some files(.png). The array for Folder1 is $iDsO and now I want to crate the arrays $iDsO1, $iDsO2 and $iDsO3 with the files in them can I make something like this:
      While $iDs > 0 ;$iDs is the number of files in Folder1>> $iDsO[0] $iDs#here should come the Foldername for example '1'# = _FileListtoArray(@ProgramFilesDir&"\Folder1\"&$iDsO[$iDs]) $iDs = $iDs - 1 Wend So that in the End I have three variabels ($iDs1, $iDs2 and $iDs3)
       
      Is this posible or if not what could I do instead ( I don´t know the number of folders in Folder1 in the begining).
    • liagason
      By liagason
      Hello everyone,
      How can I display in ascending  sequence some numbers stored in a string variable?
      $str = "18,03,48,23" MsgBox(0,"test",$str) I would like it to display "03,18,23,48"
    • rm4453
      By rm4453
      I have a table I am parsing, to find specific vehicle information. I am unable to get _ArrayFindAll to return the only valid result with my test data.
      Below is a sample of the table's HTML:
      <td class="textCenter">2010</td> <td>TOYOTA</td> <td>TACOMA 4X4 DB</td> <td></td> <td>BLACK</td> <td class="textCenter">C</td> <td class="textCenter">6</td> <td>GAS</td> <td class="textCenter">A</td> <td class="textCenter">4X4</td> <td class="textCenter">Y</td> <td>CD</td> <td class="textCenter">HT</td> <td class="textCenter">C</td> <td class="textRight" nowrap="nowrap">80,975</td> <td class="textRight" nowrap="nowrap">$16,800</td> </tr> <tr><!-- 308 --> <td class="textCenter">2010</td> <td>TOYOTA</td> <td>TACOMA 4X4 RG</td> <td></td> <td>BLACK</td> <td class="textCenter">R</td> <td class="textCenter">4</td> <td>GAS</td> <td class="textCenter">5</td> <td class="textCenter">4X4</td> <td class="textCenter">A</td> <td>CD</td> <td class="textCenter">HT</td> <td class="textCenter">C</td> <td class="textRight" nowrap="nowrap">95,224</td> <td class="textRight" nowrap="nowrap">$9,500</td> </tr> <tr><!-- 309 --> <td class="textCenter">2011</td> <td>BUICK</td> <td>REGAL</td> <td>CXL RL4</td> <td>BLACK</td> <td class="textCenter">4</td> <td class="textCenter">4</td> <td>GAS</td> <td class="textCenter">A</td> <td class="textCenter"></td> <td class="textCenter">A</td> <td>CD</td> <td class="textCenter">SR</td> <td class="textCenter">L</td> <td class="textRight" nowrap="nowrap">102,694</td> <td class="textRight" nowrap="nowrap">$5,000</td> </tr> <tr><!-- 310 --> <td class="textCenter">2011</td> <td>CHEVROLET</td> <td>AVALANCH 4X4 CR</td> <td>LS</td> <td>GRAY</td> <td class="textCenter">C</td> <td class="textCenter">8</td> <td>E</td> <td class="textCenter">A</td> <td class="textCenter">4X4</td> <td class="textCenter">A</td> <td>CD</td> <td class="textCenter">HT</td> <td class="textCenter">C</td> <td class="textRight" nowrap="nowrap">64,759</td> <td class="textRight" nowrap="nowrap">$16,300</td> </tr> <tr><!-- 311 --> <td class="textCenter">2011</td> <td>CHEVROLET</td> <td>EQUINOX AWD 4C</td> <td>LT W/2LT</td> <td>BLACK</td> <td class="textCenter">S</td> <td class="textCenter">4</td> <td>GAS</td> <td class="textCenter">A</td> <td class="textCenter">AWD</td> <td class="textCenter">Y</td> <td>CD</td> <td class="textCenter">SR</td> <td class="textCenter">C</td> <td class="textRight" nowrap="nowrap">91,896</td> <td class="textRight" nowrap="nowrap">$4,400</td> </tr> <tr><!-- 312 --> <td class="textCenter">2011</td> <td>CHEVROLET</td> <td>TAHOE 4X4 V8</td> <td>LTZ</td> <td>WHITE</td> <td class="textCenter">S</td> <td class="textCenter">8</td> <td>C</td> <td class="textCenter">A</td> <td class="textCenter">4X4</td> <td class="textCenter">A</td> <td>N</td> <td class="textCenter">MR</td> <td class="textCenter">L</td> <td class="textRight" nowrap="nowrap">126,982</td> <td class="textRight" nowrap="nowrap">$17,800</td> </tr> <tr><!-- 313 --> <td class="textCenter">2011</td> <td>CHEVROLET</td> <td>1500 SLV 4X4 EX</td> <td>LT</td> <td>GRAY</td> <td class="textCenter">X</td> <td class="textCenter">8</td> <td>GAS</td> <td class="textCenter">O</td> <td class="textCenter">4X4</td> <td class="textCenter">A</td> <td>CD</td> <td class="textCenter">HT</td> <td class="textCenter">C</td> <td class="textRight" nowrap="nowrap">60,303</td> <td class="textRight" nowrap="nowrap">$18,100</td> </tr> <tr><!-- 314 --> <td class="textCenter">2011</td> <td>CHEVROLET</td> <td>1500 SLV 4X4 EX</td> <td>LT</td> <td>SILVER</td> <td class="textCenter">X</td> <td class="textCenter">8</td> <td>E</td> <td class="textCenter">O</td> <td class="textCenter">4X4</td> <td class="textCenter">A</td> <td>CD</td> <td class="textCenter">HT</td> <td class="textCenter">C</td> <td class="textRight" nowrap="nowrap">89,403</td> <td class="textRight" nowrap="nowrap">$15,900</td> </tr> <tr><!-- 315 --> <td class="textCenter">2011</td> <td>CHEVROLET</td> <td>1500 SLV 4X4 EX</td> <td>LTZ</td> <td>BLUE</td> <td class="textCenter">X</td> <td class="textCenter">8</td> <td>E</td> <td class="textCenter">A</td> <td class="textCenter">4X4</td> <td class="textCenter">A</td> <td>CD</td> <td class="textCenter">HT</td> <td class="textCenter">L</td> <td class="textRight" nowrap="nowrap">53,087</td> <td class="textRight" nowrap="nowrap">$17,700</td> </tr> <tr><!-- 316 --> <td class="textCenter">2011</td> <td>CHEVROLET</td> <td>3500 CUTAWAY</td> <td>WORK VAN</td> <td>WHITE</td> <td class="textCenter">S</td> <td class="textCenter"></td> <td></td> <td class="textCenter">A</td> <td class="textCenter">4X2</td> <td class="textCenter"></td> <td>N</td> <td class="textCenter">HT</td> <td class="textCenter">C</td> <td class="textRight" nowrap="nowrap">202,477</td> <td class="textRight" nowrap="nowrap">$2,700</td> </tr> <tr><!-- 317 --> <td class="textCenter">2011</td> <td>CHRYSLER</td> <td>TOWN &amp; COUNTRY</td> <td>TOURING</td> <td>BLACK</td> <td class="textCenter">4</td> <td class="textCenter">6</td> <td>E</td> <td class="textCenter">A</td> <td class="textCenter">4X2</td> <td class="textCenter">A</td> <td>CD</td> <td class="textCenter">HT</td> <td class="textCenter"></td> <td class="textRight" nowrap="nowrap">198,541</td> <td class="textRight" nowrap="nowrap">$1,900</td> </tr> <tr><!-- 318 --> <td class="textCenter">2011</td> <td>DODGE</td> <td>DURANGO AWD V6</td> <td>CREW</td> <td>BLUE</td> <td class="textCenter">S</td> <td class="textCenter">6</td> <td>GAS</td> <td class="textCenter">A</td> <td class="textCenter">AWD</td> <td class="textCenter">A</td> <td>CD</td> <td class="textCenter">SR</td> <td class="textCenter">C</td> <td class="textRight" nowrap="nowrap">176,036</td> <td class="textRight" nowrap="nowrap">$2,800</td> </tr> <tr><!-- 319 --> <td class="textCenter">2011</td> <td>FORD</td> <td>FOCUS</td> <td>SE</td> <td>SILVER</td> <td class="textCenter">4</td> <td class="textCenter">4</td> <td>GAS</td> <td class="textCenter">A</td> <td class="textCenter"></td> <td class="textCenter">Y</td> <td>CD</td> <td class="textCenter">HT</td> <td class="textCenter">C</td> <td class="textRight" nowrap="nowrap">101,929</td> <td class="textRight" nowrap="nowrap">$3,100</td> </tr> <tr><!-- 320 --> <td class="textCenter">2011</td> <td>FORD</td> <td>FUSION FWD 4C</td> <td>SEL</td> <td>WHITE</td> <td class="textCenter">4</td> <td class="textCenter">4</td> <td>GAS</td> <td class="textCenter">A</td> <td class="textCenter"></td> <td class="textCenter">Y</td> <td>CD</td> <td class="textCenter">SR</td> <td class="textCenter">L</td> <td class="textRight" nowrap="nowrap">78,290</td> <td class="textRight" nowrap="nowrap">$5,500</td> </tr> <tr><!-- 321 --> <td class="textCenter">2011</td> <td>FORD</td> <td>F150 4X4 CR</td> <td>XLT</td> <td>BLACK</td> <td class="textCenter">C</td> <td class="textCenter">8</td> <td>GAS</td> <td class="textCenter">A</td> <td class="textCenter">4X4</td> <td class="textCenter">Y</td> <td>CD</td> <td class="textCenter">HT</td> <td class="textCenter">C</td> <td class="textRight" nowrap="nowrap">70,909</td> <td class="textRight" nowrap="nowrap">$16,000</td> </tr> <tr><!-- 322 --> <td class="textCenter">2011</td> <td>FORD</td> <td>MUSTANG V6 CPE</td> <td>V6 PREMIUM</td> <td>BLACK</td> <td class="textCenter">2</td> <td class="textCenter">6</td> <td>GAS</td> <td class="textCenter">A</td> <td class="textCenter">4X2</td> <td class="textCenter">A</td> <td>CD</td> <td class="textCenter">HT</td> <td class="textCenter">L</td> <td class="textRight" nowrap="nowrap">92,531</td> <td class="textRight" nowrap="nowrap">$2,700</td> </tr> <tr><!-- 323 --> <td class="textCenter">2011</td> <td>GMC</td> <td>ACADIA FWD</td> <td>SLE</td> <td>RED</td> <td class="textCenter">4</td> <td class="textCenter">6</td> <td>GAS</td> <td class="textCenter">A</td> <td class="textCenter"></td> <td class="textCenter">A</td> <td>CD</td> <td class="textCenter">HT</td> <td class="textCenter">C</td> <td class="textRight" nowrap="nowrap">79,199</td> <td class="textRight" nowrap="nowrap">$10,700</td> A picture of the table test data is attached here:

      Here is the _query function, and all other relevant code that I can share.
       
      Func _query($aSel, $aUrls) $oIE = _login() If $oIE = "Return" Then Return EndIf $j = 0 While $j < UBound($aSel) - 1 $i = 1 $aucID ;Unable To Share What This Is Other Than Var Name. _IENavigate($oIE, "Something" & $aucID[0] & "Something") _IELoadWait($oIE, 100, 2000) $oObj = _IETableGetCollection($oIE, 3) $cars = _IETableWriteToArray_ProgressBar($oObj, True, "Processing Requested Information!") ;<---- Modified Version See Post For It: https://www.autoitscript.com/forum/topic/195335-solved-how-to-add-a-progress-bar-to-_ietablewritetoarray/?tab=comments#comment-1400699 $carsYear = _filter($cars, 0, 0, GUICtrlRead($year)) $carsMake = _filter($carsYear, 0, 1, GUICtrlRead($make)) Global $carsModel = _filter($carsMake, 0, 2, GUICtrlRead($model)) $i = 0 $engine = GUICtrlRead($engine) If $engine <> "" Then While $i < StringLen($engine) $carsEngine = _filter($carsModel, 0, 6 + $i, StringLeft($engine, 1)) ;_ArrayDisplay($carsModel, "Cars Model Before Array Delete") $x = 1 While $x <= UBound($carsModel) _ArrayDelete($carsModel, $x) $x += 1 WEnd ;_ArrayDisplay($carsModel, "Cars Model After Array Delete") ;_ArrayConcatenate($carsModel, $carsEngine) ;_ArrayDisplay($carsModel, "Cars Model After Concatenate") $engine = StringTrimLeft($engine, 1) $i += 1 WEnd Else Dim $carsEngine[1][16] EndIf _ArrayConcatenate($carsEngine, $carsModel) _ArrayDisplay($carsEngine, "Cars Engine") Dim $carsDriveTrain[1][16] Dim $carsDriveTrain2[1][16] $driveTrainVal = GUICtrlRead($driveTrain) If $driveTrainVal = "4x4" Or $driveTrainVal = "awd" Then $carsDriveTrain = _filter($carsEngine, 0, 9, "4") $carsDriveTrain2 = _filter($carsEngine, 0, 9, "a") ;~ _ArrayDisplay($carsDriveTrain, "Drive Train Before") ;~ If @error Then ;~ MsgBox("", "", "Cars Drive Train Error: " & @error) ;~ EndIf ;~ _ArrayDisplay($carsDriveTrain2, "Drive Train2 Before") ;~ If @error Then ;~ MsgBox("", "", "Cars Drive Train 2 Error: " & @error) ;~ EndIf _ArrayConcatenate($carsDriveTrain, $carsDriveTrain2) _ArrayDisplay($carsDriveTrain, "Drive Train After Concat") ElseIf $driveTrainVal = "" Then _ArrayConcatenate($carsDriveTrain, $carsEngine) Else $carsDriveTrain = _filter($carsEngine, 0, 9, $driveTrain) EndIf Dim $carsOdom[1][16] $min = GUICtrlRead($odomMin) $max = GUICtrlRead($odomMax) For $i = 0 To UBound($carsDriveTrain) - 1 If $carsDriveTrain[$i][14] > $min And $carsDriveTrain[$i][14] < $max Then _ArrayAdd($carsOdom, $carsDriveTrain[$i]) MsgBox("", "", "ADDED!") EndIf Next _ArrayDisplay($carsOdom, "Cars Odom") $j += 1 WEnd _IEQuit($oIE) EndFunc ;==>_query Func _filter($tofilter, $xpos1, $ypos1, $str) ;~ If UBound($tofilter, 1) <= 1 Then ;~ $endx = 0 ;~ Else ;~ $endx = UBound($tofilter, 1) - 1 ;~ EndIf ;~ $cars = _ArrayFindAll($tofilter, $str, $tofilter[$xpos1][$ypos1], $tofilter[$endx][$ypos1], 0, 1, $ypos1, False) $cars = _ArrayFindAll($tofilter, $str, Default, Default, 0, 1, $ypos1) Dim $carsFiltered[1][16] = [["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p"]] ;_ArrayDisplay($carsFiltered) $i = 0 $uBound = UBound($cars) - 1 While $i < $uBound $filtered = _ArrayExtract($tofilter, $cars[$i], $cars[$i], 0, 15) ;_ArrayDisplay($filtered, "_filter Array of Filtered") _ArrayConcatenate($carsFiltered, $filtered) $i += 1 WEnd _ArrayDelete($carsFiltered, 0) Return $carsFiltered EndFunc ;==>_filter  
      If you know of a more efficient way of doing this please let me know would be more than happy to chew down my inefficiency while learning! (It's like my grandpa used to say, "The only criticism I can't use is that which is not given to me.")
       
      The Item an I am using to test the filter is:

       
    • rm4453
      By rm4453
      Hello,
       
      I am currently writing a program that parses a massive table from a website, and need a way to add a progress bar while parsing.
      I am currently using the function _IETableWriteToArray($oObj, True) to parse the array. I need the progress bar to update as the table is parsed, not just at the end of the parsing.
      Any help at all would be very much appreciated!
       
      *EDIT --> The array I am left with after parsing is $array[0-50000][16]
    • TrashBoat
      By TrashBoat
      So Im trying to make a simple 2d game and make some sort of collision detection so why not to make a 2 dimensional array but i have no clue how  to write it in multiple lines
      Global $map[5,5] = [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0] something like this but it doesn't work
×