Python 2.5 is fast!

I just downloaded Python 2.5 on my iBook, and I ran my stats script for the sudoku solver. Check the improvement:

{01:29}[vince@macvince: sudoku]$ time python2.4 stats.py
Easy puzzles  : 48 out of 48 (100.00%) puzzles were solved
Medium puzzles: 50 out of 50 (100.00%) puzzles were solved
Hard puzzles  : 32 out of 53 (60.38%) puzzles were solved
Evil puzzles  : 0 out of 54 (0.00%) puzzles were solved



real    3m11.721s
user    2m16.969s
sys     0m2.600s

{01:32}[vince@macvince: sudoku]$ time python2.5 stats.py
Easy puzzles  : 48 out of 48 (100.00%) puzzles were solved
Medium puzzles: 50 out of 50 (100.00%) puzzles were solved
Hard puzzles  : 32 out of 53 (60.38%) puzzles were solved
Evil puzzles  : 0 out of 54 (0.00%) puzzles were solved

real    1m17.814s
user    0m56.440s
sys     0m1.139s

{01:33}[vince@macvince: sudoku]$

That’s 2.5 times faster. People who have Python software, benchmark them on 2.4 and 2.5 and let me know if there’s a noticeable speed improvement.

Update: Sudoku Solver

I worked a few hours on my Python sudoku solver tonight. I added a new solving strategy, I reorganized the tests and made a simple statistic tool. Here are the solving stats:

Before the new solving strategy:

{23:39}[vince@vincent: python/sudoku]% python stats.py
Easy puzzles  : 48 out of 48 (100.00%) puzzles were solved
Medium puzzles: 37 out of 50 (74.00%) puzzles were solved
Hard puzzles  : 19 out of 53 (35.85%) puzzles were solved
Evil puzzles  : 0 out of 54 (0.00%) puzzles were solved

With the new solving strategy:

{23:38}[vince@vincent: python/sudoku]% python stats.py
Easy puzzles  : 48 out of 48 (100.00%) puzzles were solved
Medium puzzles: 50 out of 50 (100.00%) puzzles were solved
Hard puzzles  : 32 out of 53 (60.38%) puzzles were solved
Evil puzzles  : 0 out of 54 (0.00%) puzzles were solved

Not so bad, now all medium puzzles are solved, nearly twice as many hard puzzles can are solved and a gajillion times more evil puzzles don’t resist to my program ;)

I guess I need to add a new strategy… In the mean time, people interested in the code can ask me for a copy. Since it’s still very sloppy and not completely functional, I don’t want to put it out to the public just yet.

One good thing about web2.0

People make a lot of fun of the web2.0 buzzword these days, however, there is one thing that web2.0 got right: sign-up forms.

In the old web1.0 days, registration forms asked you a whole bunch of questions: username, password, retype password, security question, security answer, email, confirm email, name, address, city, state/province, country, postal code/zip, home phone, work phone, cell phone, fax, job, web site, MSN, AIM, ICQ, etc. The most annoying of those forms made almost all fields mandatory.

On the other hand, the common web2.0 form asks you for a username, password, retype password and email. Sometimes it asks you for your name. That’s it. They don’t need more. That makes me much more likely to subscribe to a place if registering takes less than 20 seconds.

One downside of getting a tattoo

Back in May, I got both my arms tattooed. I am still very happy with them, but I found one downside of getting them today: you cannot donate blood until 6 months after you’ve gotten your ink done.

I went this afternoon to give blood and when you get there, they give you a number and a plastified sheet explaining the conditions under which you can donate blood. For example, you musn’t have had dental treatment the same day, be on some allergy medications, etc. One of those conditions is that you may not have gotten a tattoo in the last 6 months. Well, that eliminated me. I’ll go to another clininc in a couple of months I guess.

I the mean time, those of you who think they are eligible to give blood, do it. It’s important.

Sudoku solver

A few weeks ago, I began writing a simple sudoku solver in Python. At that time, it could pretty much only solve the easiest puzzles, because the solution I used was very simple. Basically, the program looked at every empty cell and determined what numbers could be place in there by eliminating the numbers in the same line, column and box. This process was repeated until the puzzle was fully solved or that the program couldn’t find any more digits to place.

Today, I decided to open that file again and improve the program. The program now can solve more sudokus. It now also works box by box, to see where each remaining digit can be placed. Some puzzles that I couldn’t solve with the old version now work, however some puzzles still aren’t solved. I guess I’ll let you know in a few weeks what happened with that.

Oops, CPAN failed me

Yesterday, I wrote a small script to list my Amazon.ca orders in my Gmail box. The program works like this:

Ask for my username
Ask for my password
Connect to Gmail
Search for all emails from Amazon.ca where the subject begins with "Your Amazon.ca"
Get the Canada Post tracking number and the shipped items
Show all orders
Ask for an order to track
Go to the Canada Post website (with the default browser) to view where the items are

I needed three things for the script:

  • A password prompt module
  • A Gmail module that could do a search query
  • A module to send an address to my default webbrowser

I knew that Python came with getpass and webbrowser, so I just needed a Gmail modules. A Google search quickly brought me to libgmail which was easy to install (with setup.py) and did everything I needed. The script came together pretty quickly and I was satisfied with the result.

At that point, I wanted more practice with Perl, so I decided that I could just translate the script to Perl. It shouldn’t be too hard. I quickly found Term::ReadPassword for password input. Next, I went to look for a module to do what webbrowser did. I found no such module. I’m pretty sure there’s one somewhere, however I haven’t been able to find it.

I then went for a Gmail module. I found Mail::Webmail::Gmail. However, I do not think that I will be able to use it, for two reasons. (1) It doesn’t seem to support search queries and (2), the documentation doesn’t explain how to check if the login was successful. This module seems on the right track, but everything is not there yet.

So I have abandonned my idea of translating my little Python script to Perl. I guess I’ll find another task to use Perl.