wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 07-11-2008, 02:56 AM   #1
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default I2Roman

Perhaps for some reason you want to use roman numbers for some stuff? I don't know. The code is ugly if anyone can improve it, go ahead.

Collapse JASS:
function I2Roman takes integer n returns string
 local string r=""
    if n>3999 or n < 1 then
        return I2S(n)
    endif
    loop
        exitwhen n<1000
        set r=r+"M"
        set n=n-1000
    endloop
    loop
        exitwhen n < 900
        set r=r+"CM"
        set n=n-900
    endloop
    loop
        exitwhen n<500
        set r=r+"D"
        set n=n-500
    endloop
    loop
        exitwhen n < 400
        set r=r+"CD"
        set n=n-400
    endloop
    loop
        exitwhen n<100
        set r=r+"C"
        set n=n-100
    endloop
    loop
        exitwhen n < 90
        set r=r+"XC"
        set n=n-90
    endloop
    loop
        exitwhen n<50
        set r=r+"L"
        set n=n-50
    endloop
    loop
        exitwhen n < 40
        set r=r+"XL"
        set n=n-40
    endloop
    loop
        exitwhen n<10
        set r=r+"X"
        set n=n-10
    endloop
    loop
        exitwhen n < 9
        set r=r+"IX"
        set n=n-9
    endloop
    loop
        exitwhen n<5
        set r=r+"V"
        set n=n-5
    endloop
    loop
        exitwhen n < 4
        set r=r+"IV"
        set n=n-4
    endloop
    loop
        exitwhen n<1
        set r=r+"I"
        set n=n-1
    endloop
 return r
endfunction
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 07-11-2008, 03:34 AM   #2
Gorman
.▲▼▲&#9
 
Gorman's Avatar
 
Join Date: Apr 2007
Posts: 1,087

Submissions (2)

Gorman will become famous soon enough (70)Gorman will become famous soon enough (70)Gorman will become famous soon enough (70)

Send a message via MSN to Gorman
Default

ha, thats pretty cool.

I might make one of them just coz its so cool.

Smooth work man!
__________________
Gorman is offline   Reply With Quote
Old 07-11-2008, 07:53 AM   #3
Strilanc
User
 
Strilanc's Avatar
 
Join Date: Jun 2007
Posts: 917

Submissions (4)

Strilanc has a spectacular aura about (131)

2008 Spell olympics - Fire - Gold

Default

This isn't quite perfect, but it's close. I have no idea why roman numerals are still used; ever. It's a horrible representation for numbers. It would be half decent if they didn't have the crazy 'reverse for subtract' rule.

Collapse JASS:
globals
  string chars = "IVXLCDM"
  integer array periods = {5,2,5,2,5,2,5} //obviously initialize elsewhere
  constant integer numChars = 7
  integer array nums //workspace
endglobals
function I2Roman takes integer n returns string
  local string prefix = ""
  local string suffix = ""
  local string char
  local integer i = 0
  loop
    exitwhen i >= numChars
    //measure character count
    set char = SubString(chars,i,i+1)
    set nums[i] = nums[i] + ModuloInteger(n, periods[i])
    set n = n / periods[i]
    //output character
    if nums[i] == periods[i]-1 and nums[i] > 1 then
      //needs to be subtracted, so go in prefix
      set nums[i+1] = 1
      set prefix = prefix + char
    else
      //needs to be added, so go in suffix
      if nums[i] == periods[i] then
        //carry from a subtraction, pass the carry
        set nums[i] = 0
        set nums[i+1] = 1
      endif
      //add to suffix
      loop
        exitwhen nums[i] <= 0
        set suffix = char + suffix
        set nums[i] = nums[i] - 1
      endloop
    endif
    set i = i + 1
  endloop
  return prefix + suffix
endfunction
__________________
Don't pay attention to this signature, it's self-contradictory.

Last edited by Strilanc : 07-11-2008 at 08:05 AM.
Strilanc is offline   Reply With Quote
Old 07-12-2008, 06:40 PM   #4
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

Whatever, this does what it says it does. Approved.
__________________
Rising_Dusk is offline   Reply With Quote
Old 07-12-2008, 08:10 PM   #5
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

Strilanc. I am quite sure your version is much slower than mine. Try benchmarks. Sure it is shorter , but ...

I guess it is possible to save a lot using a textmacro. I didn't want to add a vJass lock-in to this.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 12:01 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services