Monthly Archives: November 2011

The Sieve of Eratosthenes (Implemented in C)

If you like programming puzzles and challenges you’ll notice that many of them involve prime numbers in one way or another. As such it becomes handy to have a large table of prime numbers ready to go. One of the easiest yet efficient methods to generate a list of prime numbers if the Sieve of […]

Solution to Project Euler 1

My plan is to post a solution to all the ProjectEuler.net problems I have managed to solve. But don’t worry I won’t spoil your fun throwing out the answer right away. Instead I’ll describe my reasoning and paste my code, so that you can work on your own solution. Problem 1 has the following description: […]

Online Algorithm Directories and Repositories

Whenever I trying to understand some new algorithm to solve a particular problem my first call is Cormen’s Introduction to Algorithms. However, not all problems are covered there, and not all covered ones come with actual implementations (or at least with pseudo-code) so that you can get a hint even on the details. To solve […]

Poker Hand Evaluator in C

Problem 54 on ProjectEuler.net was an interesting one. Instead of the usual math puzzle it had a more practical topic: Poker. You basically need to evaluate the hands of two players for 1000 rounds, and then determine how many rounds rounds player one wins. The hand evaluator I built was quite naive and used a […]

Interpreting Complex C Declarations

Once you start mixing pointers to functions in your C declarations you’ll notice that things can get complex. For example, what does the following declaration represent: float * (* (*ptr)(int))(double **,char c) What about this one: unsigned **( * (*ptr) [5] ) (char const *,int *) One tool you can use to help you with […]

The Art of Swapping Variables

Swapping variables is probably one of the most common operations inside computer programs. But did you know that there are many ways to perform a swamp? Below I’ll talk about some of them. Using an Extra Variable The easiest way is to use an extra temporary variable (usually called “temp”) where you store the value […]