mIRC Home    About    Download    Register    News    Help

Print Thread
#69268 25/01/04 03:21 PM
Joined: Feb 2003
Posts: 3,412
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,412
How would i in the simplest way calc the % of caps in a sentense ? like if $isupper($1-) is 100% .. but lest say i want to trigger somthing if $isupper = 50% ?

#69269 25/01/04 03:34 PM
Joined: Jan 2003
Posts: 2,973
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Jan 2003
Posts: 2,973
Code:
alias caps {
  var %l = 1, %c = 0
  while ($mid($1, %l, 1) != $null) {
    var %le = $ifmatch
    if ($asc($ifmatch) isnum 65-90) /inc %c
    /inc %l 
  }
  return $round($calc((%c / $len($1-)) * 100), 2)
}


That will return thepercentage of caps. i.e.

$caps(TEst) = 50.0
$caps(Test) = 25.0
$caps(HEllo) 40.0

#69270 25/01/04 03:39 PM
Joined: Feb 2003
Posts: 3,412
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,412
Where can i use a trigger in that code? and where can i see the % ? like in a echo ?

#69271 25/01/04 03:42 PM
Joined: Jan 2003
Posts: 2,973
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Jan 2003
Posts: 2,973
if ($caps(HEllo) == 40) { /echo HEllo is 40% caps! }

#69272 25/01/04 03:47 PM
Joined: Feb 2003
Posts: 3,412
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,412
nope, i cant get it to work anyway

No one that know a SIMPLE way? it must be a bether way to calc it? and maybe a way that work.. i cant get KT's code to work.. ether it dont reply anything.. or it reply to everything that is typed in the channel..

Last edited by sparta; 25/01/04 04:04 PM.
#69273 25/01/04 04:35 PM
Joined: Dec 2002
Posts: 1,893
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,893

#69274 25/01/04 05:17 PM
Joined: Nov 2003
Posts: 2,321
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,321
alias countcaps { return $regex($1-,/[A-Z]/g) }
alias percent { return $calc(($2 / $1) * 100) $+ % }
alias caps { return $percent($countcaps($1-),$len($1-)) }

echo -a $caps(ABcdEFgh)

Joined: Apr 2003
Posts: 413
A
Fjord artisan
Offline
Fjord artisan
A
Joined: Apr 2003
Posts: 413
I do benchmark of the function(from Proph),function(from KingTomato) and a function(from PnP script).
32 words(Latest News Download mIRC How to Install Translations Message Board Intro to IRC IRC FAQ Intro to mIRC mIRC FAQ Command List How to Register Mailing Lists IRC Networks Chat Links More Info)..
I call the each function 1000 times.. For proces the 32 words..
I call my benchmark 3 times for each function and take the best resulats.

Code:
;The blue part must be changed for test each function
Alias RegBenchMarkCaps {
  var %i = 1
  var %Start = $ticks
  while (%i <= 1000) {
    [color:blue]capsStandart[/color] Home Latest News Download mIRC How to Install Translations Message Board Intro to IRC IRC FAQ Intro to mIRC mIRC FAQ Command List How to Register Mailing Lists IRC Networks Chat Links More Info
    inc %i
  }
  echo -s 1000 times in $calc(($ticks - %Start) / 1000) sec.
}

;Solution from Proph
alias capsReg return $calc($regex($1,/[A-Z]/g)/$len($1)*100)

;Solution from KingTomato
alias CapsStandart {
  var %l = 1, %c = 0
  while ($mid($1, %l, 1) != $null) {
    var %le = $ifmatch
    if ($asc($ifmatch) isnum 65-90) inc %c
    inc %l 
  }
  return $calc((%c / $len($1-)) * 100)
}

;A Caps check solution from the great PnP script
Alias CapsPnP {
  var %letter = $calc($len($1-) - $len($removecs($1-,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z)))
  return $calc((%letter / $len($1-)) * 100)
}


