Consider Yourself a Developer? You Should Solve the Project Euler Problems

By Bennett Garner

12 - 15 minutes

I’m going to make a bold claim: every developer (and aspiring developer) should solve the first 50 Project Euler problems.

The benefits of working on the Project Euler problems are too great to ignore:

They’ll expose whether you understand the basic operations of the language you’re using, and they can be solved in any programming language

You’ll learn how to write solid, standard, vanilla code. No libraries needed, so you won’t have crutches to rely on

You’ll have to think about how you store and access data in memory

You’ll need to optimize processing speed and think hard about algorithms

In this quick (<5 minute read) article, I’ll make my case for why you should solve the Project Euler problems in every programming language you want to learn.

Vince Lombardi, the legendary American football coach, would start every pre-season training with a (now famous) speech:

“Gentlemen,” he’d say to a room of professional football players, “this is a football.” He’d go on to explain the fundamentals of playing and winning at the game — running, passing, tackling, and kicking.

Lombardi’s ruthless focus on the fundamentals made him the winningest coach in the history of football, with more championships (5) than any other coach in history.

The same principles apply to software development.

Any coding challenge will test your ability to use variables, conditional statements, loops, data structures, and other common features of programming languages.

Project Euler, however, is an especially rigorous test of your understanding and command of the fundamentals. You’ll have to combine the fundamentals in different permutations in order to solve the problems.

And the fundamentals are all you’ll need. If you’ve been coding web apps, games, or other software, chances are you’ve become used to using certain libraries to accomplish specific, predictable tasks.

Project Euler takes away those libraries and purely tests your ability to reason about simple logical problems and write simple code that addresses those problems.

There’s a reason why every Computer Science undergraduate program includes a course in Algorithms & Data Structures, and why so many companies test algorithmic thinking in their hiring process.

The challenge is to know when to spend time optimizing and when to go with the simple solution.

The solution that is the most readable to other humans and intuitively makes sense is often the best.

The first few Project Euler problems will teach you this lesson. They involve simple computations with (relatively) small upper bounds. Computers are fast, and there’s no need to create work for yourself over-optimizing the first few solutions.

What a theoretical Algorithms class in university can’t teach you is what it feels like to wait for a slow algorithm to compute the answer to a problem.

A great developer has intuition about efficiency. Over time, experienced devs develop a sixth sense for sub-optimal implementations of solutions to problems. You develop that intuition from experience, and the later Project Euler problems are great teachers of what efficiency intuition feels like.

If an algorithm is going to get used often or on large inputs, spending time on optimization is worth it for the time savings down the line. In other cases though, it’s not worth the extra time to optimize a solution that will only be used on a small-scale.

Judging that optimization trade-off is the intuition that experienced devs have, and it’s a skill that Project Euler can begin to teach.

Solving even a handful of Project Euler problems will work wonders on your confidence and fluency in a given language. It’s also a great way to pick up a new language or refresh a language you used to know.

For instance, I’ve been coding in Python pretty exclusively for the past few months, and it has been a while since I wrote anything in C — a language I knew before Python.

I started implementing the first few Project Euler problems in C to refresh my skills. It has worked wonders to bring back my skills and remind me of the syntax. Similarly, I used Project Euler to learn the basics of Java, since Java’s syntax is similar to but different in key ways from C.

If you want to add something impressive to your portfolio, start a GitHub repository where you keep your solutions to the Project Euler problems.

(NB: multiple comments have mentioned that sharing your Project Euler solutions is against the competition’s rules. If you’re competing on current Project Euler challenges, join the official forum and discuss code there.

However, for the archived problems that have been solved hundreds of thousands of times, there’s a lot to gain from adding Project Euler code to your portfolio, like hundreds of other developers have before you.

Just make sure you don’t look at other people’s solutions when developing your own! That spoils the fun and means you won’t learn as much!)

When you complete a solution, check your variable and function names to make sure they’re intuitive, remove any code you don’t need, and format everything beautifully and consistently.

Next, add comments about why you made the decisions you did in your code. Learning to write good comments is a skill. A good rule of thumb: any good developer can figure out WHAT your code does, so your comments should explain WHY it does it that way.

Another great opportunity with Project Euler is to learn unit testing. Add a minimal testing framework to your projects and write tests before you write the solution. This is a great way to get started with Test Driven Development.

If you solve the first 50–100 Project Euler problems you will:

Have a solid command of programming fundamentals

Be confident and fluent in the syntax of your chosen language

Learn about algorithm optimization, and — more importantly — optimization intuition

Gain experience writing clean code with good documentation

Have an opportunity to practice test-driven development

Have something impressive to show on your GitHub and portfolio

I don’t know of any other set of problems that’s as well suited to teach and demonstrate your command of programming fundamentals. Project Euler is a must-do for any developer or aspiring developer.