Coding Challenge Of The Day
-
Write a function to convert Roman numerals to Arabic numbers. The smaller the better. Bonus points, as always, for obscure languages and obfuscated assembler.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
-
Write a function to convert Roman numerals to Arabic numbers. The smaller the better. Bonus points, as always, for obscure languages and obfuscated assembler.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
Hmm. Too bad my first boss is now retired. One of his claims to fame was adding code to a FORTRAN compiler to support Roman numeral output in the
FORMAT
statement.Software Zen:
delete this;
-
Write a function to convert Roman numerals to Arabic numbers. The smaller the better. Bonus points, as always, for obscure languages and obfuscated assembler.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
-
Write a function to convert Roman numerals to Arabic numbers. The smaller the better. Bonus points, as always, for obscure languages and obfuscated assembler.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
Go out and hire some Brogrammers. They whip this stuff up while chuggin' brews. :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
-
Write a function to convert Roman numerals to Arabic numbers. The smaller the better. Bonus points, as always, for obscure languages and obfuscated assembler.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
Sub Roman_Numeral()
Range("A1").Value = "2012"
Range("B1").FormulaR1C1 = "=ROMAN(RC[-1],0)"
End Sub[Edit] I know, I know... Wrong way... I was chuggin beers:sigh:
It was broke, so I fixed it.
-
Sub Roman_Numeral()
Range("A1").Value = "2012"
Range("B1").FormulaR1C1 = "=ROMAN(RC[-1],0)"
End Sub[Edit] I know, I know... Wrong way... I was chuggin beers:sigh:
It was broke, so I fixed it.
You get points for at least writing code. As opposed to some members... (dark looks all 'round).
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
-
Write a function to convert Roman numerals to Arabic numbers. The smaller the better. Bonus points, as always, for obscure languages and obfuscated assembler.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
for well-formed roman numerals, modern rules:
int r2d2(const char *r)
{
int val[128];
memset(val,0,sizeof(int)*128);
val['I']=1; val['V']=5;
val['X']=10; val['L']=50;
val['C']=100; val['D']=500; val['M']=1000;int a = 0;
for (int cv, pv = 0, i=strlen(r)-1;i>=0;i--)
{
cv = val[r[i]];
a += cv * (pv > cv ? -1 : 1);
pv = cv;
}return a;
}
-
Write a function to convert Roman numerals to Arabic numbers. The smaller the better. Bonus points, as always, for obscure languages and obfuscated assembler.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
-
for well-formed roman numerals, modern rules:
int r2d2(const char *r)
{
int val[128];
memset(val,0,sizeof(int)*128);
val['I']=1; val['V']=5;
val['X']=10; val['L']=50;
val['C']=100; val['D']=500; val['M']=1000;int a = 0;
for (int cv, pv = 0, i=strlen(r)-1;i>=0;i--)
{
cv = val[r[i]];
a += cv * (pv > cv ? -1 : 1);
pv = cv;
}return a;
}
I once met a well formed roman, when I was touring through Italy. :cool:
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
-
Write a function to convert Roman numerals to Arabic numbers. The smaller the better. Bonus points, as always, for obscure languages and obfuscated assembler.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
In URL form: http://en.wikipedia.org/wiki/Roman_numerals#External_links[^] :-D Another interesting fact: http://answers.yahoo.com/question/index?qid=20100525032737AATfpBJ[^]
-
Write a function to convert Roman numerals to Arabic numbers. The smaller the better. Bonus points, as always, for obscure languages and obfuscated assembler.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
Chris... you should know that we don't make homework here... :rolleyes:
[www.tamautomation.com] Robots, CNC and PLC machines for grinding and polishing.
-
Write a function to convert Roman numerals to Arabic numbers. The smaller the better. Bonus points, as always, for obscure languages and obfuscated assembler.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
-
You get points for at least writing code. As opposed to some members... (dark looks all 'round).
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
-
I never enter a contest without knowing the prize, for tax purposes, but also in this case, it could be a job at CP... :doh:
Actually it's a personality test to see who among you are worthy of being labelled a Brogrammer.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
-
Thanks wizardzz, I suppose he meant like virtual points, or maybe pints, I'll definitely takes pints! :-D
It was broke, so I fixed it.
-
Don't you mean 'V' him?
Steve _________________ I C(++) therefore I am
-
Actually it's a personality test to see who among you are worthy of being labelled a Brogrammer.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
You may want to snag CodeBroject.com just in case (CodePreject.com too).
-
You get points for at least writing code. As opposed to some members... (dark looks all 'round).
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
Just like positive reenforcment in the schools today, everybody gets a trophy, even when they're wrong. Thanks! :thumbsup: :-D
It was broke, so I fixed it.
-
Write a function to convert Roman numerals to Arabic numbers. The smaller the better. Bonus points, as always, for obscure languages and obfuscated assembler.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
as a nerd, i can't resist... between, it's only a quick n' dirty solution:
public static int RomanToArabic(string romans) {
if (string.IsNullOrWhiteSpace(romans))
{
return 0;
}
//remove whitespace...
romans = romans.Replace(" ", string.Empty);
//make sure no one pass out an "A" for example...
if (!Regex.IsMatch(romans, "(I|V|X|C|M|D|L)+"))
{
throw new ArgumentException("Invalid numeral!!");
}//actual validation that matters (based on http://en.wikipedia.org/wiki/Roman\_numerals): //The symbols "I", "X", "C", and "M" can be repeated three times in succession, but no more. "D", "L", and "V" can never be repeated. string invalidSequences = "(XXXX+)|(IIII+)|(CCCC+)|(MMMM+)|(DD+)|(LL+)|(VV+)"; if (Regex.IsMatch(romans, invalidSequences)) { throw new ArgumentException("Invalid sequence!!"); } int result = 0; result += Regex.Matches(romans, "IV").Count \* 4; romans = Regex.Replace(romans, "IV", string.Empty); result += Regex.Matches(romans, "IX").Count \* 9; romans = Regex.Replace(romans, "IX", string.Empty); result += Regex.Matches(romans, "XL").Count \* 40; romans = Regex.Replace(romans, "XL", string.Empty); result += Regex.Matches(romans, "XC").Count \* 90; romans = Regex.Replace(romans, "XC", string.Empty); result += Regex.Matches(romans, "CD").Count \* 400; romans = Regex.Replace(romans, "CD", string.Empty); result += Regex.Matches(romans, "CM").Count \* 900; romans = Regex.Replace(romans, "CM", string.Empty); result += romans.Count(x => x == 'I'); romans = romans.Replace("I", string.Empty); result += romans.Count(x => x == 'V') \* 5; romans = romans.Replace("V", string.Empty); result += romans.Count(x => x == 'X') \* 10; romans = romans.Replace("X", string.Empty); result += romans.Count(x => x == 'L') \* 50; romans = romans.Replace("L", string.Empty); result += romans.Count(x => x == 'C') \* 100; romans = romans.Replace("C", string.Empty); result += romans.Count(x => x == 'D') \* 500; romans = romans.Replace("D", strin
-
Don't you mean 'V' him?
Steve _________________ I C(++) therefore I am
Good catch. Live long and prosper.