07.27
I mentioned in the last post that I’ve been doing a programming project for a few months. One of the things that we found necessary was url shortening. You know, that’s where you take a web address that looks like this:
http://www.slate.com/articles/sports/fivering_circus/2012/07/london_olympics_viewers_guide_slate_s_day_by_day_cheat_sheet_for_the_2012_games_.html
and turns it into something that looks like:
http://sobr.org/aF
This is beneficial for services like Twitter, that have limited content space. You start with “/0″, then go to “/1″, “/2″ and so on until you get to “/Z”. Then you flip to “/00″, “/01″, “/02″ and so on. When you get to “/ZZ”, you flip to “/000″. You get the idea.
Anyway, I started thinking about it today and wondering how many possible url’s we will be able to shorten with that scheme.
We use this character set: 0-9, a-z, A-Z, for a total of 62 possible characters. So, the math is 62 ^ x, where x is the number of character spaces in the shortened url.
Here’s the result:
1 chars: 62
2 chars: 3844
3 chars: 238328
4 chars: 14776336
5 chars: 916132832
6 chars: 56800235584
7 chars: 3521614606208
8 chars: 2.183401055849E+14
9 chars: 1.3537086546264E+16
So, by the time we get through 6 characters (http://sobr.org/ZZZZZZ), we would have shortened a total of 57,731,387,490. I’d say 57 billion url’s is probably gonna last me the rest of my life.
Here’s the php script that runs the calculation:
$charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charcnt = strlen($charset);
for( $i = 1; $i < 10 ; $i++ ) {
echo "$i chars: ".pow($charcnt, $i)".\n";
}



[...] Southern Bread Blog (n.d.). How many url’s can you shorten? [...]