Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Golf: Magic Formula for Roman Numerals

by ambrus (Abbot)
on Feb 18, 2007 at 11:21 UTC ( #600677=note: print w/replies, xml ) Need Help??


in reply to Golf: Magic Formula for Roman Numerals

sub m1{1+4*y/VLD//.E.ord()x3%75%50%4}
can be improved to
sub m3{5**y/VLD//.E.ord()x3%75%50%4}

This is much longer than yours, but I thought I'd still mention it:

sub b0{(1e3,10,5,1,100,500,50)[ord()%87%7]}

Update: a new one that's only one character too long

sub b1{M1E3D500C100L50X10V5I1=~$_;$'}

Replies are listed 'Best First'.
Re^2: Golf: Magic Formula for Roman Numerals
by eyepopslikeamosquito (Bishop) on Feb 18, 2007 at 12:29 UTC

    Update: a new one that's only one character too long
    sub b1{M1E3D500C100L50X10V5I1=~$_;$'}
    Not any more. ;-)
    sub b2{M999D499C99L49X9V4I=~$_+$'}

    Update: As described in The 10**21 Problem (Part I) this one is four strokes shorter:

    sub b3{XCMVLD=~$_;"1E@+"%9995}

      Oh yes, using the return value of matches is a trick that could have helped me in the Fonalty golf as well, as I've realized when reading other's solutions.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://600677]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2021-05-10 07:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (104 votes). Check out past polls.

    Notices?