mIRC Home    About    Download    Register    News    Help

Print Thread
#167071 19/12/06 03:36 PM
M
MisterMage
MisterMage
M
1. Is there a way to tell the bigger of numbers? Like is there a $command() for it?

2. I wanted to make a 'Most Used Word' script. How would i start it?

#167072 19/12/06 03:55 PM
Joined: Oct 2003
Posts: 284
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 284
You can use $iif(%num1 > %num2,%num1,%num2) for two numbers.

For more, you can use a tokenised list:
Code:
var %list = 10 25 18 7 256 11 9 | echo -a $gettok($sorttok(%list,32,nr),1,32)


The advantage here is that you can get the N largest entries by specifying 1-N for the $gettok index value

One way of saving the number of occurrences of items is with a hash table:
Code:
var %sentence the cat sat on the mat and on the mat it sat 
var %n = $numtok(%sentence,32)
var %list
while (%n) {
  var %word = $gettok(%sentence,%n,32)
  hinc -m wordlist %word
  dec %n 
}


However using this with the above method for getting the max value would require a separate loop. Instead you could store the max value and compare it on each addition:

Code:
  ...
  hinc -m wordlist %word
  set %wordlist.max $+(%word,:,$hget(wordlist,%word))
  ...



Sais #167078 19/12/06 04:33 PM
Joined: Oct 2004
Posts: 8,061
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Oct 2004
Posts: 8,061
You can very easily sort a hash table by using hsave and filter.

Code:
alias top10 {
  hsave -n hashtable tempfile.txt
  filter -ffcteun 1 32 tempfile.txt tempfile.txt
  var %i = 1 | while (%i <= 10) {
    var %itemname = $hget(hashtable,$gettok($read(tempfile.txt,nt,%i),1,32)).item
    echo -a Top 10 $+(#,%i,) %itemname with a score of $hget(hashtable,%itemname)
    inc %i
  }
}


This is from one of DaveC's posts a long time ago. It works very well for quickly sorting a hash table.


Link Copied to Clipboard