Now the resultats wink
Result of CapsStandart: 3.319 sec.
Result of CapsReg: 0.983 sec.
Result of CapsPnP: 3.486 sec.
Yap.. Regular Expression rulZ wink
All tests was on a comp(333mHZ,Win98SE).
Anyone know where can i read about the history of the Regular Expression(ex. the year when the first version was realised) ?

Joined: Feb 2003
Posts: 3,412
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,412
and that should help me with ?

Joined: Jan 2003
Posts: 2,973
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Jan 2003
Posts: 2,973
your test wasn't actually accurate. The aliases were meant to be run as $identifiers, not as a /command. So that affected mine in that I refered tot he text being passed as $1, because $caps(blah blah blah) would be the $1 value. Anyways, here is a more accurate test:

Code:
alias RegBenchMarkCaps {
  /echo -s -
  /echo -s Benchmark Of 3 Case-Sensative Searches

  var %count = 100
  var %str = Home Latest News Download mIRC How to Install $&
    Translations Message Board Intro to IRC IRC FAQ Intro to $&
    mIRC mIRC FAQ Command List How to Register Mailing Lists $&
    IRC Networks Chat Links More Info

  ; Standard
  /echo -s Standard...
  var %s = $ticks, %a = 0
  while (%a < 1000) {
    .echo -q $caps_standard(%str)
    /inc %a
  }
  /echo -s Completed in $calc(($ticks - %s) / 1000) secs
  var %least = $calc($ticks - %s), %name = Standard

  ; PnP
  /echo -s PnP...
  var %s = $ticks, %a = 0
  while (%a < 1000) {
    .echo -q $caps_pnp(%str)
    /inc %a
  }
  /echo -s Completed in $calc(($ticks - %s) / 1000) secs
  if ($calc($ticks - %s) < %least) var %least = $calc($ticks - %s), %name = PnP

  ; Regex
  /echo -s RegEx...
  var %s = $ticks, %a = 0
  while (%a < 1000) {
    .echo -q $caps_regex(%str)
    /inc %a
  }
  /echo -s Completed in $calc(($ticks - %s) / 1000) secs
  if ($calc($ticks - %s) < %least) var %least = $calc($ticks - %s), %name = RegEx

  /echo -s Outcome: (In %count iterations) %name Won with a time of $calc(%least / 1000) secs
}

; mine
alias caps_standard {
  var %l = 1, %c = 0
  while ($mid($1, %l, 1) != $null) {
    if ($asc($ifmatch) isnum 65-90) /inc %c
    /inc %l 
  }
  return $round($calc((%c / $len($1-)) * 100), 2)
}

;Solution from Prophalias
alias caps_regex {
  return $calc($regex($1,/[A-Z]/g)/$len($1)*100)
}

;A Caps check solution from the great PnP script
alias caps_pnp {
  var %letter = $calc($len($1-) - $len($removecs($1,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z)))
  return $calc((%letter / $len($1-)) * 100)
}

-
Benchmark Of 3 Case-Sensative Searches
Standard...
Completed in 10.656 secs
PnP...
Completed in 0.672 secs
RegEx...
Completed in 0.343 secs
Outcome: (In 100 iterations) RegEx Won with a time of 0.343 secs

D
DaveC
DaveC
D
Your to truthfull for your own good <grin>

totally different subject,

I notice your putting /inc in every where, and i was wondering if there is some anomally/reson in mirc that makes using /inc better than inc ? Or if it was just personal choice.

Joined: Jan 2003
Posts: 2,973
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Jan 2003
Posts: 2,973
I tend to put /'s before all commands no matter where they are executed. I submitted a script to mirc.net and actually was critqued on this, and marked down. Personally, I don't see the harm, and acts more as clearification to me than anything. I do it because at a quick glance, I can take notice to what is and isn't a command. It is trivial to include it, and on that note--why not? I mean no harm, no foul.

As far as truthful, are you frerring to putting my own script to shame? I didn't have any stock investments in it, so I really don't care. I just wanted to see the actual outcome (with a proven method) and got one. Kind of interesting how a $remove even does better than a loop.>:D


Link Copied to Clipboard