Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
fred@kuzel.ca
Beginner


Joined: 25 Nov 2003
Posts: 15
Location: United Kingdom

PostPosted: Sat Aug 14, 2004 9:53 pm   

Solution Found. Ignore this post.
 
Solution Found.
Reply with quote
Thandril
Adept


Joined: 03 Dec 2000
Posts: 260

PostPosted: 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
Reply with quote
Thandril
Adept


Joined: 03 Dec 2000
Posts: 260

PostPosted: 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.
Reply with quote
fred@kuzel.ca
Beginner


Joined: 25 Nov 2003
Posts: 15
Location: United Kingdom

PostPosted: 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]
_________________
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net