- 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
Was this before or after In the Mix?
Admin
Just my one-liner:
captcha: saluto. I saluto to this code.
Admin
http://lmgtfy.com/?q=roman+numeral+converter
Admin
I hope you're trolling. It's one line, not 25. The fact that you would need 24 lines of comments to understand one line of code, says nothing about Haskell, and everything about you. I only read the line of code, not the rest of his post, and I understand perfectly what it does, and how. (It's quite succinct and clever by the way, kudos Meep.) So either I am much smarter than you, or you have never read one book on Haskell, and for some reason find it strange that this implies you don't understand the language. Probably both.
You clearly don't even understand how a processor works. There is no direct recursion in his code, but some of the library functions he uses are implemented as tail recursive functions. Modern compilers (you know, like the one used to compile Haskell, but also most modern C compilers) will output the exact same processor instructions for a tail-recursive function as a C compiler would for a while loop.
Admin
Admin
They wouldn't fail PROPERLY on VIIII, as that is not a valid roman numeral.
http://mathworld.wolfram.com/RomanNumerals.html http://chart.copyrightdata.com/ch02.html
Admin
You know, I wish I used a language that allowed us to put pointlessly long lines together in the name of stupidity.
Oh wait... I do:
With some spacing, for mere mortals:
http://pastebin.com/usUTLr42
Admin
From your first link:
"the practice of placing smaller digits before large ones to indicate subtraction of value was hardly ever used by Romans and came into popularity in Europe after the invention of the printing press"
So VIIII is a perfectly valid Roman numeral, though the canonical form is probably IX (VIV is definitely incorrect though.)
It might be worth pointing out though IL is ambiguously 49, the more usually seen way to write that is XLIX. The general rule is that you would only write subtraction BA if B was a power of ten (I, X, C) and A was either 5 * B or 10 * B.
Admin
Yawn. I can do it in one statement in Intercal:
READ OUT ,1
(possibly 2 if you need to add a PLEASE before it, and depending on whether you interpret the PLEASE as a separate statement or not).
Admin
Before, but there's probably some old western starring Tom Mix that would produce another false hit.
Admin
Admin
Sorry, dude. That is Python.
Admin
Eee ya plonker. Alegbra is for people with saggy legs.
Admin
Admin
[quote user="briverymouse"][quote user="Brendan"]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)![/quote]
I hope you're trolling. It's one line, not 25. The fact that you would need 24 lines of comments to understand one line of code, says nothing about Haskell, and everything about you. I only read the line of code, not the rest of his post, and I understand perfectly what it does, and how. (It's quite succinct and clever by the way, kudos Meep.) So either I am much smarter than you, or you have never read one book on Haskell, and for some reason find it strange that this implies you don't understand the language. Probably both.
To be honest, it was a mixture of trolling and joking. However, they say behind every joke there's an element of truth, and obviously this element of truth has made you react in the way you have.
I've never learnt Pascal, or COBOL, or Objective C, or MIPS assembly; but have no trouble reading code written in any of these (and many other) languages. Some languages are so good that a person with no programming experience at all can get a good idea of what the code is doing. Some languages are so bad that even after learning the language you can't easily follow source code written in it. Are you suggesting that reading a book on Haskell is a necessary step just to understand Haskell source code? If so, what does that tell you about Haskell?
[quote user="briverymouse"]You clearly don't even understand how a processor works. There is no direct recursion in his code, but some of the library functions he uses are implemented as tail recursive functions. Modern compilers (you know, like the one used to compile Haskell, but also most modern C compilers) will output the exact same processor instructions for a tail-recursive function as a C compiler would for a while loop.[/quote]
The best way to tell what the compiler generates is to have a look at what the compiler generates. Either post a disassembly so I can laugh at it, or use silence to admit defeat.
Admin
code obfuscation for the win
here is a ruby version:
$h = { "I" => 1, "V" => 5, "X" => 10, "L" => 50, "C" => 100, "D" => 500, "M" => 1000 }
def r2d(r, p=0);r.empty? ? 0 : r2d(r[0..-2], v=$h[r[-1]]) + (v < p ? -v : v);end
Admin
And here I thought most natural women desired to be the conquered other. Take the terms we use in every day society, "A man takes a wife", "A woman gives herself to her man." On top of that look at the desire for women to be attractive, to display themselves to attract a good mate. It seems biologically wired that women should be seen this way, but not as weak, one can conquer and take a strong woman, and trust me if she remain strong even when she is yours it is so much better. :)
Admin
Admin
Some people look at a problem and think "I know, I'll use regular expressions." Now they have II problems.
Admin
Admin
With roman numbers you don't just copy last line, hit backspace and add a char one position higher than the one you erased. If it were that simple it could be done on an "auto-pilot" mode (albeit it would still be a minor WTF)
So, how does your foot taste?
Admin
Admin
Admin
Captcha: commoveo => Con los ojos.
Admin
I never said it was good production code. It obviously isn't. Nesting two list comprehensions is something I would probably never do. This is roughly what I would write in practice (based on Meep's code): http://pastebin.com/7KK7r8jW (I added error handling, as this is supposed to be production code.) As you can see, only ten lines, of which two are imports that you probably already have in any serious application, one is a blank line, and one is a type annotation that's only added for clarity.
Still, Meep's code is very readable considering it's a one-liner, and every person that actually knows Haskell needs less than a few seconds to see what it does. And it is a one-liner: adding a line break anywhere in there would feel unnatural. I'm not sure what you mean by instruction, as there's no such thing in Haskell, but you probably mean the semicolons. They are part of the case statement, and could indeed be replaced by newlines, but having a small case statement like that on one line is not always considered bad style.
Admin
What the hell, have some old school VB:
Deals with all the weird stuff like IIIIX, CCCCCCCCCCCCCCCCCCCIC etc, who knew 1999 can be written as MCMXCIX, MLMVLIV, MXMIX, MVMIV & MIM.
Admin
Admin
MCMXCIX: yes. MLMVLIV: no, VL doesn't work because V is not a power of 10. MXMIX: no, XM doesn't work because M > 10 * X MVMIV: no, VM doesn't work because V is not a power of 10 and M > 10 * V MIM: no, IM doesn't work because M > 10 * I
You could also write it as MDCCCCLXXXXVIIII which is how the Romans would have written it.
Admin
Admin
Since there aren't any rules for Roman numbers (citation needed & all that), all those variations are equally valid.
Those variations are from Excel; for whatever reason it gives you the option of specifying how long-winded you want to be.
Admin
Haskell:
Python:
Which one would you most easily understand? Obviously the Python one. Which one would you most easily understand once you know what foldl1 does? Obviously the Haskell one: it's all there on one line, it folds 1 to 10 using addition. Choose the right tool for the job: if you want your code to be understood by non-programmers, by all means use a language that's easy to read for non-programmers. If you want your code to be easily understood by programmers, use a language like Haskell.
http://pastebin.com/2miyJFjiAdmin
Since we don't have a new WTF (yet?) today, I thought I'd share one.
I sat down to dial in to my daily conference call this morning. You know, the one where 18 highly paid people waste an hour each listening while three people discuss the project's lack of progress? I don't typically say more than one sentence a week but there's no cost to the meeting organizer to invite everyone who might slightly be needed so they blast the world. And in our organization the culture is that you just can't decline a meeting invite without a pretty good reason, like being dead.
So we spend five minutes waiting for the moderator, then having everyone connect and introduce themselves, and we're almost ready to get down to real not-work when the call suddenly hangs up on everyone. What to do, what to do? Start over of course.
So five minutes later everyone is kicked off again.
This happens a couple more times before we figure out that maybe we can live through the day without this call. You think?
Later the word comes back: the problem was we exceeded our license for 120 simultaneous conference calls.
WTF#1: Spending 5 hours a week waiting for that one moment to answer a question that could be done in 30 seconds by email.
WTF#2: Multiplying WTF#1 by 18 highly paid people.
WTF#3: Multiplying WtF#2 by 120 simultaneous calls. Even if we average only 3 people per call, that's 360 people in our organization all discussing at the same time why nobody is getting anything done. And that's this hour. Start over next hour?
WTF#4: Could there possibly be a less graceful way to handle the error condition "you haven't paid us enough money to do that"?
WTF#5: Me, I guess, for trying to tolerate all this.
Admin
Really? Hitler wandered around the wilderness tending sheep?
Admin
Did you hear they made a sequel to "Malcolm X"? It is, of course, called "Malcom XI".
Admin
Can we include this text in the description of Algebra II in our course catalog? I think it could really boost enrollment.
Admin
Admin
What this thread really needs is a code competition...
Admin
Side note: Roman numerals do have one obvious advantage: Addition is easy. At least, if you use "old style" Roman numerals where you don't do that "if the next symbol is higher subtract" stuff, so you write 4 as "IIII", etc.
To add two numbers, just ram the two together and replace any counts that now "carry" with the higher digit, like 5 I's with a V. Sort them if you like, but it doesn't really matter.
For example: LXVII + XXIII. LVXIIXXIII. IIIII=V so LVXVXX. VV = X so LXXXX. Done. It's probably easier for children to learn.
Multiplication isn't that tough either. The "times table" is shorter as you only have to deal with 7 symbols -- I, V, X, L, C, D, and M -- instead of 10. I * I = I, I * V = V, ... V * V = XXV, V * X = L, ... X * V = L, X * X = C, X * L = D, ...
Multiply each digit of one number by each digit of the other. Ram them all together. Then do the "carries". E.g. LXVII * XXIII = DCLXX DCLXX LXVII LXVII LXVII. The first two groups are when we multiply each digit by X, which we must do twice because there are two X's. The other three groups are when we multiply each digit by I, which we do 3 times. Then simplify:
DCLXX DCLXX LXVII LXVII LXVII IIIII=V: DCLXX DCLXX LXVV LXV LXVI VV=X: DCLXX DCLXX LXX LXX LXI XXXXX=L: DCLL DCL LX LXX LXI LL=C: DCC DCC X CXX XI CCCCC=D: DD D X XX XI DD=M: MDXXXXI
Of course a Roman would have done several roll-ups in each pass, maybe all in one pass if he was "good at arithmetic".
I suspect that with some practice, it's easier to do addition, subtraction, and multiplication with Roman numerals than with Hindu-Arabic numerals.
Division was probably tough. Of course writing arbitrarily large numbers, working with decimal places, and many other functions are more difficult. I'm not suggesting we use Roman numerals. But they're not totally dumb.
Admin
You said, "The real WTF is ..." What did that mean other than, "The problem is unsolvable"?
If you simply meant, "The problem is inadequately defined", well, nobody said that the one sentence given in the article was the complete description or that the employee was not allowed to ask questions.
Admin
Nobody notice that this code can only go up to 2011. Did program candidate think world going to end after that or did he think nobody is going to remember Roman Number greater than 2011?
I would like to know his think process.
Admin
Agreed.
Wrong. The most natural solution to the problem is a loop ("foreach"). Ask someone who's never programmed anything before how they would do it and I can guarantee their answer won't involve recursion. Once you know what fold1 does it's "clever".
Note: I use "clever" in a derogatory way. It's like a man who sets up a system of pulleys and levers to push buttons on his remote control just so he can feel superior to everyone else, without realising everyone else thinks he's a moron for not shifting the remote control closer.
This is the essential problem with Haskell - often the most natural solution isn't suitable in Haskell. You have to spend ages learning how to think "clever" before your mind is so screwed up that unnatural solutions seem acceptable; and only "clever" people are stupid enough to think that is a good idea.
The right tool for the job is the tool that allows you to express the most natural solution (and get good performance from that). Haskell is the right tool for doing research into compiler optimisations, and is almost never the right tool for any actual programming.
That isn't the piece of code we're talking about. It isn't even Haskell code. You've attempted to prove that apples are yellow and mushy by squashing a banana.
Admin
Admin
Ask someone who's never programmed anything before how they would do it and I can guarantee their answer won't involve a foreach loop either. They will probably say something like "add the first two, then add the next to it, and so on until the end", which is literally what foldl1 does, and not "make a temporary variable, set it to zero, then take every value from the list and add it to the temporary variable". That would be foldl by the way, which also exists.
What I said was: You asked me to prove it, and I did. What else do you want me to show? I can't show you that Haskell produces the same bytecode as C, because it obviously doesn't: Haskell has an entirely different execution model (lazy evaluation). And I will immediately admit that this sometimes slows Haskell programs down a bit. That's not what you were claiming though, according to you, Haskell's use of recursion slows it down. That's just bullshit.Admin
I love you guys and this forum!
Admin
But part of implementing a feature is settling on a spec. I am proposing that the following set of rules from Wikipedia be adopted when converting Arabic to Roman. The advantage of this set of rules is that the resulting output is unique. (A different, more all-encompassing set of rules could be applied to converting Roman to Arabic; or the same strict set of rules could be used, depending on the scenario.)
Admin
Computer science should being more concurned with conversion of Arabian Numerals (but invention in India) -> to binary.
Admin
simple solution: use a loose regex to get all the sequels, then eliminate entries where prior sequels aren't present - 'In the MVIII' isn't there so 'In the Mix' isn't a sequel.
Admin
Java implementation, only valid roman numerals, throws stadnard exception, single function. It is not so trivial, because the rules for valid numerals.
Admin
IMPORTANT ANNOUNCEMENT:
Alex is in the hospital in an alcohol-poisoning-induced coma. He did not leave me with the access codes, so I cannot post a new article. I encourage you to try the "Random Article" link, or to post a few more implementations of the Roman Numeral conversion libraries in whatever esotaric language you would like.
Admin
And you call yourselves WTFers ...
You're all reinventing the wheel. Not only is this wheel square it's made out of balsa wood!