A blog about technology, photography, and stuff

Tuesday, September 30, 2008

The Math behind TinyURL

TinyURL is a website that condenses a submitted URL, usually a long one, into a short readable URL on tinyurl's website. In turn, this shorter URL then redirects to the original url. This is quite handy.

As of this writing, the text below their logo reads:
Making long URLs usable! More than 90 million of them. Over 1.5 billion hits/month.
From what I've seen, they only use letters and numbers. So that gives us 26 possible letters, which are not case-sensitive (in other words, "A" is the same as "a"). There are 10 numbers then, zero through nine (0-9). So through TinyURL's website, that gives us 36 possible links that are of 1 character length. To get number links of length 2, we would multiply the total possible of the first character by the total possible of the second character, luckily they're the same, so 36 x 36 = 1296. For each additional, we again multiply by 36. If n is the number of characters, then the formula can be represented by 36^n, also read 36 raised to the power of n. Mathematically it's represented as 36n.

So one of the things I'm wondering is, how long before the tiny url isn't so tiny anymore?

As of this writing, they have reached the 90 million (90,000,000) range. So let's see how big this gets:

1 character = 361 = 36 possible
2 characters = 362 = 1296
3 characters = 363 = 46,656
4 characters = 364 = 1,679,616 (over 1 million)
5 characters = 365 = 60,466,176
6 characters = 366 = 2,176,782,336 (over 2 billion)
7 characters = 367 = 78,364,164,096
8 characters = 368 = 2,821,109,907,456 (over 2 trillion, approaching 3 trillion)

So they just passed using 5 characters and are at 6 characters. Getting to 7 or 8 characters may take a while still. According to this Google Search wiki, in 2006 Google has indexed over 25 billion web-pages. So we're not even at the trillion mark just yet!

Plus, this isn't meant for everyone to use to index their page. But for giggles, let's see what adding a few more characters will yield us.

9 characters = 369 = 101,559,956,668,416
10 characters = 3610 = 3,656,158,440,062,976 (over 3 quadrillion!)
11 characters = 3611 = 131,621,703,842,267,136
12 characters = 3612 = 4,738,381,338,321,616,896 (over 4 quintillion!)

So each new character that is added adds a significant amount to the upper limit on number of URLs. They won't need to add too many characters at our current pace! Wow, isn't math fun?!

Thursday, September 25, 2008

Jewel Osco opening in Chicago's River West

Across the street from me, in Chicago's River West, the construction of Jewel Osco is complete. The grand opening is tomorrow: Friday September 26, 2008. I'm pretty excited about this. When I lived in Boston, I had a Starmarket (now a Shaws) a few blocks from me, and it literally served as my big refrigerator.

Now I'll have the same here in Chicago. I'll have access to fresh meat, fruits, and vegetables whenever. I probably won't need to stock up on much of anything in my actual fridge. This also probably means the end of my need to use PeaPod.

It's location is right at Desplaines and Kinzie. Also, across the parking lot from Jewel is a Chase bank. Sweet.

[UPDATE 9/27/2008] - The street lights have flag banners with West Loop on it, so maybe my area is considered more West Loop than River West. Just a thought.

Monday, September 15, 2008

A C# Code Solution for FizzBuzz

I read a slashdot article earlier today which lead me to a Coding Horror article: Why Can't Programmers.. Program?. This lead me to the FizBuzz problem, which prompted me to write my own quickie solution in C# (as a console application).

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

My Quick Solution:
for (int i = 1; i <= 100; i++)
if ((i % 3 == 0) && (i % 5 == 0))
else if (i % 3 == 0)
else if (i % 5 == 0)
I know my version is probably not optimal, nor is it the shortest way to write it. I just wanted to write it for fun, code for fun. I honestly can't remember the last time I coded something purely for fun. Now I'm wondering how I can optimize this in C# and even how to write it in other languages.

Where I formatted my C# code into HTML for Blogspot: http://formatmysourcecode.blogspot.com