Do you have any programming "exercises" that you do in order to hone your programming skills? Anything from FizzBuzz to more complicated problems to get you thinking about real-life scenarios that you may encounter?

+16  A:

+91  A: 

A lot of great suggestions are archived in this question about teaching beginners. Particularly the bits about what projects you should try for beginners.

Here is a summary of some resources out there for programmer practice.

Another great technique for practice is to repeat problems using a different language or technology, or a different approach.

Justin Standard
Very interesting list of links!
petr k.
+3  A: 

Project Euler is fun.

Jake Pearson
+4  A: 

A series of 20+ code katas are available from the Pragmatic Programmer folks here. I particular like the Supermarket Pricing challenge ($3.00 each or 2 for $5.00) kind of stuff. As Dave says:

How do you get to be a great musician? It helps to know the theory, and to understand the mechanics of your instrument. It helps to have talent. But ultimately, greatness comes practicing; applying the theory over and over again, using feedback to get better every time.

+3  A: 

I like Programmer Puzzles on forums, this way you can see other people's clever(or not) answers


Ok enough! I mean, what's next?

"What is your favorite color?" Or maybe "What does you desktop background look like?"

Com'on people. I'm not really picking on this question, but this site has seen a slew of "fluff" questions. Are people gaming the system?

Stephen Cox
+4  A: 

some general questions that I found fun:

1) Reversing a string in place -- using no swap (this is prb a C question)

2) reverse a linked list (iteratively)

3) reverse a linked list (recursively)

4) converting strings of numbers to ints (character by character, don't cheat and use a class library)

5) splitting a string of strings into an array of strings

6) converting milliseconds into hours, minutes,seconds, and remaining milliseconds

7) join a 2D array of strings into one string

8) given a function:

float getAngle(int hours, int minutes) - return the angle between them if the hours and minutes were represented on a regular clock. Example getAngle(12, 15) would return 90.0

For extra credit get #8 to return 82.5, the actual angle between the hour and minute hands at 12:15.
+3  A: 

I hear that CipherSaber is a good programming exercise. Try implementing that in a variety of languages! (My picks, for the sake of choosing extremes in the abstraction continuum, would include Scheme and assembly language.)

I've recently taken to implementing MD5 and its related MD4 functions. The skill is not in coding it as such (although it's always nice to see that the test vectors pass):

  • How to factor out the commonalities between MD4 and MD5.
  • How to write each of the algorithms in more elegant ways, in your chosen language.
    • Most implementations of MD5 I see use 64 lines of code across the 4 rounds—this is good for speed, but is not very elegant.
    • There are more "OAOO" approaches to this, if you're using a higher-order functions.
  • Trying different languages, and exploring the abstraction mechanisms they provide to allow for such elegance.

Once you run out of languages to try, you can then try to implement SHA-1, again refactoring commonalities (SHA-1 is very similar to MD5).

After that, perhaps SHA-2? Refactoring your hash system to accommodate the SHA-2 family would be interesting…I'll say no more. :-)

Chris Jester-Young
+8  A: 

Have you tried TopCoder?

Adhip Gupta
+3  A: 

I once participated in an ACM programming contest.

To practice we went through questions from UVA online-judge. It provides a huge list of problems and allows you to submit your answers to see if they are correct. I do believe it supports C, C++ and Java submissions. The questions deal with graphing problems, number crunching, simulations, etc. Half the battle is trying to figure out what type of question it is.

Here are a few sample questions.

Another useful site is Hunting UVA Problems. It will create a list of problems that are roughly the next easiest for you. You will need to sign up to UVA online-judge before using this tool.

Tao Zhyn
+4  A: 

Jeff Bay, in the Thoughtworks Anthology has a nice set of 'rules' (object calisthenics) to follow to get your code back to a more object oriented state. It's an exercise to help change the way you think about structuring your code, and give you better OO habits when writing real-world code. The ideas is to right 1,000 lines of code while imposing the following constraints:

  1. Use only one level of indentation per method. If you need more than one level, you need to create a second method and call it from the first. This is one of the most important constraints in the exercise.

  2. Don’t use the ‘else’ keyword. Test for a condition with an if-statement and exit the routine if it’s not met. This prevents if-else chaining; and every routine does just one thing. You’re getting the idea.

  3. Wrap all primitives and strings. This directly addresses “primitive obsession.” If you want to use an integer, you first have to create a class (even an inner class) to identify it’s true role. So zip codes are an object not an integer, for example. This makes for far clearer and more testable code.

  4. Use only one dot per line. This step prevents you from reaching deeply into other objects to get at fields or methods, and thereby conceptually breaking encapsulation.

  5. Don’t abbreviate names. This constraint avoids the procedural verbosity that is created by certain forms of redundancy—if you have to type the full name of a method or variable, you’re likely to spend more time thinking about its name. And you’ll avoid having objects called Order with methods entitled shipOrder(). Instead, your code will have more calls such as Order.ship().

  6. Keep entities small. This means no more than 50 lines per class and no more than 10 classes per package. The 50 lines per class constraint is crucial. Not only does it force concision and keep classes focused, but it means most classes can fit on a single screen in any editor/IDE.

  7. Don’t use any classes with more than two instance variables. This is perhaps the hardest constraint. Bay’s point is that with more than two instance variables, there is almost certainly a reason to subgroup some variables into a separate class.

  8. Use first-class collections. In other words, any class that contains a collection should contain no other member variables. The idea is an extension of primitive obsession. If you need a class that’s a subsumes the collection, then write it that way.

  9. Don’t use setters, getters, or properties. This is a radical approach to enforcing encapsulation. It also requires implementation of dependency injection approaches and adherence to the maxim “tell, don’t ask.”

