Top

$avg

+ 0 likes
Please Register to submit score.
Average Score  4.0
Scores Submitted  1
Date Added  Dec 12, 2007
Last Updated  Dec 13, 2007
Tags  average  avg  number  numbers 

Introduction

This is an identifier than finds the average of a set of numbers.

Syntax: $avg(N.N.N.N,C)

N = numbers
. = delimeter
C = delimeter #


Ex:

$avg(1 5 2 1 6,32) » 3
$avg(2|4|6|8,124) » 5
$avg(1.1.1.1,46) » 1


Enjoy :P

Grab the Code

Comments

  (7)  RSS
mountaindew
Comments: 1,513
 
mIRC Snippet:  $avg
Posted on Dec 12, 2007 8:15 pm
Enjoy :P
Noutrious
Comments: 343
 
mIRC Snippet:  $avg
Posted on Dec 13, 2007 3:00 pm
Code:
alias avg $iif($isid,return,echo -a) $calc(($replace($gettok($1,1-,$2),$chr($2),+)) / $numtok($gettok($1,1-,$2),$2))

Guess this is a bit better. ;)
mountaindew
Comments: 1,513
 
mIRC Snippet:  $avg
Posted on Dec 13, 2007 4:52 pm
this is meant to be an identifier, i cant see people doing /avg 1.2.3.4 46 :P
Rebellious
Comments: 64
 
mIRC Snippet:  $avg
Posted on Dec 13, 2007 4:55 pm
Noutrious, the problem with your code is the $1 and the $2, it would consider your a second number to be $2 and it would consider that the token separator. Also, it would only consider $1. Here is an updated code:
Code:
 alias avg {
  var %c = $iif($isid,$2,32), %1 = $iif($isid,$1,$1-)
  $iif($isid,return,echo -a) $calc(($replace($gettok(%1,1-,%c),$chr(%c),+)) / $numtok($gettok(%1,1-,%c),%c))
}

Supports as an identifier and an alias. :)
Rebellious
Comments: 64
 
mIRC Snippet:  $avg
Posted on Dec 13, 2007 4:58 pm
Quote:
Noutrious, the problem with your code is the $1 and the $2, it would consider your a second number to be $2 and it would consider that the token separator.


Vague and confusing. ;P

Basically: if I had the string /avg 1 2 3 It would only average 1 separated by $chr(2).

Quote:
Also, it would only consider $1.
* $1 as the entire string. :)

Sorry for the double post.
Rebellious
Comments: 64
 
mIRC Snippet:  $avg
Posted on Dec 13, 2007 5:01 pm
Quote:
this is meant to be an identifier, i cant see people doing /avg 1.2.3.4 46 :P
Sometimes I\'d just like to see an average of a string myself without using the entire $calc syntax; so something like /avg would be much easier to get data in that sense.
Lindrian
Comments: 726
 
mIRC Snippet:  $avg
Posted on Dec 15, 2007 4:00 pm
I would of done something more like this
Code:

alias avg {
  if ($isid) {
    tokenize $iif($2,$2,32) $1
    var %g = $calc(($replacecs($1-,$chr(32),+)) / $numtok($1-,32))
  }
  return $iif($isid,$iif($prop,$round(%g,0),%g),* $avg: invalid parameters)
}


The code being very small aint anything id care about.
Id rather have proper usage of identifiers...

eg:

$avg(1 2 3 4 5)
$avg(1 2 3 4 5,32)
$avg(1.2.3.4.5,46)
$avg(1 2 3 4,32).n
the $prop will round the value.

My version will depend on you using the correct syntax, since tokenize will return a value even if you didnt specefiy the correct delimiter.

Generally: $avg(string,N)

Please Register or Login to start posting comments.
Bottom