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

    • HardXOR
      By HardXOR
      Hello AutoIt community
      I run into speed problem in my script wich i cant solve myself, problem is with decoding texture loop - for better explanation, you need extract from file pallete (16x 16 RGB color) and picture data (224 * 128 byte), then use correct color for your picture data.... nothing extra hard and also texture is quite small 224*256
      it is for my car model viewer/later maybe editor GranTurismo 2 from Playstation 1, so its old dataformat and i cant understand why AutoIt take so long to decode texture when good old Playstation almost 2,5 decades old can do that nearly immediately (when you list through cars in shop or garage)
      My first atempt was create all trought dllstructure, because its easier approach, but it was soooo slow (40-50s for create textures) then i upgrade my routine via arrays, first 3D arrays later only 1D, next i put decoding colors outside loop but it is still not enough, my last version took cca 15s wich is still unacceptable for car model viewer when you click on one carmodel from listview (1100 cars for whole game) and you must wait 15-16s for model to load....  oh and i forgot mention some cars have more then 1 color (much more... 8-9-10 etc) soloading take 8-9-10 times more time
      in attachment i post texture file from GranTurismo 2 for one car (contain only 1 color) and also my dll struct version and array version code
      dll struct version - ± 40 sec (33 without saving)
      #include <FileConstants.au3> Global $IMDT[256][256][4] LoadTexture("ufs9r.cdp") Func LoadTexture($file) $fileHandle = FileOpen($file, $FO_BINARY) $header = FileRead($fileHandle, 0x20) ConsoleWrite("header> " & $header & @CRLF) $PAL = FileRead($fileHandle, 0x200) ConsoleWrite("PAL> " & $PAL & @CRLF) FileSetPos($fileHandle, 0x43A0, $FILE_BEGIN) $IMD = FileRead($fileHandle, 0x7000) ConsoleWrite("IMD> " & $IMD & @CRLF) $st = DllStructCreate("BYTE[512]") DllStructSetData($st, 1, $PAL) $struct_PAL = DllStructCreate("WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16]", DllStructGetPtr($st)) $struct_IMD = DllStructCreate("BYTE[" & 0x7000 & "]") DllStructSetData($struct_IMD, 1, $IMD) $start = TimerInit() For $i = 0 To 15 For $j = 0 To 223 $cn = 0 For $k = 0 To 127 $bt = DllStructGetData($struct_IMD, 1, $j * 128 + $k + 1) $blue = BitShift(DllStructGetData($struct_PAL, $i + 1, BitAND($bt, 0x0F) + 1), 7) $IMDT[$j][$cn][0] = $blue $green = BitShift(DllStructGetData($struct_PAL, $i + 1, BitAND($bt, 0x0F) + 1), 2) $IMDT[$j][$cn][1] = $green $red = BitShift(DllStructGetData($struct_PAL, $i + 1, BitAND($bt, 0x0F) + 1), - 3) $IMDT[$j][$cn][2] = $red If DllStructGetData($struct_PAL, $i + 1, BitAND($bt, 0x0F) + 1) = 0 Then $IMDT[$j][$cn][3] = 0x00 Else $IMDT[$j][$cn][3] = 0xFF EndIf $cn += 1 $blue = BitShift(DllStructGetData($struct_PAL, $i + 1, BitShift($bt, 4) + 1), 7) $IMDT[$j][$cn][0] = $blue $green = BitShift(DllStructGetData($struct_PAL, $i + 1, BitShift($bt, 4) + 1), 2) $IMDT[$j][$cn][1] = $green $red = BitAND(BitShift(DllStructGetData($struct_PAL, $i + 1, BitShift($bt, 4) + 1), - 3), 0xFF) $IMDT[$j][$cn][2] = $red If DllStructGetData($struct_PAL, $i + 1, BitShift($bt, 4) + 1) = 0 Then $IMDT[$j][$cn][3] = 0x00 Else $IMDT[$j][$cn][3] = 0xFF EndIf $cn += 1 Next Next saveTGA($i) Next ConsoleWrite("t " & TimerDiff($start) & @CRLF) ; +- 40 seconds FileClose($fileHandle) EndFunc Func saveTGA($name) Local $tga[18] = [0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x20, 0x20] Local $data for $i = 0 To 17 $data &= Hex($tga[$i], 2) Next For $i = 0 To 255 For $j = 0 To 255 For $k = 0 To 3 $data &= hex($IMDT[$i][$j][$k], 2) Next Next Next $binary = FileOpen("test\" & $name & ".tga", BitOR($FO_BINARY, $FO_OVERWRITE, $FO_CREATEPATH)) FileWrite($binary, "0x" & $data) FileClose($binary) EndFunc  
      array version - ± 15 sec (under 10s without saving)
      #include <FileConstants.au3> LoadTexture2("ufs9r.cdp") Func LoadTexture2($file) $fileHandle = FileOpen($file, $FO_BINARY) $a = TimerInit() Global $header[0x20] For $i = 0 To UBound($header) - 1 $header[$i] = Int(String(FileRead($fileHandle, 1))) ; read 0x20 bytes Next ConsoleWrite("header " & TimerDiff($a) & @CRLF) $a = TimerInit() Global $PAL[0x100] For $i = 0 To UBound($PAL) - 1 $PAL[$i] = Number(FileRead($fileHandle, 2)) ; read 0x200 (16*16) words Next Global $PALcolor[16 * 16 * 4] For $i = 0 To UBound($PAL) - 1 $PALcolor[$i * 4 + 0] = BitShift($PAL[$i], 7) $PALcolor[$i * 4 + 1] = BitShift($PAL[$i], 2) $PALcolor[$i * 4 + 2] = BitShift($PAL[$i], -3) If $PAL[$i] = 0 Then $PALcolor[$i * 4 + 3] = 0x00 Else $PALcolor[$i * 4 + 3] = 0xFF EndIf Next ConsoleWrite("PAL " & TimerDiff($a) & @CRLF) $a = TimerInit() FileSetPos($fileHandle, 0x43A0, $FILE_BEGIN) Global $IMD[0x7000] For $i = 0 To UBound($IMD) - 1 $IMD[$i] = Int(String(FileRead($fileHandle, 1))) ; read 0x7000 bytes Next ConsoleWrite("IMD " & TimerDiff($a) & @CRLF) Global $IMDT[256*256*4] $a = TimerInit() For $i = 0 To 15 For $j = 0 To 223 $cn = 0 For $k = 0 To 127 $byte = $IMD[$j * 128 + $k] ; byte for decode $index = $j * 1024 + $cn * 4 $index2 = $i * 0x40 + BitAND($byte, 0x0F) * 4 $IMDT[$index + 0] = $PALcolor[$index2 + 0] ; blue $IMDT[$index + 1] = $PALcolor[$index2 + 1] ; green $IMDT[$index + 2] = $PALcolor[$index2 + 2] ; red $IMDT[$index + 3] = $PALcolor[$index2 + 3] ; alpha $cn += 1 $index = $j * 1024 + $cn * 4 $index2 = $i * 0x40 + BitShift($byte, 4) * 4 $IMDT[$index + 0] = $PALcolor[$index2 + 0] ; blue $IMDT[$index + 1] = $PALcolor[$index2 + 1] ; green $IMDT[$index + 2] = $PALcolor[$index2 + 2] ; red $IMDT[$index + 3] = $PALcolor[$index2 + 3] ; alpha $cn += 1 Next Next ;~ $b = TimerInit() saveTGA2($i) ;~ ConsoleWrite("save TGA " & TimerDiff($b) & @CRLF) Next ConsoleWrite("full time " & TimerDiff($a) & @CRLF) ; 16 seconds FileClose($fileHandle) EndFunc Func saveTGA2($name) Local $tga[18] = [0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x20, 0x20] Local $data For $i = 0 To 17 $data &= Hex($tga[$i], 2) Next For $i = 0 To UBound($IMDT) - 1 $data &= Hex($IMDT[$i], 2) Next $binary = FileOpen("test\" & $name & ".tga", BitOR($FO_BINARY, $FO_OVERWRITE, $FO_CREATEPATH)) FileWrite($binary, "0x" & $data) FileClose($binary) EndFunc if anyone can optimize my code I would be very grateful, or pointing me to better solution, thx
      ufs9r.cdp
    • FMS
      By FMS
      Hello,
      Does somebody knows a quick way to split eash word to an array in a text?
      I've a text and want to have each word in that text in an array.

      I tried to get in some way multiple seperators inside stringsplit but couldn't get it to work.
      I hope to get an array like :
      $aArray[0] = "PARIJS"
      $aArray[1] = "AFN"
      $aArray[2] = "Air"
      ....
      sample text: PARIJS (AFN) - Air France-KLM heeft de financieel directeur van het Franse nuts- en vervoersbedrijf Veolia, Philipe Capron, in het vizier om de nieuwe topman van de luchtvaartcombinatie te worden. Volgens de krant La Tribune wordt Capron als favoriet beschouwd om de topfunctie te gaan vervullen. AdChoices Advertentie Volgens bronnen tegen La Tribune is de keuze voor Capron zelfs al gemaakt door Air France-KLM en zal zijn voordracht volgende week worden voorgelegd aan de raad van toezicht bij het bedrijf. Capron zou dan de opvolger worden van de opgestapte topman Jean-Marc Janaillac. In mei trad Janaillac af nadat het hem niet was gelukt buiten de bonden om zaken te doen met het eigen personeel. Sindsdien heeft een interim-bestuur de dagelijkse leiding. De zestigjarige Capron is sinds 2014 financieel directeur bij Veolia. Daarvoor werkte hij onder meer bij mediaconcern Vivendi. Minder macht Overigens zijn er ook geruchten dat de nieuwe topman van Air France-KLM direct een zetel zou krijgen in de raad van commissarissen van KLM. Binnen de Nederlandse divisie, die juist alles op alles zet om minder macht naar Parijs te laten vloeien, is men volgens ingewijden verbolgen over die gang van zaken. ,,Stank voor dank", zo klinkt het in de wandelgangen. Eerder zou Janaillac ook al hebben geprobeerd om een dikkere vinger in de pap te krijgen bij KLM, dat door de bank genomen beter presteert dan haar Franse zustermaatschappij. Dit lukte eerder niet, onder meer door inmenging van het Nederlandse kabinet. AdChoices Advertentie Geruchten Een woordvoerder van Air France-KLM wilde niet reageren op de geruchtenstroom. Het concern gaat er vanuit dat binnen afzienbare tijd een nieuwe bestuursvoorzitter benoemd zal worden. Minister Cora van Nieuwenhuizen (Infrastructuur) wilde evenmin ingaan op geruchten. ,,Ik heb hierover nog geen contact gehad met KLM, dus dat wil ik eerst even afwachten'', zei ze. Tweede Kamerleden spraken deze week tijdens een debat nog maar eens hun zorg uit over de ontwikkelingen bij Air France-KLM. Zij drongen aan op herbevestiging van oude afspraken over de relatief zelfstandige positie van KLM binnen de groep.>Exit code: 0 Time: 28.52  
    • VollachR
      By VollachR
      Hi,
      I'm looking for a way to take a number value from a Row2 of a 2D array and according to this check if files that appear in rows 3-11 in the array exists.
      For example, if the number in Row2 is 5 I need to check for the files in Row 3-6 only, if it is 6 than rows 3-7 and so on.
      I thought on using a FOR loop but I have very little experience with those.
      Can you suggest the best way to do what I need?
      BTW, the files in Rows 3-11 will usually have blank value for any row above the number in Row2 (e.g. Row2 = 5 so Rows3-6 will have values but 8-11 be empty), The values I need are in Column 1 of the array, the name of the key from the INI file that the array was created from is in Column 0.
      Full Example:
      Row2 of Array:
      Col0 = Games# - Col1 = 5
      Rows3-6
      Col0 = Exe2 - Col1 = Path To File
      Col0 = Exe3 - Col1 = Path To File
      Col0 = Exe4 - Col1 = Path To File
      Col0 = Exe5 - Col1 = Path To File
      I need that if Row2 is 5 to check these above for rows if the file exists, if it was 6 then the next row as well and so on up until number 10 in Row2 as it can't go above 10.
      So basically for whatever number in Row2 from 2-10 need to check 1-9 rows from 3-11 to see if the files in Col1 exists and if any of them don't exist it should call a function that shows an error message.
      I'm pretty sure I have the first line of the for look correct:
      For $i = 1 To $aAIO[2][1] Just not sure how to continue from there, also not sure if $i should be equal 1 or 2.
      Help will be appreciated.
    • FMS
      By FMS
      Hello,
      I'm trying to get data from twitter to an array and so far I found an Twitter UDF whish lookes very intresting but couldn't get it to work.
      It lookes not supported any more(2010) and buggy when i read all te replies.
      More around this subject (autoit and twitter) i couldn't find on this forum.
      Is there sombody who know's a good way to get live data from twitter to an array inside autoit?
      (I kinda doubt that this isn't tackled before)
      In the end I was hoping to get all tweets from date to date from an specific subject inside a 2D array to work whit.
    • AndreasNWWWWW
      By AndreasNWWWWW
      I got a question:  i am trying to run different functions based upon what i select in these radio buttons.(code below)
      it needs to check server 1. then run function 1 or function 2 after what i selected in the checkbox.
      once that function is done it moves to the next one, until it has been trough all 5 
       
      iv'e tried using while loops with different while $i equals to something but then i manualy need to go in and edit the script every time.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) $Server2 = GUICtrlCreateLabel("Server2", 216, 95, 41, 17) $server1 = GUICtrlCreateLabel("Server1", 216, 72, 41, 17) $server4 = GUICtrlCreateLabel("Server4", 216, 144, 41, 17) $server3 = GUICtrlCreateLabel("Server3", 216, 119, 41, 17) $server5 = GUICtrlCreateLabel("Server5", 216, 170, 41, 17) $Start = GUICtrlCreateButton("Start", 240, 248, 147, 25) $Checkbox1 = GUICtrlCreateCheckbox("function1", 288, 72, 97, 17) $Checkbox2 = GUICtrlCreateCheckbox("function2", 392, 72, 97, 17) $Checkbox3 = GUICtrlCreateCheckbox("function1", 288, 96, 97, 17) $Checkbox4 = GUICtrlCreateCheckbox("function2", 392, 96, 97, 17) $Checkbox5 = GUICtrlCreateCheckbox("function1", 288, 120, 97, 17) $Checkbox6 = GUICtrlCreateCheckbox("function2", 392, 120, 97, 17) $Checkbox7 = GUICtrlCreateCheckbox("function1", 288, 144, 97, 17) $Checkbox8 = GUICtrlCreateCheckbox("function2", 392, 144, 97, 17) $Checkbox9 = GUICtrlCreateCheckbox("function1", 288, 170, 97, 17) $Checkbox10 = GUICtrlCreateCheckbox("function2", 392, 170, 97, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  
×