I have not downvoted, but your answer does not really pertain to the question, does it?
petr k.
It is an exercise, the idea is that for the next 1,000 lines of code you write, place these constraints on your code and see how it helps transform your thinking about OO development.
Only two instance vars? That's like lisp with only car and cdr!
Joseph Holsten
+3  A: 

For some puzzles that arent necessarily programming but you may run into at interviews check out

Adam Lerman
+4  A: 

I'm a programmer and I have several web projects. I don't need external excercises to keep me busy. If I feel that I should do something I just take one of my projects and improve it:

  • Add a Spam-Filter that works
  • Improve performance if it is not as fast as I'd like it to be
  • Optimize algorithms to best fit my user's behavior, trying to hold them longer, clicking more ads ;) ...
  • Add some more automation to anything

Really, I don't need to write another sort algorithm when there are so many interesting "real world" problems to solve.

You should try that and be creative yourselves. Maybe you are the first to develop the 100% spam protection mechanism?

+7  A: 

Pushups: Gets the heart pumpin', the mind workin', and wears out those wrists encouraging you to keep the code concise and avoid redundant comments.

Darts: Strengthens your wrists, so you don't become crippled after too many push-ups / redundant comments. Plus, you can (and should) drink while playing, allowing you to hit that elusive Ballmer Peak.

Mavis Beacon Teaches Typing: Oh... Mavis...

+2  A: 

Ed's Programming Contest Problem Archive

+3  A: 

Google code jam

+2  A: 

There are some good puzzles at ITA Software. If you do well, they might offer you a job.

+1  A: 

How about these challenges?

  1. Write a http server in plain posix
  2. Write a tool to serialize C++ objects
  3. Write a tool to autoswap stuct fields in C

Ruby Quiz has a good set of problems.

+2  A: 

Haven't seen this mentioned:

It's built on the Google App Engine. I like the part where it gives a breakdown of the submissions by language.


My standard exercise when learning a new language has been to write a Mandelbrot set app. Done it in BBC Basic, Turbo Pascal and, recently, C# among others. The TP version was the most optimised with all sorts of approximations going on, but then it was running on a 12MHz 286 or something.

I worked through some of the Python Challenge a few years back. That was fun.

A: has various ranked challenges.


It depends on what kind of skills you want to work on...

Project Euler is good for building math and problem solving skills. If you are a web developer, building your own webserver will teach you a LOT about lowlevel HTTP, which can't be a bad thing. Choosing a language and implementing it is a great way to learn all about the deeper aspects of programming. A subset of scheme is fairly easy to implement, or, you could even implement one of the wierder languages like brainfuck for befunge. Implementing tools for programming is another excellent exercise. Editor plugins are pretty easy to do, and a good start.

Jonathan Arkell

Topcoder and ProjectEuler.

Topcoder is a challenging environment where you can be prized and eventually hired... but the competitors are incredibly strong!


The Scripting Games by Microsoft are held every year. You can also look at past years' problems and solutions and exercise your Perl, VBScript and Windows Powershell skills.

Bruno Gomes

I wrote all my favorite exercises down in my Building Skills books.

+2  A: 

The book Programming Interviews Exposed contains a number of good exercises to brush up your programming skills.

Jahanzeb Farooq

Find some old software you've written, and expand it so it can send and receive email.

Jeffrey Kemp
+1  A: 

I'm rewriting Tetris game once a 1/2 year. :)

Arnis L.
+2  A: 

SPOJ - has much of the same ACM problems, but has code submission in a large number of programming languages.

Jonathan Maddison

One thing I like to do with my college friends when we want to practise optimisation, or more commonly when we want to learn a new language, is we write programs to generate primes (usually using eratosthenes sieve or some variant thereof). Whoever has generated the largest prime by the end of the night wins! While it seems a fairly simple algorithm, there are a lot of small optimisations you can make (especially in languages a bit closer to the machine, like C). If it's a scripting language we play prime number golf (writing the smallest program we can that outputs primes).

David Claridge