in reply to Re^2: Risque Romantic Rosetta Roman Race
in thread Risque Romantic Rosetta Roman Race

Would it be faster as

@rtoa{ split//, uc } # save uc from having to process an argument by +letting it just default to $_

Replies are listed 'Best First'.
Re^4: Risque Romantic Rosetta Roman Race
by hippo (Archbishop) on May 10, 2023 at 10:05 UTC

    Faster still to avoid the uc entirely? Just double the hash:

    state %rtoa = ( M=>1000, D=>500, C=>100, L=>50, X=>10, V=>5, I=>1, m=>1000, d=>500, c=>100, l=>50, x=>10, v=>5, i=>1, );

    A quick test shows it's not significantly different - just feels better. :-)


    🦛

Re^4: Risque Romantic Rosetta Roman Race
by eyepopslikeamosquito (Archbishop) on May 10, 2023 at 10:07 UTC

    Ha ha, I'd already tried that and couldn't measure any difference. I'd also tried losing the uc function by increasing the hash to include lower case letters, but that was a bit slower. Update: hippo suggested that while I was typing. :)

    The most promising approach may be to find an alternative to:

    M=>1000, D=>500, C=>100, L=>50, X=>10, V=>5, I=>1
    to do the mapping. For example, 'M1000D500C100L50X10V5I1' and use a regex or something. I made a few half-hearted attempts but didn't find anything faster.

    It might also be faster to remove the reduce and do the summing in another uglier way ... but reduce is so elegant I couldn't bring myself to try anything along those lines, that would be like losing an old friend. :)