- 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
Admin
A single equals sign doesn't make for a very useful comparison.
Admin
I can see an episode of Myth Busters here.
Admin
Admin
Admin
Wouldn't that be a gerbil? I stayed away from that intentionally. Unless you're talking about the great felching incident - fake, but funny to read. And I don't know if I'd watch that episode - you'd never be able to watch Buster again...
Admin
Why do you call Rexx a pseudolanguage?
Admin
This is quite bad. If you don't know how to take a modulo, then for a large range of problems you are effectively playing as Arnold J. Rimmer.
Admin
Am I the first one to note that this has come up before?
http://thedailywtf.com/Articles/Checking_Your_Digits.aspx
Captcha: cogo (n) a suite of programs aimed at coordinate geometry problems in civil engineering.
Admin
There's even a duplicate comment: http://thedailywtf.com/Comments/Checking_Your_Digits.aspx#128782
Admin
ASCII digits are a linear shift from the real number. So, you can turn the letters into numbers quite easily in assembler.
Admin
Trolls 1, Posters 0. :-)
Admin
So, excuse me, but you only need semicolons in Rexx if a line is encased in exactly one line of braces?
Admin
...and terminates a block? Clearly absurd.
Or is it "the last element in a multi-line if block"? 'cause I guess that would make more sense, although you'd think that's what the closing brace was for. Syntactic salt from hell!
Admin
Does the compiler see 3 + 4 + 2 as operations to calculate or change it to the value of 9.
It's more efficient to compile 9 because the result of 3 + 4 + 2 will never change anyway unless the code is changed then recompiled.
Admin
Fine, fine...
check = (10 - (sum % 10)) % 10;
Admin
Depends on the compiler - and for many compilers, depends on the flags you pass to the compiler.
The benefit of "3 + 4 + 2" is it makes it clear where the "9" came from.
This sample smacks of generated code.
Admin
Python? Not that you need semicolons anywhere in python, you just can put them at the end of lines if you feel like it.
Not that I think that the above code is python.
Admin
FAIL! Let's try this:
Modulus(12,10): return 12 - ((12/10) * 10); return 12 - ((1.2) * 10); return 12 - (12); return 0;
Admin
Umm, he said "works for languages that "round down" the result of an integer division...
So 12/10 = 1, not 1.2, hence his calculations work with his documented assumptions...
you fail!
Admin
actually, you failed to read the comment at the top of the code. it clearly says, this works for languages that round down after integer division. assuming that we get:
Modulus(12,10): return 12 - ((12/10) * 10); return 12 - ((1) * 10); return 12 - 10; return 2;
Admin
In python:
-sum(int(x) for x in str(barCode)) % 10
Admin
Admin
The problem with summing the digits and taking mod 10 is that it doesn't protect against transpositions of two adjacent digits, a very frequent kind of error: 123456789 and 123546789 both have the same check digit.
One fix is to take the whole number (without summing digits) and mod it by 11. This is guaranteed to detect transposition errors:
<math>The reason is that 10 mod 11 == -1 mod 11. So the check digit of "...dcba" is (a-b+c-d+...) mod 11.
If we transpose two digits, say d and c, we have check("...dcba") - check("...cdba") == (a-b+c-d+...) mod 11 - (a-b+d-c+...) mod 11 == (2c-2d) mod 11 != 0 unless c=d.
</math>Admin
It's OK, he didn't need to code for extra zip codes. The talk is that the Postal Service is bleeding money, so they won't waste money adding new zip codes.
Admin
[quote user="@Deprecated"][quote user="Anon"]On embedded systems without a file system...[/quote]
you would recieve a sound thumping about the ears for wasting precious flash eeprom on code like this.
[quote]
Wouldn't this mess go into a PROM instead of an EPROM?
Admin
Admin
dbaseIII, maybe, but dbaseIII+ which was used by most people did, it was number % number
Admin
[quote user="justsomedude"][quote user="@Deprecated"][quote user="Anon"]On embedded systems without a file system...[/quote]
you would recieve a sound thumping about the ears for wasting precious flash eeprom on code like this.
[quote]
Wouldn't this mess go into a PROM instead of an EPROM?
[/quote]
PROM technology (as a seperate product) disappeared decades ago. EPROM technology is on life support.
The main memory technology in use today is FLASH, and EEPROM.
Admin
Wow... just wow....
Y'know, there used to be ways to address issues like this in a development team....usually it involved printing off code like this, wrapping it around a steel bat and beating the author to death with it in a timely fashion.
In today's environmentally aware culture however, I would suggest just printing off their P45 and using that instead. You'll save a few tree's and still make your point =D
Admin
Ob: Embedded and tables (and more, Oh My!). Yes, sometimes it is easier to use tables for parity and the like. On one embedded project I worked on, the author of the code (he had his name on the company) used 256 byte lookup tables (in an 8 bit micro no less) to lookup such things as:
Yes, it happens, but nothing like this example!
Admin
http://en.wikipedia.org/wiki/ZIP_code
Zipcodes are not really numbers. They are more like numeric strings. Many of them begin with 0 (Zero).
There are actually parts of the US that have three digit zipcodes. Think national parts. Some places I can remember include an area in Montana and most of the Everglades.
FYI: Zipcodes may not be what you think. There are actually zipcodes for places that aren't a place. Zipcodes starting with 095xx is for the navy.
Also, a city can have many zipcodes. Many cities can share a zipcode. Same goes with counties. State boundries are not even sacred as some zipcodes even cross state lines.
And that's just in the U.S. of A.
MArk B.
Admin
It also ensures that the barcode always contains at least a single non-zero number.
Admin
I've used 256-byte lookup tables for CRC calculations before, but never for popcount or parity. For those it's easy to use two table lookups into a 16-byte (nybble-indexed) table. You can even use the same one, e.g.,
Admin
This is one of the funniest things i've read on this board. Takes me back to days of school camp and talent show skits. I just wish I could say I didn't have to deal with code this inane from our "cracker jack senior developer consultant".
Admin
Admin
Admin
Admin
Fun fact, if you deal with mail and relational databases. "State" is not functionally dependent on "Zipcode". Somewhere around 73xxx, there is a town, "Texhoma". One guess which states!
Having encountered this in live data once, it's an easy way to ID a bad SQL tutorial.
Admin
lol...sounds like the kinda code my 8th grade bro would write when he s sleepy :D
Admin
CYA
Admin
In C:
Admin
You mean: switch (zipcode) { //snip case 19: code = code + 1; case 18: code = code + 1; case 17: code = code + 1; case 16: code = code + 1; case 15: code = code + 1; case 14: code = code + 1; case 13: code = code + 1; case 12: code = code + 1; case 10: code = code + 0; case 9: code = code + 1; case 8: code = code + 1; case 7: code = code + 1; case 6: code = code + 1; case 5: code = code + 1; case 4: code = code + 1; case 3: code = code + 1; case 2: code = code + 1; case 1: code = code + 1; case 0: code = code + 0; }
Admin
I documented this poorly, usage:
char check_num=calc_check("12345",1);
There's probably a cleverer way to do the flag but it's been a while since I've written C code.
Admin
Find a website with a check digit calculator that works, such as http://www.gs1.org/barcodes/support/check_digit_calculator (frist google result)
Steal code from website
?????
PROFIT
Admin
Ahh, the new floating point int. That's what I call a powerful language. Maybe php?
/* captcha: abbas , theres more of them now? */
Admin
Admin
Yeah because they intended to embed this algorithm into their postscript printers.
Admin
Well, at least he was studious in examining his sources thoroughly.