Post Reply 
[SOLVED] DSRN (dog slow roman numerals)
06-11-2014, 08:23 PM
Post: #5
RE: DSRN (dog slow roman numerals)
Alright, this was as fast as I could get it. It runs in about half the time, but it's also about 140 bytes larger. Anything I tried involving local variables and subroutines actually ran slower. :/ I'm guessing it could be even faster if you get rid of the A subroutine and unroll it wherever it's used, but then the program will get even more bloated.

Code:
\<<
  \<< ROT ROT - ROT ROT + SWAP \>> \-> A
  \<< "" SWAP
    WHILE DUP 1000 \>= REPEAT 1000 "M" A EVAL END
    WHILE DUP 900 \>= REPEAT 900 "CM" A EVAL END
    WHILE DUP 500 \>= REPEAT 500 "D" A EVAL END
    WHILE DUP 400 \>= REPEAT 400 "CD" A EVAL END
    WHILE DUP 100 \>= REPEAT 100 "C" A EVAL END
    WHILE DUP 90 \>= REPEAT 90 "XC" A EVAL END
    WHILE DUP 50 \>= REPEAT 50 "L" A EVAL END
    WHILE DUP 40 \>= REPEAT 40 "XL" A EVAL END
    WHILE DUP 10 \>= REPEAT 10 "X" A EVAL END
    WHILE DUP 9 \>= REPEAT 9 "IX" A EVAL END
    WHILE DUP 5 \>= REPEAT 5 "V" A EVAL END
    WHILE DUP 4 \>= REPEAT 4 "IV" A EVAL END
    WHILE DUP 1 \>= REPEAT 1 "I" A EVAL END
    DROP
  \>>
\>>

I tried it with IF instead of WHILE for the multi-letter terms (since they can only be appended once), but it was slightly slower. I can't explain that. Maybe extra parsing overhead looking for an ELSE or something.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: DSRN (dog slow roman numerals) - HP67 - 06-11-2014, 07:06 PM
RE: DSRN (dog slow roman numerals) - Dave Britten - 06-11-2014 08:23 PM
RE: DSRN (dog slow roman numerals) - HP67 - 06-12-2014, 11:44 AM
RE: DSRN (dog slow roman numerals) - HP67 - 06-12-2014, 04:49 PM
RE: DSRN (dog slow roman numerals) - HP67 - 06-15-2014, 12:02 PM
RE: DSRN (dog slow roman numerals) - HP67 - 06-16-2014, 06:09 AM
RE: DSRN (dog slow roman numerals) - HP67 - 06-12-2014, 05:46 PM



User(s) browsing this thread: 1 Guest(s)