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

Whenever I set about trying to learn new ProgrammingLanguages? (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 om 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 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.

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. Writting 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.