Archive - Jun 24, 2007

Hot pocket is Amazing

That ad totally kills me... xD
Now I can use that Hot pocket joke anywhere... any time...
just like the geico, allstate and esurance ones.

I just save a bunch of money on my car insurance.

Accident forgiveness? Accident forgiveness my ass!

Quote, buy, print. fast and easy.

Blame the juicy goodness.

My entry to the PHP contest

Remember the PHP contest I was talking about last post?
I entered and I believe I can get at least a 3rd prize, a pen.
The code will be private until the day contest ends, but you can see my algorithm now.

At first, I thought this can be converted into a geometric question, then I just have to find the optimal solution for a geometric problem. Oh, how I wish I had read the entire book about computational geometry.

I still manage to generalize it into some geometric problem.

Each word is a point in a plane. Each word is connected with another word when there is exactly one letter difference between those 2 words. My idea is start from the starting word and trace all the links until it find the ending word.

My first idea is to create a web, map out all the lines between the points, and then, find the shortest lengh.
Map the relationship between all points
Then, my idea change. I only calculate the links for current point and move to another point. Do that recursively. Any point that's already touched will not be touched again. Like the picture below, when the link touches the ending word, the algorithm stops.
recursively find a a link touches the point.
The algorithm returns a valid result, but it is not always the shortest path.

Here is a example.
Suppose these words are valid
AAA AAB ABB AAC ABC CBC

we want to turn AAA into CBC
with my algorithm, it might end up like this
AAA->AAB->ABB->ABC->CBC
but the shortest path is
AAA->AAC->ABC->CBC
why would that happen? Because as soon as my algorithm find the path, it will end and not verify if is it the shortest. If I want to verify if it's the shortest, I will have to go check all other path until it reaches this depth.

That doesn't sound fast, so I discard my idea and turned to a new one.
A tree like algorithm. The only difference between this one and the other one, is this algorithm doesn't go recursively. The algorithm find all the point relate to the first one, then move on, and then fine ALL the point related to the points that related to the first point(confusing...) BEFORE it goes into the next level. Now, when a link connects a word with the last word, it finds the shortest path.
use a tree, grow deep one level each run

Tim from vSig.org gave me an idea. Maybe it's possible to turn words into numbers and there might be some property between those numbers can find the shortest path to the word. I'm going to think that though.

The program is still slow... mainly because of the contest entries will be judged by "Does not produce any errors/warnings/notices."

Nah, I shouldn't blame them...it's slow because my implementation of the algorithm purposely1 include a LOT rehashing of arrays. So, I can be No.2 and get the t-shirt. I already have a Zend Studio, what can I do with the 2nd one? Give to a complex dog and let the real part eat it? Then wait for it to digest in it's imaginary stomach? and while I laugh at it, some old stereotypical dōjō dude come up and talk to the dog.
"Why are you so crazy, You no hungry for Zend Studio! you hungry for hot pockets!"

  1. 1. I lied
Honey Pot that kill bots