league problem in python

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Wed Apr 1 13:57:46 EDT 2009


Ross:
> How should I go about starting this problem...I'm feel like this is a
> really simple problem, but I'm having writer's/coder's block. Can you
> guys help?

There are refined ways to design a program, but this sounds like a
simple and small one, so you probably don't need much formal things to
solve it.

So start writing down:
1) A precise description of what results you want
2) A precise description of what data you have to find those answers
2b) You may want to think about what kind of user interface to give to
your program, but being this program very small and being you not much
experienced yet, you may think about this later too (see point 9).

Then:
3) Invent the simplest way to feed that data to the program, for
example reading a TXT file.
4) Create artificially some toy data files, very short, and able to
reveal several of the corner cases of your problem.

Then start programming in a test-driven way. Write a tiny program that
just reads and decodes the input data of one of your inputs and shows
them.

5) Once that is done, you may write some outputs, that is the result
of each of those little inputs.
6) Try to slowly grow the code to go toward the solutions you look
for.
7) If the algorithm and processing required to find the solutions
isn't simple, then you may want to step away from the computer, take a
graphite pencil, eraser and paper and invent how to solve the problem
generally.
7b) sometimes you may also need to invent how to represent data and
solutions (and even intermediate stages) into your small program.

8) Keep creating more complex test cases and look if their solution is
correct. If it's wrong then debug your program. Soon your purpose will
be to invent stranger and stranger corner cases able to break your
program (that make your program give a wrong answer).

9) Eventually you will have to think to improve the user interface. In
bigger programs this has to be done after point (2), but for your
small program you may do it now too.

This programming strategy is not good enough if you are writing big
programs or very difficult ones, but for small easy programs it's more
than enough.

Bye,
bearophile



More information about the Python-list mailing list