Facebook Puzzle #4 Solution – Breathalyzer

After reading this part of the the puzzle’s description:

A change is defined as replacing a single letter with another letter, adding a letter in any position, or removing a letter from any position. The total score for the wall post is the minimum number of changes necessary to make all words in the post acceptable.

I was immediately reminded of the Levenshtein algorithm I read earlier in the PHP documentation.

Ironically, I didn’t come up with a solution in PHP, but Python:

[gist id=1377213]

Here are some sample benchmarks:

$ time python breathalyzer.py "hello world"
0 0 real 0m0.235s user 0m0.170s sys 0m0.020s

The program processes all the words quite fast if they are found identically written in the list.

Here is the the levenshtein algorithm in action:

$ time python breathalyzer.py "hellofdsf worldtra"
3 3 real 0m1.121s user 0m1.110s sys 0m0.007s

Just above a second… passable.

I want it to actually do some work, so let’s throw the phrase found at the puzzle’s page to the program: “tihs sententcnes iss nout varrry goud”

$ time python breathalyzer.py "tihs sententcnes iss nout varrry goud"
1 2 1 1 2 1 real 0m4.092s user 0m4.013s sys 0m0.070s

 

4 seconds! I haven’t benchmarked other solutions, so I cannot say if my implementation is one of the faster or slower ones… so leave your comments about your solution (and also some rocking benchmarks).

Emacs Dired Mode – The Basics

I did not tend to use Dired mode often, as I was not aware about its usefulness. After digging in I found out it is really easy to use and can save you some time when managing files.

So, I shared my experience by creating this video:

You can also watch it on Vimeo: http://vimeo.com/30321079

Please, do leave your comments! :-)

My first impressions of the Play! Framework

Lately I have been searching a Java web application framework to develop a Competition Manager, which you can fork here. As my fellow schoolmates only had some experience with Java it had been an indispensable requirement to use Java, and Play! (the commonly used shortcut for “Play! Framework”) really seemed to be an interesting approach.

The name, at first, made me a little skeptical about the seriousness of the project, but pretty soon I knew that the people behind Play! were exceptional professionals with goals.

I remember having tried other Java web frameworks like Struts or Spring, but I couldn’t see my own code anymore amongst dozens and dozens of XML configuration files to set up your database, and start writing your application logic. I eventually gave up on those, and gladly found that there was a Java framework written by web developers for web developers: Play!

Having a strong Django and a not-so-strong Ruby on Rails background, picking up Play! was a real charm. Play! features a built-in server which allows you to run a Play! application with just a few keystrokes after installing it.
Instead of ./manage.py runserver I just had to type play run in a terminal, and voilá, a local development server was running on port 9000.

I appreciated the excellent NetBeans integration, which allowed me to use a full-fledged IDE. The good thing about that is: it’s entirely optional.
It is just a matter of typing play netbeansify in a terminal, but those who had tendencies to other IDEs or text editors were generally well served.

Certainly the very best thing about Play! is that it is Open Source software, and straight after that the awesome community. It has a very active mailing list to which I have been subscribed for a month or so now, and the response time feels good. The people are awesome and helpful.

I don’t really want to go through all the awesome features of Play!, but you can do that yourself! Visit the website, watch the introduction video (I fell off my chair after viewing that) and start your own Play! application. Today.