I am reading numbers off a database and create a 4 digits patterns such as:
1, 2, 2, 1
0, 2, 2, 2
4, 0, 2, 0
1, 2, 2, 1
2, 1, 1, 2
Each digit can only be from 0-6. The second step is where my problem is. I need to tally each pattern. For example, pattern 1,2,2,1 has a tally of 2 because it appears twice and the other patterns appear only once each.
At the end output, I need to be able to display each unique pattern with the count such as:
1, 2, 2, 1 - 2
0, 2, 2, 2 - 1
4, 0, 2, 0 - 1
2, 1, 1, 2 - 1
I was thinking of using a 2-dimensional array. Where
combinations[1][1]="1, 2, 2, 1" (the pattern)
combinations[1][2]=2 (the count)
combinations[2][1]="0, 2, 2, 2"
combinations[2][2]=1
etc.
How can I actually create the array dynamically while matching the pattern? i.e. if the pattern is not yet found add to the array. If it is found, add to the count. I have tried this:
<cfloop index="i" from="1" to="#ArrayLen(combinations)#">
<cfif not arrayFind(combinations[i][1],"#patterns#")>
<cfset arrayAppend(combinations,["#patterns#",1]) >
<cfelse>
<cfset combinations[i][2] = combinations[i][2] + 1>
</cfif>
</cfloop>
But I am getting the error on the ArrayFind:
Object of type class java.lang.String cannot be used as an array
Any help is appreciated. Thank you in advance.