This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Nice. This was the kind of solution I was expecting. Hope it was not too tedious.
I fixed your solution to reflect syntax coloring
This is C#:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
Convert numbers in subtractive notation to those not in subtractive notation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Mind sharing your code with us?
Log in to reply
Code? Here's what I did. First, I took your raw text and dumped it into Microsoft Word. Then I replaced all the {M,D,C,L,X,V,I} with {1000,500,100,50,10,5,1}, plus putting in commas and brackets in all the right places, using the "Replace" feature. Then I put this into Mathematica which accepts it as a regular array. Then whenever there is a pair of numbers such that the first is less than the other, the other is reduced by the first, while the first is made 0. Then flatten all, and then total all.
What code? It was almost done by hand. Being that this is supposed to be "computer science", I suppose I cheated.
Log in to reply
That's cool. How did you manage the occurences of IX, IV, etc?
Log in to reply
@Agnishom Chattopadhyay – The arrays, once prepared for Mathematica, shows numbers in descending order, except for those subtractive notation occurrences. I used a simple program to go look for those pairs of numbers not in descending order and make simple arithmetic adjustments. For example, if CM, then that means (-100+1000). I could have just made the 100 into a negative -100 with the same results, but I was too much of a hurry to be that clever, and instead changed the pair into (0, 900). Probably out of superstitious need to stay with the familiar?
Problem Loading...
Note Loading...
Set Loading...
Python: