Updates:

Mata al pato \_O< en el canal #Traffic-Games

Números Romanos

Iniciado por TerraChat, Sep 26, 2023, 11:55 AM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

TerraChat

### channel set #TRAFFIC-CHAT +udef-flag-romen

setudef flag romen

bind pub -|- "!no" no_search
bind pub -|- "!romen" roman_search

proc no_search {nick uhost hand chan text} {
  if {![channel get $chan romen]} { return }
       set q [lindex [split [string toupper $text]] 0]
  if {[regexp {[0-9]+} $q] || [llength $q] eq "0"} {
       puthelp "privmsg $chan :\00304$::lastbind <Roman numerals>\003"
       return
       }
      puthelp "privmsg $chan :$nick ->\00313 $q \003== \00307[roman:get $q]\003"
      return 0
 }

proc roman_search {nick uhost hand chan text} {
  if {![channel get $chan romen]} { return }
       set q [lindex [split $text] 0]
  if {![regexp {[0-9]+} $q] || [llength $q] eq "0"} {
       puthelp "privmsg $chan :\00313$::lastbind <sayi>\003"
       return
       }
       puthelp "privmsg $chan :$nick ->\00313 $q \003== \00307[roman:number $q]\003"
       return 0
 }

# http://goo.gl/HCXci1

 proc roman:number {i} {
    set res ""
    foreach {value roman} {
        1000 M 900 CM 500 D 400 CD 100 C 90 XC 50 L 40 XL 10 X 9 IX 5 V 4 IV 1 I} {
        while {$i>=$value} {
            append res $roman
            incr i -$value
        }
    }
    set res
}

proc roman:get {s} {
       array set r_v {M 1000 D 500 C 100 L 50 X 10 V 5 I 1}
       set last 99999; set res 0
       foreach i [split [string toupper $s] ""] {
               if [catch {set val $r_v($i)}] {
                   putlog "hatali arama"
               }
               incr res $val
               if {$val>$last} {incr res [expr -2*$last]}
               set last $val
       }
       set res
}

putlog "=== Números Romanos ==="