« Sprite Threading | That's Not Totally What I Meant » |

Since the invention of the printing press made dime-store novels a commodity, as intended, distribution has always been a problem. With places like "The House" on "The Street" in "The Empire" on which "The Sun" never sets, postmen have their work cut out for them. Luckily, postmen are very clever and have come up with systems for describing how to route mail.

Like programmers, postmen are also lazy; they'll give you discounts for making their job easier if you utilize the cleverer parts of their system. For instance, in the United States, you can make postal workers happy by printing a simple barcode on your item. This barcode includes a check digit.

The way **Kat** (who has been in the industry for many years) describes it:

The check digit is calculated by adding up all the digits of the barcode, throwing away the tens place, and modding the rest by 10. So, if all the digits of the barcode add up to 39, you ignore the 3, and 9 mod 10 leaves you with 1. Couldn't be simpler, right?

Unfortunately, her company decided to hire programmers during the last minute Y2K rush. Combine that with the fact that their printing software came with a "custom language" (like C, but not quite) and it's obvious why hiring new people had become hard. The obvious solution was to lower standards.

That year, they brought on a number of business students as long as the candidate had at least one programming course under his belt. Still, **Kat** was surprised when the `CalculateCheckDigit` function turned out to be thousands of lines long. To wit,

counter=0; if(zipcode>=00000) if(zipcode< 10000){ if(zipcode>=0000) if(zipcode<1000){ if(zipcode>=000) if(zipcode<100){ if(zipcode>=00) if(zipcode<10){ if(zipcode>=0){ if(zipcode>=1){ if(zipcode>=2){ if(zipcode>=3){ if(zipcode>=4){ if(zipcode>=5){ if(zipcode>=6){ if(zipcode>=7){ if(zipcode>=8){ if(zipcode>=9){ counter+=9; }else{counter+=8;} }else{counter+=7;} }else{counter+=6;} }else{counter+=5;} }else{counter+=4;} }else{counter+=3;} }else{counter+=2;} }else{counter+=1;} }else{counter+=0;} } if(zipcode>=10) if(zipcode<20){ if(zipcode>=0){ if(zipcode>=1){ if(zipcode>=2){ if(zipcode>=3){ if(zipcode>=4){ if(zipcode>=5){ if(zipcode>=6){ if(zipcode>=7){ if(zipcode>=8){ if(zipcode>=9){ counter+=0; }else{counter+=9;} }else{counter+=8;} }else{counter+=7;} }else{counter+=6;} }else{counter+=5;} }else{counter+=4;} }else{counter+=3;} }else{counter+=2;} }else{counter+=1;} } /* ... */ } /* ... */ } /* ... */ } /* ... */

Luckily, the business students did know a bit about optimization. In order to make the function faster, they got a list of postal codes that were not in use and deleted the lines for those ZIP ranges from their pyramids of power.

And in case anyone was wondering: yes, the address described in the first paragraph is a real place.

« Sprite Threading | That's Not Totally What I Meant » |