Sign in to follow this  
Followers 0
NiM

finding dupes and how many of them in an array

3 posts in this topic

So I am making this whole crazy program for my teacher and I have an array of clubs and I need to know which club shows up the most and how many times they show up. I got something working, not to sure how it works just that it works, horribly.

So what I am asking is if there is an easier way/better way to do this.

#Include <Array.au3>
#Include <string.au3>

dim $aClubs[11] = ["fighting mongoose", "fatdood", "fighting mongoose", "team awsome", "teem bad", "fighting mongoose", "teem gamming", "teem bad", "fighting mongoose", "fighting mongoose", "teem bad"]


dim $club[UBound($aClubs)][2]
;~ $club[0][0] = $aClubs[0]
;~ _ArrayDelete($club, 0)
;~ _ArrayDisplay($club)
for $u = 0 to UBound($aClubs)-1;i have no idea whats going on here
    for $y = 0 to UBound($aClubs)-1
        if $aClubs[$u] = $aClubs[$y] Then
            if $club[$y][0] = "" then $club[$y][0] = $aClubs[$u]
            $club[$y][1] += 1
;~          _ArrayDisplay($club, "added 1")
        EndIf
    Next
Next

;~ _ArrayDisplay($club, "b4sort")
_ArraySort($club)
;~ _ArrayDisplay($club, "baftersort")

dim $last, $todelete
for $i = 0 to UBound($club)-1
    if $club[$i][0] = $last then 
        $todelete &= $i&","
    EndIf
    $last = $club[$i][0]
Next

;~ MsgBox(0, "", $todelete)
$todelete = StringTrimRight($todelete, 1)
$todelete = _StringReverse($todelete)

;~ MsgBox(0, "", $todelete)

$str = StringSplit($todelete, ",")

;~ _ArrayDisplay($str)

for $i = 1 to $str[0]
    _ArrayDelete($club, $str[$i])
Next

_ArrayDisplay($club, "DONE")
;then just go through like everything else and do ties but this is all i need right now

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#Include <Array.au3>

dim $aClubs[11] = ["fighting mongoose", "fatdood", "fighting mongoose", "team awsome", "teem bad", "fighting mongoose", "teem gamming", "teem bad", "fighting mongoose", "fighting mongoose", "teem bad"]
dim $aResult[1][2]

_ArraySort($aClubs)

;check element to next element, up to second last element against last element
for $i = 0 to UBound($aClubs) - 2
    if $aClubs[$i] <> $aClubs[$i+1] then
        if $aResult[UBound($aResult)-1][0] <> "" then ReDim $aResult[UBound($aResult)+1][2]
        $aResult[UBound($aResult)-1][0] = $aClubs[$i]
        $aResult[UBound($aResult)-1][1] = 0
    endif
Next

;check last element of $aClub against second last element
if $aClubs[UBound($aClubs)-2] <> $aClubs[UBound($aClubs)-1] then
    if $aResult[UBound($aResult)-1][0] <> "" then ReDim $aResult[UBound($aResult)+1][2]
    $aResult[UBound($aResult)-1][0] = $aClubs[UBound($aClubs)-1]
    $aResult[UBound($aResult)-1][1] = 0
endif

_ArrayDisplay($aResult)

for $i = 0 to UBound($aClubs) - 1
    for $y = 0 to UBound($aResult) - 1
        if $aResult[$y][0] = $aClubs[$i] Then
            $aResult[$y][1] += 1
        endif
    Next
Next

_ArrayDisplay($aResult)

Edited by KaFu

Share this post


Link to post
Share on other sites

Awesome! thank you so much KaFu!

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