- 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
Err, "write" this I mean.
Admin
CAPTCHA: validus : Latin meaning valid
Admin
Admin
Admin
I know what it's supposed to do, but I think they missed the point entirely. That's like cutting a sandwich into one piece and expecting to be able to share it without any further action.
Admin
Admin
Admin
David St. Hubbins: It's such a fine line between stupid, and clever.
Admin
This person could have AT LEAST used else ifs
Admin
Holy sh*t dudes
Admin
But i would suggest using the metal table for that. Or an oaken table.
Admin
FTFY.
Admin
Apple has filed for a trademark on "max-iPad" It will blow the doors off of the current iPad. Packed with more memory, but fewer memory leaks.
Admin
Maybe the compiler can optimize it to the point that a sane coder would write it :-)
Admin
This is the part of the code that I think is the most useful:
function ZeroFill(Data) {
var length = Data.length;
var NewData;
if (length >= 100) {
NewData = Data.substring(0,length);
}
/// should be followed by: perhaps replacing: "NewData = Data.substring(0,length);" with: if(NewData != Data.substring(0,length)) writeln( "I am sorry to inform you that your computer is ill." );
Captcha: usitas (it is... because it is too expensive to fix)
Admin
How embarrassing. It should look more like this:
if (length == 1) {
Data = "0" + Data;
} if (length == 2) {
Data = "0" + Data;
}
Sorry for the confusion caused by my inattention to code produced try to make a joke. It clearly interfered with your ability to detect sarcasm.
Admin
OOPS :). so much stuff to make fun of... we will just forget I ever said anything.
Admin
Shouldn't that be something like:
Left("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", 100-len("12345")) & "12345"
?
captcha: nobis - a noble noob
Admin
Com'n now. He simply unrolled the loop.
Admin
==== Teacher mode on ====
==== Teacher mode off ====Well, coming to think of it, I'd probably use a for-loop. But hey, it's almost a text-book example for this kind of stuff...
Admin
I just think you do not need a hundred zeroes either, because I believe VB has a function to replicate a string. (Gladly, my VB-coding days are looooong gone.)
Admin
Ahh the joys of being paid by the line.
Admin
Admin
I was thinking the same thing... the endless if's are one thing, but the wtf moment is in the first one... and they aren't even if/else's so each one has to be evaluated.
Admin
what, no switch??
Admin
You sure do! Lots and lots of charming ones.
Admin
they were REALLY REALLY careful about counting the right number of zeros in every of the ONE HUNDRED use cases...
Admin
Admin
Apparently your inattention to code is rivaled only by your inattention to English.
Admin
One who was being paid per line generated.
Admin
The correct way would of course be:
import std.range; NewData = take(cycle("0"), 100 - length) ~ Data;
Admin
Uh-oh, looks like we've been hacked by Perez Hilton.
Admin
I like how his >=100 check doesn't even work....
Admin
Truly horrifying. I hope it's a joke. Even someone coming out of the hackiest fly-by-night six-month tech "college" would do better. Hell, even a kid straight out of Comp Ed in high school would do better.
Of course PHP already has something built in!
Admin
Admin
Was the code at least correct? :-)
Admin
Actually, VB (6.0 and earlier; not VB.NET) would make coding this problem more efficiently than the Java/.NET solutions offered: VB has a native "String$(number,string)" function which returns a string repeated "number" of times.
Instead of having to manually define a string of 100 "0" characters, VB would allow you to reduce this function to a one-liner:
Function ZeroFill(Data as String) As String
End Function
I'm sure there's Java / C# libraries that would implement the same functionality as the "String$" function, but VB 6.0 provides a decent solution using "native" calls.
VB 6.0 FTW! :-P
Admin
Your definition of efficiency is amusing to me.
Admin
OK, I admit I didn't test the code I posted, and it was buggy. Next time I try to make a joke I'll be careful to do it with tested code, so we don't have to get bogged down in the details.
My point, which has been totally lost by now, was to make it worse, and thereby possibly make someone chuckle. If I were to actually implement this functionality I'd probably just do this in C#
return data.PadLeft(100, '0');
Admin
Yes, .NET has both a String.PadLeft and String.PadRight function that does this as a one liner:
public string ZeroFill(string data) { return data.PadLeft(100,"0"); }
It doesn't even require you to work out the length of your string and how many extra characters you need to pad. It does it all for you. In fact, there really isn't much point in bothering with writing the ZeroFill function in the first place.
Admin
You can make the code an order of magnitude smaller:
Admin
But then you would have to type in 100 zeros!
I would do this:
Admin
Common idiom:
Admin
This code calls for optimization using Duff's device.
Admin
Why the hate toward Lisp?
In lisp, we wouldn't even need a library, it's in the core language:
(format nil "~100,'0D" input)
Admin
Genius. I wish every company had such dedicated employee....
Admin
Function ZeroFill(Data as String) As String
End Function
FTFY. :)
Admin
And also broken, since 'length' never changes, nor does 'Data'. As implemented, the entire function is a verbose way of saying 'return "0" + Data;'.
Admin
I can't believe they didn't use a case statement.
Actually I also like if (length >= 100) { NewData = Data.substring(0,length);}
could at least bother to trim to 100 chars :-)
Admin
No, this code calls for optimization with a blunt instrument, and a way of securely disposing of a body.