eastern314 Posted February 11, 2011 Share Posted February 11, 2011 (edited) Hey ,guys, I am a new comer here. I come across an troublesome problem: Imagine there are five arrays: $a1[5]=[1,2,3,4,5] $a2[5]=[2,3,4,9,10] $a3[5]=[2,1,3,4,7] $a4[5]=[9,8,6,5,4] $a5[5]=[3,2,1,5,6] … … The Element 2 appears in $a,$b and $c, so Element 2 appears 3 times continuously. The element 1 appears in $a and $c and $c, so element 1 does not appear any time continuously. I wonder how to to count the times any element appears continuously in such a serials of arrays. It seems complicated. Is there any simple method? Thanks for you attention and you kind help. Edited February 11, 2011 by eastern314 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 11, 2011 Moderators Share Posted February 11, 2011 eastern314, Welcome to the AutoIt forum. Interesting little problem. Probably not the most elegant solution, but it seems to work: expandcollapse popup#include <Array.au3> Global $aArray[5][5] = [ _ [1, 2, 3, 4, 5], _ [2, 3, 4, 9, 10], _ [2, 1, 3, 4, 7], _ [9, 8, 6, 5, 4], _ [3, 2, 1, 5, 6]] Global $aCount[11] Global $aContinuous[11] Global $aResults[11] ; For each line For $i = 0 To 4 ; Reset current values array Global $aCurrent[11] ; Run through elements and set Current elements For $j = 0 To 4 $iItem = $aArray[$i][$j] $aCurrent[$iItem] = 1 Next ; Go through elements and check continuity For $j = 1 To 10 ; Is element present If $aCurrent[$j] Then ; Increase count $aContinuous[$j] += 1 Else ; Not present so check for previous continuity If $aContinuous[$j] > 1 Then $aResults[$j] += 1 $aContinuous[$j] = 0 EndIf Next Next ; Check for existing continuity For $j = 1 To 10 If $aContinuous[$j] > 1 Then $aResults[$j] += 1 Next _ArrayDisplay($aResults, "Final Results") I hope it does what you want. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
eastern314 Posted February 11, 2011 Author Share Posted February 11, 2011 eastern314, Welcome to the AutoIt forum. Interesting little problem. Probably not the most elegant solution, but it seems to work: expandcollapse popup#include <Array.au3> Global $aArray[5][5] = [ _ [1, 2, 3, 4, 5], _ [2, 3, 4, 9, 10], _ [2, 1, 3, 4, 7], _ [9, 8, 6, 5, 4], _ [3, 2, 1, 5, 6]] Global $aCount[11] Global $aContinuous[11] Global $aResults[11] ; For each line For $i = 0 To 4 ; Reset current values array Global $aCurrent[11] ; Run through elements and set Current elements For $j = 0 To 4 $iItem = $aArray[$i][$j] $aCurrent[$iItem] = 1 Next ; Go through elements and check continuity For $j = 1 To 10 ; Is element present If $aCurrent[$j] Then ; Increase count $aContinuous[$j] += 1 Else ; Not present so check for previous continuity If $aContinuous[$j] > 1 Then $aResults[$j] += 1 $aContinuous[$j] = 0 EndIf Next Next ; Check for existing continuity For $j = 1 To 10 If $aContinuous[$j] > 1 Then $aResults[$j] += 1 Next _ArrayDisplay($aResults, "Final Results") I hope it does what you want. M23 Thanks very much for your help. But i am so sorry that I made quite a lot of mistakes in my short question and i dont know how to edit it. As a new comer, i am not familiar with this forum very much. Please forgive me. Anyway , I will the method you give and learn from you. thanks again. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 11, 2011 Moderators Share Posted February 11, 2011 eastern314,You need a certain number of posts (5?) before you get the ability to edit your posts. If that does not do what you want, then what exactly do you want to do? I like little puzzles like this - keeps the litle grey cells active. M23P.S. When you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
eastern314 Posted February 12, 2011 Author Share Posted February 12, 2011 (edited) Thanks for you help,M23. I thought about the problems over and over again and I suddenly got a good idea. If you have some suggestion, pls let me know, thanks. Attached is an ini file from which I read the serial of arrays. expandcollapse popup#include <WindowsConstants.au3> #include <array.au3> $total=IniReadSection(@ScriptDir&"\test.ini","test") For $v=1 To 49 Dim $period[31] Dim $t=0 Dim $j=0,$value[31] For $i=0 To 30 $period[$i]=StringSplit($total[$i][1],",") If _ArraySearch($period[$i],$v,1)>0 Then $t+=1 EndIf If _ArraySearch($period[$i],$v,1)>0 Then $value[$j]=1 $j+=1 EndIf If _ArraySearch($period[$i],$v,1)=-1 Then $value[$j]=0 $j+=1 EndIf Next $a=StringReplace(_ArrayToString($value),"|","") $b=StringSplit($a,"0") Dim $two=0,$three=0,$four=0,$five=0 For $p=1 To UBound($b)-1 If $b[$p]="11" Then $two+=1 EndIf If $b[$p]="111" Then $three+=1 EndIf If $b[$p]="1111" Then $four+=1 EndIf ;If $b[$p]="11111" Then ; $five+=1 ;EndIf Next MsgBox(0,"","Number "&$v&" appears "&$t&" times in total; "&$two&" times appears twice continuously; "&$three&" times appears tripe continuously; "&$four&" times appears quartic continuously.") Nexttest.zip Edited February 12, 2011 by eastern314 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now