Penguin
Note: You are viewing an old revision of this page. View the current version.

Whenever I set about trying to learn a new ProgrammingLanguage (very frequently) I often find myself stuck without simple exercises to do. I hope that if people add neat simple programming exercises here, it could be quite useful.

Greatest Common Divisor

The oldest known nontrivial algorithm is Euclid's Algorithm for computing the greatest common divisor (gcd) of any two positive integers (300 B.C.). The idea of the algorithm is based on the observation that, gcd(a,b)=gcd(b,remainder(a,b)), and that gcd(x,0)=x.

Seems trivial? I agree, but it's a start.

Compound Interest Calculator

http://moneyethics.com/Articles/compound.html

Hello World

This is usually a very trivial program, but a good first exercise when learning how to use a new programming environment (see HelloWorld).

99 Bottles of Beer

Make your computer sing the 99 Bottles of Beer on the Wall song.

Very popular: http://99-bottles-of-beer.ls-la.net/

TPK

The TPK Algorithm is DonaldKnuths HelloWorld. It doesn't actually do anything but it has an array, loop, conditional and function in it to make it exciting.

Ward Numbers

See Wiki:WardNumberInManyProgrammingLanguages

A graph theory problem that looks convoluted enough to get very high-level languages sweating.

A ProgrammingLanguage

Writing/implementing ProgrammingLanguage will teach you that all the bugs, wrinkles and flaws in the languages you've ever used are there for a reason: ProgrammingLanguage design is challenging and ProgrammingLanguage implmentation is very hard and painstaking work. Plus, if you ever get it to the point where you have users, then they'll never comment on the 9/10s of the code that replicates what all the other languages do except to whine that it's not perfect.

Esoteric Interpreters

Wiki:EsotericProgrammingLanguages, like Brainf*ck, usually have small instruction sets and simple grammars. Interpreters for these languages aren't big programs but need a fair sample of a programming language's features to implement.

An example: befunge.a68 A Befunge interpreter in Algol 68 (the esoteric in the obscure).

A self compilation system

GCC is written in C. The Oberon system is written in Oberon. Writing a Compiler in the language it compiles is a great way to make sure you understand the language. The hard bit, of course, is the BootStrap.