Username:
Password:
  Home About Us Articles Rules Script Library FAQ Help
Not logged in (register
Roman numbers for mIRC

Last Modified: Oct 13 2:20pm (r2)

Syntax: /romanize <string1> [string2] ... [stringN]
or $romanize(<string1>,[string2],...,[stringN]

The inputted string can be either roman number or regular. You can add as many numbers to convert as you want. For example:
/romanize II 142 MI
would echo "2 CXLII 1001"

Please note that there's a way the numbers have to go and as such "IM" isnt 999.

r1: Now supports numbers up to 938000! Note that that limit is only existant if you dont add any other numbers to convert.
r2; Prolly made it a bit faster. Changed some variables names to make it more clear. Oh, and I think the last version sucked ass but couldnt bother to test it, anyways it should be fixed now if there was anything to be fixed in the first place.
alias romanize {
  if ($1) {
    var %i = 1,%return,%thousands = 0,%num
    while ($gettok($1-,%i,32)) {
      if ($v1 isalpha) var %return = $rome2arab($v1)
      elseif ($v1 isnum) {
        %num = $v1
        if (%num > 999) {
          while (%num > 999) {
            dec %num 1000
            inc %thousands
          }
        }
        %return = %return $str(M,%thousands) $+ $arab2rome(%num)
      }
      inc %i
    }
  }
  if ($isid) return %return
  else echo -ag %return
}

alias -l reverse {
  var %length = $len($1),%return
  while (%length >= 1) { %return = %return $nums($mid($1,%length,1)) | dec %length }
  return %return
}
alias -l nums {
  var %roman = I V X L C D M
  var %arabic = 1 5 10 50 100 500 1000
  var %pos = $findtok(%roman,$1,1,32)
  return $gettok(%arabic,%pos,32)
}

alias rome2arab {
  var %reversed = $reverse($1),%j = 1,%big = 0,%return = 0
  while ($gettok(%reversed,%j,32)) {
    if ($v1 > %big) %big = $v1
    if ($v1 < %big) dec %return $v1
    else inc %return $v1
    inc %j
  }
  return %return
}

alias -l roman return $gettok(I V X L C D M,$1,32)
alias arab2rome {
  var %length = $len($1),%leap = 1,%return,%temp,%pos = 1
  while (%length > 0) {
    var %current.number = $mid($1,%length,1)
    var %first = $roman(%pos)
    var %second = $roman($calc(%pos + 1))
    var %third = $roman($calc(%pos + 2))
    inc %pos 2
    if (%current.number != 0) {
      if (%current.number isnum 1-3) %temp = $str(%first,$v1)
      if (%current.number == 4) %temp = %first $+ %second
      if (%current.number isnum 5-8) %temp = %second $+ $str(%first,$calc($v1 - 5))
      if (%current.number == 9) %temp = %first $+ %third
      %return = %temp $+ %return
    }
    inc %leap
    dec %length
  }
  return %return
}

Comments
arcane
Sep 06 2:59pm
Neat script! Seems to fall apart with numbers in the 3000+ range, but anyone using roman numerals for numbers that high should be punched anyway.
[Talon]
Sep 09 5:36pm
Roman Numerals >_< ... numbers... bah

Either way, cool beans.
Fradam
Sep 12 8:21am
romanize <-- romanise! ;)
 
All content Copyright © 2004 - 2008 UtoNet IRC Network
UtoNet is sponsored and hosted by Datinix Systems