I hope there is no one liner $regex's for these, or knowing my luck some of these are prolly built into mirc >.>
****: The numbers must be in numerical order from 0 - whatever. for now. i will add an auto arrange soon :P
;; If a given number is even, returns $true ;;
alias iseven {
if ($1 isnum) {
if (. !isin $calc($1 / 2)) {
return $true
}
else {
return $false
}
}
}
;; If a given number is odd, returns $true ;;
alias isodd {
if ($1 isnum) {
if (. !isin $calc($1 / 2)) {
return $true
}
else {
return $false
}
}
}
;; Returns the average of the values supplied ;;
alias avg {
if ($1) {
var %x = 1, %avg = 0
while (%x <= $0) {
if ($gettok($1-,%x,32) isnum) {
var %avg = $calc(%avg + $gettok($1-,%x,32))
inc %x 1
}
else {
echo -a 4Error: ($avg): $gettok($1-,%x,32) is not a number
halt
}
}
return $calc(%avg / $0)
}
}
;; returns the median (middle number when layed out in row **** ;;
alias median {
if ($1) {
if ($iseven($0)) {
var %res = $calc(($gettok($1-,$calc($0 / 2),32) + $gettok($1-,$calc(($0 / 2) + 1),32)) / 2)
}
else {
var %res = $gettok($1-,$calc(($0 / 2) + 0.5),32)
}
return %res
}
}
;; returns the mode of the numbers given (the one(s) that occur most often)
alias mde {
if ($1) {
write -c modetemp.dat
write -c modetempcalc.dat
var %x = 1
while (%x <= $0) {
if ($read(modetemp.dat, s, $gettok($1-,%x,32))) {
var %p = $read(modetemp.dat, s, $gettok($1-,%x,32))
write -ds $+ $gettok($1-,%x,32) modetemp.dat
write modetemp.dat $gettok($1-,%x,32) $calc(%p + 1)
}
else {
write modetemp.dat $gettok($1-,%x,32) 1
}
inc %x 1
}
var %x = 2, %xy1 = $gettok($read(modetemp.dat,1),1,32), %xy2 = $gettok($read(modetemp.dat,1),2,32)
while (%x <= $lines(modetemp.dat)) {
if ($gettok($read(modetemp.dat,%x),2,32) > %xy2) {
var %xy1 = $gettok($read(modetemp.dat,%x),1,32), %xy2 = $gettok($read(modetemp.dat,%x),2,32)
}
elseif ($gettok($read(modetemp.dat,%x),2,32) == %xy2) {
write modetempcalc.dat $gettok($read(modetemp.dat,%x),1,32) $gettok($read(modetemp.dat,%x),2,32)
}
inc %x 1
}
write modetempcalc.dat %xy1 %xy2
echo -a Mode: $gettok($read(modetempcalc.dat,$lines(modetempcalc.dat)),1,32) occured $gettok($read(modetempcalc.dat,$lines(modetempcalc.dat)),2,32) times
var %x = 1
while (%x <= $calc($lines(modetempcalc.dat) - 1)) {
echo -a Mode: $gettok($read(modetempcalc.dat,%x),1,32) occured $gettok($read(modetempcalc.dat,%x),2,32) times
inc %x
}
return Mode Calculation complete
.remove modetemp.dat
.remove modetempcalc.dat
}
}
Old script jonesy44, I know, but I would like to say something about the isodd and iseven functions.
I don't think checking to see if there is a decimal or not in the script, because 24.42, for example, is even but has a decimal point in it. Not to mention, both of the isodd and iseven functions are exactly the same.
Good identifiers though.