practice programs

maney at maney at
Sat Jan 4 04:58:48 CET 2003

Raymond Hettinger <vze4rx4y at> wrote:
> From: "Tupoi" <EDB30 at>
>> any ideas for programms a begginer might try writing to help hone his
> skills
> A spell checker might be useful ;)


> Some classic exercises are:
> -- prime number generator (3,5,7,11, and 13 are prime; 9 is an anomaly)

Don't you have that backwards?  I'm quite certain that, with a less
selective sample, 9 would be seen to belong to the more common class.  :-)

> -- Markov sentence generation
> -- mail merge (table of fields inserted in to text with place holders)
> -- key word in context (search google for KWIC index)
> -- shuffle a deck and evaluate a blackjack hand
> -- use introspection and metaclasses to write a native Python compiler
> (okay, maybe not).

Aww, and you were doing so well up to that last one, too.

But [relatively] seriously...

Many years ago, when the universe was younger (and so was I), I had the
good luck to acquire a large-format book titled _Etudes for
Programmers_, written by one Charles Wetherwell of UCD.  He had a wide
range of programming exercises, from the quite simple (a gasoline usage
computation program, for example) to a set intended for teams of
students in a systems programming course (machine simulator,
link/loader, compiler for a simple algebraic language, and a TRAC
interpreter).  What they all had was a reasonably complete
description/specification, some hints about reasonable languages and
approaches, and of course citations to relevant literature (for
example, Martin Gardner's SciAm columns for the etude on implementing
Conway's game of life - and that's a wonderful project that's easily
explained and doesn't require great skill to get running).

I mention this not to suggest the book itself (published in 1978, what
do you suppose the odds are that it's two decades out of print now?),
but the approach in general.  There are various programming contests,
many of which make their program specs and, often, some or all of the
submissions, readily available, but those tend to be suited to a more
advanced student.  Perhaps someone else knows of similar content aimed
at less experienced programmers?

Oh heck.  Now that I've pulled it off its dusty shelf I may as well
give you a table of contents.  I'm omitting (mostly) the fanciful
chapter names in favor of the subtitles that are usually more
descriptive of the etude.

1)  What's It All About, Alfie?  or  How To Use This Book
2)  The Game of LIFE  or Cellular Automata and Computer Graphics
3)  Map Coloring by Exhaustive Search
4)  Printer's Devil  or  Automatic Text Formatting
5)  Tournament Design and Evaluation
6)  Business management and Computer Simulation
7)  Puzzle Construction Using Heuristics
8)  Automatic Creation of Mazes
9)  Know Thyself  or  Programs That Print Their Own Sources
10) Calculations of investment Yield
11) Ye Soule of Witte  or  Textual Redundancy and File Compression
12) Bookkeeping for Home Use
13) Simulation of a Turing Machine
14) A Computer Strategy for Kalah
15) Searching for Patterns Among the Primes
16) A Gasoline Usage Computation
17) Highway Traffic Simulation
18) Construction of a FORMAT Scanner
19) Solitaire Statistics Collection
20) A Symbolic Algebra Package
21) Perverse Inverse  or  Errors Using Floating Point
22) High-Precision Arithmetic Routines
23) Mastermind  or  Optimal Strategies for a Guessing Game
24) A Code of Dishonor  or  Mathematical Cryptanalysis

and the set of etudes for compiler courses:

25) Simulation of a Typical Large Computer
26) A Linking Loader
27) A Compiler for an Algebraic Language
28) Building a TRAC Interpreter

worked solutions for etudes #3 and #11

More information about the Python-list mailing list