euglug.org

[Think] contest? –in python!

작성자

카테고리:



HorstWed Dec 4 20:19:55 PST 2002

On Tue, 5 Nov 2002, Rob Hudson wrote:

> I've been following these, but not actively participating.  There are some
> interesting challenges, though.  Anyone want to play along in Python?
> 
> PHP Coding Contest:
> http://codewalkers.com/php-contest.php
> 
> The current one is the 'Stacking Discs' contest.

Rob, 
Did you (or anyone else) continue working on the disk stacker problem?
 Well, I got hooked until I found that the time constrain (30sec run
time) prohibits me from further optimizing the search algorithm.

 They finally posted the winning results together with the input data
against which the contestant's code is ranked. So I plugged those input
data into my python version and was pleasantly surprised: my algorithm
beats the winning code at the total score, as well as in 9 out of 10
cases. So I couldn't resist to post my solution (incl. reference to code
and output data) to their forum:

http://codewalkers.com/forum/index.php?action=displaythread&forum=php-contest&id=340&realm=default
 or if thread above has moved:
http://codewalkers.com/forum/index.php?forum=php-contest&realm=default

Coming back to learning python, I would say that those run time restricted
contests are not really ideal for learning the language or good coding
style: 
a) The crux in winning that contest was finding the best algorithm, no
matter how elegant or ugly the code looks like.
b) Because of the time constrains you may be inclined to take shortcuts,
and tailor your code to that specific problem (with little interest in
reusability).

As a matter of fact, I ended up coding procedural and didn't even bother
to wrap a class around it at the end. Reasons:
1) Speed: I assumed that pulling data out of a global 4-dimensional list
is faster than going through a series of access functions. 
2) Readability. Most of the code would turn into class methods, with all
the relevant data hidden as private members; e.g. instead of accessing
'maxDisk' you would have to look at 'self.__maxDisk' all the time (or
alias it).

If it wouldn't be for the 9/10 'victory' I wouldn't have made it public,
so here you go. But then, 9/10 also means the glass is only 90% full --so,
any takers ? ........................... Horst

_______________________________________________
Think mailing list
Think at zoneverte.org
http://mail.zoneverte.org/cgi-bin/listinfo/think