|
fred@kuzel.ca Beginner
Joined: 25 Nov 2003 Posts: 15 Location: United Kingdom
|
|
|
|
Thandril Adept
Joined: 03 Dec 2000 Posts: 260
|
Posted: Sat Aug 14, 2004 10:40 pm |
Funny you should bring this up... I will be posting about a similar issue. Try this out:
Code: |
#var mylist "54|50|60|54|61|54"
#var singlist %dups( @mylist)
#var highcount 0
#FORALL @singlist {
#VAR count 0
#VAR check {%i}
#FORALL @mylist {
#IF (%j = @check) {
#ADD count 1
#VAR itemlist %delitem( @check, @itemlist)
}
}
#IF (@count > @highcount) {
@highcount = @count
@highest = @check
}
}
#SAY "You say: " @highest
|
|
|
|
|
Thandril Adept
Joined: 03 Dec 2000 Posts: 260
|
Posted: Sat Aug 14, 2004 10:42 pm |
Now people will wonder why I posted that. Best not to edit posts and remove their content. The original question was how to find the value in a list with the most occurences.
|
|
|
|
fred@kuzel.ca Beginner
Joined: 25 Nov 2003 Posts: 15 Location: United Kingdom
|
Posted: Sat Aug 14, 2004 11:23 pm oops |
Sorry, I deleted my old post before I read your answer.
I found a very handy function called countlist that essentially makes a key-value pair like this:
54 5
45 1
60 2
etc etc
I then make a dummy entry with a count of 0 and loop the count list above and replace this value every time a higher one is found.
Thanks for the post though, take alook at %countlist(), its pretty handy now that I know its there.
Code: |
#VARIABLE myList "54|45|60|80|54|12|22|23|60|54|54|46|54"
#VARIABLE myListCount %countlist( @myList)
MostRepeated.1 = "NoKeyFound"
MostRepeated.2 = 0
#LOOPDB @myListCount {
#IF (@MostRepeated.2 < %val) {
MostRepeated.1=%key
MostRepeated.2=%val
}
}
#SAY Most Repeated Key: @MostRepeated.1, Repeats: @MostRepeated.2
|
[/code] |
|
_________________ |
|
|
|
|
|