88Pro Thinking

cat /senthoor/mind | grep thought > blog

Thursday, January 05, 2006

Python Contest

Participating in pycontest was very interesting. I was no expert in Python but wanted to give it a try. Took couple of my python books, went to Barista and came up with the first prototype. When I tried to submit my first cut, ooops, the site refused to accept anything more than 345 bytes. after few revisions I was able to reduce it up to 295 bytes.

At that time 120 bytes was the lowest count and everyone who had more byte size knew they are not winning the competition and started discussing their solutions on blogs. Lot of techniques were put out to reduce the byte count. One such blog is gumuz online. As you can see the final winner of the contest André (117 bytes), who is also the first commenter in that started with a 171 byte version and then moved on to 119 byte version refining the code using some of the techniques discussed on that blog.

I learned a lot, I knew I could use lambda/map/list comprehension and come up with a short code, but the main problem I was having is how to encode the pattern in less than 140 bytes. I knew, even if I was expert in python, until I crack the encoding problem I am not going to be able reach 120. One way it was done was to encode the pattern in something other than base 0, for example base 64.

One thing I am really happy about is, I used a (silly)technique in my code to reduce the byte count. If the google team has used the same technique they would have also reached 19 byte count. It is to have everything in one line, separated by semicolon which reduces one byte from your total, since when you put in two lines there is a \n and a \r involved which accounts for 2 bytes.

You might not win anything in these contests but by participating you learn a lot.

Other Links

Journey to 117

posted by 88Pro / Thursday, January 05, 2006

This page is powered by Blogger. Isn't yours?

doteasy.com - free web hosting. Free hosting with no banners.