Register to reply 
C++ converting base 10 to Roman numerals 
Share this thread: 
#37
Feb405, 04:20 PM

P: 613

MMDCDXLVIV is correct for 2949.
Point is, my algorithm is inherently simpler than yours. 


#38
Feb405, 04:23 PM

P: 1,046

2949=MMCMXLIX



#39
Feb405, 04:24 PM

Emeritus
Sci Advisor
PF Gold
P: 4,922




#40
Feb405, 04:26 PM

P: 1,046




#41
Feb405, 04:27 PM

P: 613

According to that page on roman numerals, IX is incorrect... you can't have a I and then an X, it skips the V, the same reason IMM is incorrect.



#42
Feb405, 04:29 PM

P: 1,046




#43
Feb405, 04:32 PM

Emeritus
Sci Advisor
PF Gold
P: 4,922

If it's any consolation I think I failed spectacularly on the C++ midterm today. Guess what was on the test  converting to Roman f'ing numerals! I couldn't remember anything. I was like a deer in the headlights I was so scared. 


#44
Feb405, 04:33 PM

P: 1,046

I didn't study that page, but I'm sure that 9 is generally written IX and not VIV.



#45
Feb405, 04:37 PM

P: 1,046

On the other hand, it's a lot more fun than studying for an exam on computabilty, complexity, etc.  which is what I should be doing.
I'll check back later to see what Bartholomew comes up with. 


#46
Feb405, 05:03 PM

Emeritus
Sci Advisor
PF Gold
P: 16,091

My algorithm is the best. Given an integer, look up its string representation in a table of strings.



#47
Feb405, 05:04 PM

P: 613

Well, as I said, I don't have a c++ compiler. So rather than translate this into C++ and hope I didn't make any syntax errors in doing so, I'll just post it in Java, which I wrote it in. (No user input here since that takes several lines in Java)



#48
Feb405, 08:21 PM

HW Helper
P: 430

In Python (this moreorless does what I outlined earlier (rather inefficiently ); I think it's also a version of Hurkyl's method):



#49
Feb405, 08:26 PM

P: 1,046

You (Bartholomew) have disappointed me.
It's a few characters shorter than mine (ignoring the user chitchat), but it's still wrong. Yes, your algorithm is simpler, but only because the language that it recognizes is simpler and as a result it fails to handle 9, 90 and 900 correctly. Why did you think that 9 = VIV and 90 is LCL? The Wolfram page that MathIsHard posted http://mathworld.wolfram.com/RomanNumerals.html clearly indicates that 9=IX and and 90=XC. If you look at page "9" (romannumbered) of the preface of any textbook, or the production date of any 20th century movie you'll see ix and MCM.... 


#50
Feb405, 08:41 PM

P: 613

If you don't have a Java SDE, here's a _tentative_ translation into C++. Probably this doesn't work, but hopefully you'll be able to correct the error if that's the case. (it won't be a logic error, it does work in Java) I also refined the code slightly while translating, to shave off an additional few characters and further complicate that beautiful cout of mine .



#51
Feb405, 08:45 PM

P: 613

Oh, I didn't see you had postedtook me a while to do that translation. 1 moment.
Edit: Okay, you raise a valid point. I will think about how best to modify my method to do 9's, 90s, and 900s correctly. It will still be very short though. 


#52
Feb405, 09:53 PM

P: n/a

Alright, lemme have a shot at this:
PS: Don't be hatin' on the printf!!! 


#53
Feb405, 10:02 PM

P: 1,046

Interesting, but not correct:
Please enter the number that must be converted: 1999 Here is your number in Roman numerals: MDCCCCLXXXXVIV 3 errors: DCCCC for 900, LXXXX for 90, VIV for 9 Edit: What's the "multithreaded" comment about? 


#54
Feb405, 10:05 PM

P: n/a

Ah crap, didn't notice that. Awesome beta testing on your part.
I meant, if your compiler supports it (I think all compilers nowadays do), like gcc 3.4.x, compile it for Multithreaded mode (to support Intel HyperThreading!) and notice the performance difference. I believe the code is significantly faster if it runs multithreaded. Btw, I found this rather succint piece of code (I'm quite sure it works) here . I feel a JScript to C/C++ conversion is in order. 


Register to reply 
Related Discussions  
Need program for roman numerals  Engineering, Comp Sci, & Technology Homework  2  
Roman Emperors and Empire  History & Humanities  28  
Probability of Repeated Identical Numerals  Set Theory, Logic, Probability, Statistics  15  
Can converting Roman soldiers compete with Grand Theft Auto  Social Sciences  0  
Roman numerals  General Math  1 