Jump to content

Barand

Moderators
  • Content Count

    21,784
  • Joined

  • Last visited

  • Days Won

    574

Barand last won the day on June 19

Barand had the most liked content!

Community Reputation

1,681 Excellent

About Barand

  • Rank
    Sen . ( ile || sei )

Profile Information

Recent Profile Visitors

66,890 profile views
  1. i x ii v -1 10 -2 5 = 12 x = according to my ancient calculator.
  2. A similar approach to mine function ad_litera ($n) { if ($n >3999) return 'NaN'; $n2r = [ 1000 => [ 1 => 'M', 2 => 'MM', 3 => 'MMM' ], 100 => [ 1 => 'C', 2 => 'CC', 3 => 'CCC', 4 => 'CD', 5 => 'D', 6 => 'DC', 7 => 'DCC', 8 => 'DCCC', 9 => 'CM' ], 10 => [ 1 => 'X', 2 => 'XX', 3 => 'XXX', 4 => 'XL', 5 => 'L', 6 => 'LX', 7 => 'LXX', 8 => 'LXXX', 9 => 'XC' ], 1 => [ 1 => 'I', 2 => 'II', 3 => 'III', 4 => 'IV', 5 => 'V', 6 => 'VI', 7 =>
  3. Attached is a gift for you so you can test all numbers from 1 - 3999 Sample contents... I II III IV V VI VII VIII IX X XI XII XIII XIV XV XVI XVII XVIII XIX XX . . MCMVC MCMXCVI MCMXCVII MCMXCVIII MCMIC MM MMI MMII MMIII MMIV MMV . . MMMCMXC MMMCMXCI MMMCMXCII MMMCMXCIII MMMCMXCIV MMMCMVC MMMCMXCVI MMMCMXCVII MMMCMXCVIII MMMCMIC roman_test.txt
  4. Because X is not less than the subsequent X, so only the I is subtractive
  5. Nothing there resembles what you had in your original post, which was
  6. Post the raw data that you get in $order before you start your processing and we'll see if we can help with your formatting
  7. The normal order is high to low and a number to that precedes a higher value is subtracted. The first "III" are therefore subtracted from the following V, giving 5 + 2 + 1 + 1 + 1 = 10
  8. As far as I know, it became "open source" as soon as I posted it here. But if a small toke of appreciation would ease your conscience if you use it ....
  9. This illustrates the way my algorithm works ... IXCM = 1000 - IXC = 1000 - ( 100 - IX ) = 1000 - ( 100 - ( 10 - 1 ) ) = 1000 - ( 100 - 9 ) = 1000 - 91 = 909
  10. If you want a recursive approach it is far more efficient to read all your data into a suitably structured array then process the array recursively.
  11. Your subtractive array is far from exhaustive. You have IX and VI so why not XI and IV. And II as in XIIX? This recursive solution implements the above approach giving XIIX 18 IXCX 101 XICX 99 MCMIL 1949 MCMXLIX 1949 MCMXXXXVIIII 1949 MDCCCCXXXXVIIII 1949 Code <?php // Test values $nums = ['XIIX', 'IXCX', 'XICX', 'MCMIL', 'MCMXLIX', 'MCMXXXXVIIII', 'MDCCCCXXXXVIIII' ]; echo '<pre><br>'; foreach ($nums as $rn) { printf( "\t%-20s %4d<br>", $rn, ad_decim
  12. Looks like solution is to look for substrings of lower value number prior to an even larger one IX C X |___| | -9 100 10
  13. PS However, I think IXCX should give 101 so I still have some work to do! IXCX = -9 + 100 + 10 = 101
  14. I wouldn't say XICX was any more invalid than XIIX. Unusual, yes, XICX = -10 - 1 + 100 + 10 = 99 The rule being any smaller number occuring before a larger number is subtracted.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.