- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Admin
Give him +1 for figuring out how to do that in Excel (unless it's automatic, where you type "I" in the first box and all other values increment by dragging).
Admin
Tokenize on (IV, IX, I, XL, XC, X, CD, CM, C, M), map to (4, 9, 1, 40, 90, 10, 400, 900, 100, 1000), and sum.
Actual code is left as an exercise for the reader.
Admin
Of course EMACS users would just use M-x roman-numerals-mode, but that's another story.
Admin
What the hell is it with people and having to return "error codes" from everything? THIS ISN'T VB6. There are sophisticated error handling in modern languages, you don't need to return ints or bools all over the place.
Admin
You must be a barrel of laughs in a requirements meeting.
Customer: We need to display the number of days between any two given dates.
Anon: That's impossible. Some months have a different number of days from other months. And the number of days in each month can change: What about leap year? And historically, countries switched from the Julian to the Gregorian calendars at different times.
Surely the obvious reply is: "The problem is not trivially simple" and/or "The problem as stated has some ambiguitites" is not the same as "The problem is impossible". In this case, we would either agree up front on our definition of how Roman numerals are to be parsed, or if we really wanted to be thorough, we could include some setting or parameter to specify which variation we want. This is hardly a ground-breaking idea. We regularly deal with different date and number formats. Why not different Roman numeral formats?
Admin
Admin
Admin
Admin
Admin
Admin
...and to those curious: I did not write the above function by hand neither -- I used his rom2num to generate mine.
Admin
...last time i checked the "modern numerals" were called "arabic" ;)
Admin
As the author of the article wisely suggested with the comment about >>lots of "code"<<, the real WTF is not separating code and data apropriately.
The data as this should be stored in an editable database relation:
and then accessed with a simple SQL query:
Of course in a real life application would add a caching proxy layer, and/or store the database in a ROM (as the name of the function suggests).
Admin
Admin
No real magic going on b/c this is "Haskell". It'd be 1 line of perl or any language w/ recursion. The string as a hash key helps ... which supports that it'd be 1 line in perl too.
Admin
'; echo roman2dec('MMVI'); //2006 echo '
'; echo roman2dec('MCMLIV'); //1954 echo '
'; echo roman2dec('MCMXC'); //1990 echo '
'; echo roman2dec('IV'); //4 echo '
'; echo roman2dec('V'); //5 echo '
'; echo roman2dec('MCMXLIV'); //1944 echo '
'; echo roman2dec(''); //0 echo '
';
Admin
"Haskell", officially the new name for Python.
Admin
Admin
Somewhat serious followup: Give me a regex that will match only movie titles that end in Roman numerals. Take into account that sometimes there will be a secondary title, as in "Death Warriors IV: the Deaths Continue".
I tried to do this a few years ago on IMDb to figure out what the highest numbered "sequel" was. Ran into the problem that "mi", "di", "xi" and others are actual words in some languages.
Admin
prmivm
FTFY
Admin
Admin
Admin
Nobody said it was impossible. Do you always put words in other people's mouths so you can argue with them?
Admin
Admin
Nah, first he wrote a decimal to roman converter.
Admin
Ouch! You just tried to correct [fake] Nagesh when he is actually correct.
While they are often called "Arabic" numerals, they are more correctly called "Indo-Arabic" numerals. In the west we call them Arabic numerals because we learnt them from Arabs who, in turn, learnt them from the Indians.
Admin
That's about 25 lines of code (including the comments that are necessary to make Haskell readable). It would've been less typing in something like COBOL (and probably faster too, as there's no need to depend on the misuse of recursion)!
Admin
Admin
replace: "IV" => "4", "IX" => "9", "IL" => "49", "IC" => "99", "ID" => "499", "IM" => "999", //"VL","VC","VD","VM" not supported, use XLV instead... "XL" => "4", "XC" => "9", "XD" => "49", "XM" => "99", //"LD","LM" "VI" => "6", "VII" => "7", "VIII" => "8", "I" => "1", "II" => "2", "III" => "3", "V" => "5", "X" => "1", "L" => "5", "C" => "1", "D" => "5", "M" => "1",
Admin
Admin
And, in Haskell, you can return the error indicator just by using the Maybe type (in a new programming language, currently codenamed "Ibtlfmm", the you can use the successor type which is the same as Haskell's Maybe just with a different name)
I often complain about same things tooAddendum (2012-04-02 15:45): (MMMIM is a non-standard, but valid, roman numeral; IIX, however, is not even valid.)
Admin
That code in question did in fact fail on IX though. As will most of the examples people have shared.
Admin
example here... http://www.dofactory.com/Patterns/PatternInterpreter.aspx
This pattern also works out well for creating a sounddex generator.
Admin
TRWTF is that Roman numerals are still used in certain contexts. How fucking shit-for-brains stupid is that.
Admin
Admin
There was actually a serious (maybe) proposal to add Roman numerals to Python, but it got rejected:
PEP 313
Too bad. I wanted to see whether I could calculate the square root of pi, using only Roman Numerals.
Admin
mine certainly did not fail on IX
Admin
Here's my (crummy) stab at it: (Now with input validation)
PRINTS:
Admin
This will get you started CD/CXXVII = PI
Admin
Don't laf. There is such a thing as Feminist Algebra. Yes, it's moronic, but is a real-life kolluge kourse.
Admin
BFD. The copyright expired centuries ago. And, as we say in non-static, loosely typed societies (a little computer language lingo as societal commentary there), "yeah? so what have you done for me lately?"
Admin
I guess his solution to the first exercise was this:
printf( "99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n" "98 bottles of beer on the wall, 98 bottles of beer.\nTake one down and pass it around, 97 bottles of beer on the wall.\n" "97 bottles of beer on the wall, 97 bottles of beer.\nTake one down and pass it around, 96 bottles of beer on the wall.\n" "96 bottles of beer on the wall, 96 bottles of beer.\nTake one down and pass it around, 95 bottles of beer on the wall.\n" "95 bottles of beer on the wall, 95 bottles of beer.\nTake one down and pass it around, 94 bottles of beer on the wall.\n" "94 bottles of beer on the wall, 94 bottles of beer.\nTake one down and pass it around, 93 bottles of beer on the wall.\n" /* SNIP 92 lines */ "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n" "1 bottle of beer on the wall, 1 bottle of beer.\nTake one down and pass it around, no more bottles of beer on the wall.\n" "No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n");
Admin
Admin
Really? In this thread?
Why not:
Admin
The company's hiring practices alone could be its own article.
Admin
Bleedinell. You ain't wrong:
http://www.sydneyline.com/Gross%20and%20Levitt%20review.htm
"There was actually a paper read at a 1993 meeting of the Mathematical Association of America entitled 'Toward a Feminist Algebra' by Maryanne Campbell (a literary critic) and Randall K. Campbell-Wright (a mathematician).
Part of the paper was a call for an end to what it claimed were sexist stereotypes in college algebra textbooks. They disapproved of problems which used examples of a girl and her boyfriend running towards each other because this portrayed heterosexual involvement. On the other hand, they recommended approval of problems about Sue and Debbie, 'a couple financing their $70,000 home'. They wanted algebra problems to present female heroes, to analyse sex differences and to affirm women's experiences.
Taking to heart the absurd shibboleth of contemporary literary theory that all language is metaphor, Campbell and Campbell-Wright set out to prove that metaphor plays a central role in the language of mathematics. They do not demonstrate this through the obviously rather difficult cases of symbolic statements and formulae. Instead they offer verbal examples culled from textbooks -- 'manipulate an algebraic expression', 'attack a problem', 'exploit a theorem' -- as evidence that mathematics is a nest of aggression, violence, domination and sexism.
From this they derive postmodern literary dogma such as: 'Mathematics is portrayed as a woman whose nature desires to be the conquered Other.' They want the whole field of mathematics reappraised so that its imagined failings can be rectified and it can become a discipline fit for women to enter. Gross and Levitt, however, are more perceptive about their motives.
'The purpose of the carefully tailored feminist language and imagery is not primarily to build the self-confidence of women students, but rather to convert problems and examples into parables of feminist rectitude. It is, at bottom, not different from an imaginary Christian fundamentalist pedagogy requiring that all mathematics problems illustrate biblical episodes and preach evangelical sermons.'
... and then I must point you towards this:
http://stonetelling.com/issue1-sep2010/johnson-towards-a-feminist-algebra.html
... enjoy, you buggers.
Admin
Admin
Ummm, oops.
No error checking and lots of WTFery, but that's the general idea.
Admin
Probably not "the" way to do it in c#, but it works... [code] private enum RomanNumerals { I = 1, V = 5, X = 10, L = 50, C = 100, M = 1000 }
[/code/