• ticanito (unregistered)

    Hey ! I live within the first range of zipcodes !!!

  • That guy (unregistered)

    Someone's read "Loops considered harmful"

  • Jay (unregistered) in reply to delta224
    delta224:
    I wonder if the person was getting paid by LOC.

    A company I worked for years ago talked about rating programmers by lines of code produced per day. I was quite disappointed that they didn't do this. I had lots of plans like this in mind to really boost my productivity.

  • Jay (unregistered) in reply to Massive Debt
    Massive Debt:
    BentFranklin:
    How would string manipulation functions help calculate the check bit?

    ASCII digits are a linear shift from the real number. So, you can turn the letters into numbers quite easily in assembler.

    Well, not really a shift. digit = ascii & 0x0F.

    Personally, I always use " ascii - '0' " as more readable, though. Surely slightly slower, but more readable.

  • Jay (unregistered) in reply to Paul Vouga
    Paul Vouga:
    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.

    The solution I've used on several occassions is to take the sum of the odd-position digits plus 3 times the sum of the even-position digits, then take the mod on that.

    So 1234 -> (1 + 3) + 3 * (2 + 4) = 22 22 mod 10 -> check digit 2 (or 8 if you want to take 10 minus).

    1243 -> (1 + 4) + 3 * (2 + 3) = 20 20 mod 10 -> check digit 0

    i.e. a transposition gives different results.

  • (cs) in reply to Jay
    Jay:
    take the sum of the odd-position digits plus 3 times the sum of the even-position digits, then take the mod on that

    That fails to catch certain transpositions like 32 => 23 (Luhn fails to catch 09 => 90, to be fair.)

    For an algorithm that catches all transpositions:

    http://en.wikipedia.org/wiki/Verhoeff_algorithm

  • Srh (unregistered)

    Holy Mary, mother of Jesus...

  • Coder (unregistered) in reply to Yaos
    Yaos:
    The code is pretty scary, what happens if the value of 1 changes in the future to 2 or even 3? It would be much faster and easier and secure to create an access database, in one table you have every possible barcode and in another table you have every possible address and then a 3rd table that is used to join the address to the barcode.

    As a bonus, this ensures you will always only create barcodes for addresses that exist which will save the post office money because they won't try to deliver to an address that does not exist.

    Yes, that is the way a modern addressing system works.

    Every single delivery point has a unique code. To get the cheapest rate, you put the correct unique code on every single piece of mail. To do that, you have an enormous database of every single address point, with it's correct unique index. And every single unque code has a "correct" mail address, which the is used for final delivery.

    The unique mail point database is provided by the post office. I don't know if the post office in your country has a modern addressing system.

    Big mail houses also have mail lists, which match people to address points. This is a separate service.

  • Flaming Foobar (unregistered) in reply to Flaming Foobar
    int calc_check(char *s)
    {
      static int frist=1;
      return *s?(frist?(frist=0,10-(*s-'0'+calc_check(s+1))%10)%10+'0':*s-'0'+calc_check(s+1)):(frist=1,0);
    }
  • (cs)

    Have you noticed your trackbacks are all spam?

  • (cs)

    To think so much of the repetition could have been done away with using one goto.

  • xyz (unregistered) in reply to dgushurst
    dgushurst:
    AWTF: "As for the most wondrous thing about this program? The coder took special care to find out exactly what ZIP code ranges aren't used by the postal service, so as to avoid unnecessary coding for those ranges."

    Looks to me like this "code" goes to extra pains to test every zipcode against every range. Otherwise they would have used an if-else-if construct.

    Not to mention the zipcodes change a bit. We have to cass certify some data vs the postal zip codes with a system which has to be updated every 90 days. There has always been at least 1 zip code change every update and some times more.

  • Anonymous (unregistered) in reply to joeyadams
    joeyadams:
    To think so much of the repetition could have been done away with using one goto.
    Quieten down man, you'll attract the... uh oh... [image]
  • Tarass (unregistered)

    Wouldnt this work?

    int checkDigit(char *zipcode) { int result = 0; for(;*zipcode != '\0';zipcode++) { result+=*zipcode-'0' if(result>10)result-=10; } return 10 - result; }

  • Anonymous (unregistered) in reply to frits
    frits:
    There seems to be a few semicolons missing.

    It must be JavaScript.

  • Tarass (unregistered) in reply to Anonymous
    Anonymous:
    joeyadams:
    To think so much of the repetition could have been done away with using one goto.
    Quieten down man, you'll attract the... uh oh... [image]

    The raptor? :)

    http://xkcd.com/292/

  • Chris Casto (unregistered)

    Woah, deja vu.

  • (cs) in reply to Flaming Foobar
    Flaming Foobar:
    int calc_check(char *s)
    {
      static int frist=1;
      return *s?(frist?(frist=0,10-(*s-'0'+calc_check(s+1))%10)%10+'0':*s-'0'+calc_check(s+1)):(frist=1,0);
    }

    hyperventilating

Leave a comment on “Check Digit Check”

Log In or post as a guest

Replying to comment #:

« Return to Article