Hacker News new | past | comments | ask | show | jobs | submit login
Project Euler (projecteuler.net)
792 points by vinchuco on Dec 10, 2017 | hide | past | web | favorite | 163 comments

After hearing about it for years, I decided to start working through Project Euler about two weeks ago. It really is much more about math than programming, although it's a lot of fun to take on the problems with a language that has tail call optimization because so many of the problems involve recurrence relations.

I like that the problems are constructed in a way that usually punishes you for trying to use brute force. Sometimes there's a problem that doesn't have a more elegant solution, though, as if to remind us that brute force often works remarkably well.

My only real complaint is (according to my experience) unless you happen to understand some mathematical concept/s involved in the question, it's incredibly difficult to get some insight or clue for how to go about solving it.

The forums are a fantastic resource once you already know how to solve the problem.

I agree with this for the most part, but I also really like the freedom/creativity that comes from having no idea how to solve a problem or whether there is even an optimal way of solving it. Some of my favorite solutions have come from hacking the brute force method in any way possible and coming up with interesting optimizations which I might not have found had I known the math-fact based optimal solution.

seeing a simpler/more elegant solution after you solve it will make you appreciate it more. It's also a strategy to teach math: first you fight the problem, then you learn the trick, and it will stick way longer. Unfortunately, this method is not used in high schools (not over here in BE anyway).

Totally agree. While I learnt a few interesting concepts it doesn't feel lasting to learn isolated concepts.

Personally I would like to have a little orientation system to pick a book to learn and get challenges focusing on the subject to reinforce them.

I definitely wish there was a hint system / forum where you could get pointers towards concepts you should read up on, and not the full answer.

There are forums for the problems where you can ask for general directions, so long as hints are not asked / provided.

Yeah, I "cheated" by using the forums a lot when I was going through Project Euler, too. One thing that helped me to understand different approaches was to write any solution that worked, and then benchmark my solution against all of the other submissions in my language of choice (Ruby at the time). There are so many other sites about learning to code, reviewing answers in the forums is kind of like giving yourself the lecture with content, and then you go do the real homework somewhere else. It doesn't matter how you learn it, as long as the learning sticks!

You could just look things up with Google, Wikipedia, etc. It's not like it's hard to do that for the first 100 problems.

It's hard if you don't know what you're looking for. And if you just Google "Euler problem 67" you're very likely to find a solution, which kind of ruins the point. It would be cool if project Euler came with an official multilevel hint systems with each hint getting closer and closer to giving you the actual solution .

> It's hard if you don't know what you're looking for.

Yes, that's tautologically true. You do have to put in some effort and thought.

This is true, though there are recurring themes, and the forum discussion for previous problems often helps.

I think Exercism [1] is a better not-math-inclined coding challenge collection

[1]: http://exercism.io

Plus the community is great at providing feedback on your code.

> It really is much more about math than programming

This illustrates one of my favorite things about Project Euler. How you perceive it depends totally on your background: programmers say it's mostly math, math people say it's mostly programming!

I agree with Project Euler being mostly about math. I prefer Codewars for practicing programming or learning a new language.

Euler was a mathematician after all. Now thinking about it I wonder what project Djikstra would look like, or say maybe project Stallman.

Project Stallman: Find the Github project with the most open-source license term violations (then convince them to fix it).

Project Stallman would be finding a project with open-source license and convincing them to adopt copyleft instead.

Or maybe find all projects which aren't using the GPLv3+ or are using the word Linux without prefixing GNU/ or GNU+ or GNU- or GNU* appropriately or allow running, distributing, compiling, touching or ingesting of proprietary code.

There's a Project Rosalind (named after Rosalind Franklin) which is sort of like Project Euler for bioinformatics: http://rosalind.info/about/

Project Rosalind (which has mostly been subsumed by the larger Stepik effort I believe?) is fantastic and a much more directed, progressive setup than Project Euler. I enjoyed PR greatly, and each problem led naturally to the next, whereas PE is just random problems and one might be monstrously difficult and on an utterly different topic than the next. A comprehensive mathematics project that grew in complexity the way PR does for bioinformatics would be unbelievably awesome.

I like https://rosalind.info bioinformatics problems because:

- There are problem explanations and an accompanying textbook.

- You can structure the solutions with unit tests that test for known good values.

- There's a graph of problems.

I think a Project Turing might be an interesting one, solving problems specific to computer science (maybe something like pathfinding, evolutionary algorithms, data structures, etc)

Or simply writing programs against the classic Turing machine. I wrote one out by hand 25 years ago, 3 pages I think to add two integers.

I have found that for me, a classical musicians although somewhat mathematically inclined, most problems up to about problem 100 were solvable with my maths book and some helpful pointers.

I ended up spending too much time per problem (days to weeks) and then I got a kid, so that time is being spent on better things.

My advanced algorithms professor at University has the prerequisite for doing research with him of solving Project Euler questions from 1-100. He had some sort of time table on it like 1-3 months, but also said if you solved them all in a shorter period like 1 week that you were too good to learn anything from doing research with him.

So, honestly you just doing 1-100 as a classical musician is really surprising and amazing to me. Great job!

Can you provide a link for this? I'm very interested in it.

What exactly do you want a link to? I just used my friend's old maths books from high school (he did all 7 courses available, which means about 25% of his 3 year HS studies. It includes stuff like linear algebra and linear optimization and game theory. ) and lots of time.

He went on to become a PhD in maths and just pointed me in the right direction when I couldn't figure stuff out myself.

Yes, but ProjectEuler is awesome since abstracting ideas and optimization is a great way to training and search for the best resources of your host language.

Me and some friends has been written some solutions for ProjectEuler on a lot of different languages for years. Sincerly, I have a giant feedback from them and we have awesome people writing things on the problem_solved-walled threads per question.

I love the ProjectEuler way to "lock" and "force" the user really solve the problem in your own before getting further for more deep analysis. For me, copy-paste solution don't help in anything to your skills of abstractions! For that reason, for me StackOverflow sometimes may be so evil for non-engineer/non-dev problems. Beginneers should avoid it mainly and search more deeply.

BTW, this is the repo: https://www.github.com/DestructHub/ProjectEuler

>It really is much more about math than programming

This is true to a degree. My first venture into Project Euler I was using Python, and some of the early problems involve manipulations of lists of numbers. These were almost non-problems using Python. Coming back to those same problems using C, they became a little more challenging.

One of the most important lessons I learned from PE was all the computer power in the world won't outrun a good algorithm.

I didn't do many, but outside of the first couple, I didn't notice any that had attainable answers without computation.

One example was adding one hundred 100 digit numbers and returning the first 10 digits of the sum. The forums were full of "only the first 11 digits matter", "no the first 12 digits matter because there are 100 different numbers and 10^2 is 100", etc.

No one considered:




You can try http://www.spoj.com/ if you're more interested in algorithms-oriented programming contests.

I really like to use project euler when I want to learn a new language. Exercises are sorted more or less by difficulty, at least for the first 50-100, and are completely langage agnostic (you just need to answer a question in a text input).

It's also very good to learn algorithm and maths. Some problems can even be solved without any programming. And for some, a certain amount of math is necessary to have a efficient solution to the problem.

Ps: you can find the first 50 problems in french here : https://www.lucaswillems.com/fr/articles/19/project-euler-tr...

I've used it for the same purpose, but one thing to bear in mind is the problems are incredibly focused on a small domain, so while you can pick up some bits of a language, it is nowhere near a thorough introduction.

> Some problems can even be solved without any programming.

Here's a fairly comprehensive list of those problems, but it hasn't been updated in a while, e.g., 601 is solvable with pencil and paper but it's new enough that it isn't on the list.


This is exactly what I use it for.

(They do ask not to share the solutions.)

But nice job translating them :-)

That's not me, but I found those translations very useful a few years ago! Hope it can help someone.

Similar w/me. I picked up Python that way.

For anyone looking for some less math-based coding challenges than Project Euler, then I highly recommend looking at AdventOfCode.

It's presented as an advent calendar (so a challenge per day of December) and when you unlock the first half it gives you a second challenge based in the same domain.

There's at least a couple of previous years too, if you just want to crack on and work though something.

[1] http://adventofcode.com/2015

I discovered AOC this year, I clearly recommend it over ProjectEuler if you want programming challenges that requires less math knowledge to go through.

It is also a great platform to learn a new programming language. I'm using it as an opportunity to improve my (small) knowledge of rust.

[1] https://github.com/StreakyCobra/advent-of-code-2017

Ah, memories. Back in 2010 I whinged to colleagues who were using their fancy functional languages to solve problem 1 inefficiently in 2 lines of code...

" Project Euler problem 1 :-

It helps to know the sum of (1 .. x) is 0.5 * n * (n+1).

Multiples of 3 less than 1000 are (3 .. 999) == (1 .. 333) * 3 = 0.5 * 333 * 334 * 3 = 166833

Multiples of 5 less than 1000 are (5 .. 995) == (1 .. 199) * 5 = 0.5 * 199 * 200 * 5 = 99500

We must subtract common multiples (those of 15), so (15 .. 990) = (1 .. 66) * 15 = 0.5 * 66 * 67 * 15 = -33165

166833 + 99500 - 33165 = 233168

O(1) solution FTW :P Nice looking code is good, but a smart algorithm makes a big difference. "

OK, I was a smug arsehole, but there's a point to be made y'know?

> It helps to know the sum of (1 .. x) is 0.5 * n * (n+1)

This is cool. As someone out of full time education, and who dropped maths relatively early, where’s a good place to start learning some of this stuff? By stuff I mean things related to algebra and whatever the black magic I quoted is

This would be a finite series. I think it is usually covered in calculus courses but some of the basics are discussed in earlier algebra courses. Here is a link to a brief summary on finite series. http://calculus.nipissingu.ca/tutorials/finiteseries.html

You can also start your way up from the basics in Khan's Academy.

There's a legend, Gauss came up with that while an elementary student: http://www.nctm.org/Publications/Teaching-Children-Mathemati...

I came up with it too when I was in school. I was bored and staring at some tiles and noticed that for a square block of tiles with side = n, n^2 = sum(1...n) - sum(1...n-1).

The funny thing is that, since then, I've looked at that formula several times and can't for the life of me figure out I got from the above formula to the the sum of the range formula. I guess younger me was smarter than current me.

You can arrive to the formula n^2 = sum(1..n) + sum(1..n-1) visually, separating a square into two triangles and fill them adding diagonals. Ok, that doesn't sound very informative, so let me show you an example.

Let's start with a 4x4 square:





Divide it into two triangles:





Note that one of the triangles has a side of (n-1) and other has a side of n. Now, let's see how many elements has each triangle. As I said, we can use diagonal lines. So the first diagonal has 1 element:


We then add the second diagonal, which has 2 elements (I'll use lower caps for the elements that were already present):



The third one has 3 elements:




And finally we add the last one:





It's easy to see how this procedure can be extended to any triangle and to any square (which can be divided in two triangles).

So we can see that:

1) A triangle of side n has sum(1..n) elements.

2) A square of side n can be decomposed into a triangle of side n and another one of side (n-1).

3) Now you can use some basic algebra to determine the value of sum(n): if sum(n-1) + sum(n) = n^2, and sum(n-1) + n = sum(n), then 2·sum(n) = n^2+n, therefore sum(n) = (n^2+n)/2, or if you prefer, sum(n)=n·(n+1)/2.

That is an outstanding explanation of the intuition behind that formula, and in ASCII no less! :)

That's a neat visualisation.

n^2 = sum(1..n) - sum(1..n-1) = 2sum(1..n-1) + n

=> n^2 - n = 2sum(1..n-1) => n(n-1) = 2*sum(1..n-1) => sum(1..n-1) = n(n-1)/2

And you can rewrite that as... sum(1..n) = n(n+1)/2

That's it! Makes me realize how rusty at math I've gotten. :/

Isn't sum(1...n) - sum(1...n-1) just n? (1+2+3+4+5 - (1+2+3+4) = 5). That should be a +, right?

This is an awesome visualization, by the way.

> Isn't sum(1...n) - sum(1...n-1) just n?

Yes. I meant n^2 = sum(1..n-1) + sum(1..n).

You may have a look at “The Magic of Math” [1]. I’m reading it right now and I am loving it. It contains a lot of interesting problems from arithmetics, algebra and geometry. They are well explained and show that math is about creative thinking and not about memorizing equations.

[1] https://www.amazon.com/Magic-Math-Solving-Figuring-Out/dp/04...

Honestly math is filled with cool stuff like this. In fact sometimes I wish I would have done a math minor or major at University instead of just a Computer Science major and Information Systems minor (I’m finishing my undergrad in the spring.)

Combinatorics is one of my favorite fields I always feel it has a lot of cool gems like that one and the proofs are often really intuitive. Combinatorics is all about counting things like the number of possible poker hands given a single deck or the number of ways you can seat 4 people around a table.

It was already mentioned below but, discrete math is another good one. Discrete math includes combinatorics, graph theory, set theory, logic, and number theory. All of these have really cool little tidbits of information. My Discrete Math course was my favorite class at university so far. One of the first random bits of information I learned in that class was that any number is divisible by 9 if the sum of it’s digits are divisible by 9 this was posed to us in one of our first homeworks to be proven or disproven and we were able to prove it using some algebra.

I really like the book “Concrete Mathematics”. It might be a little hard going without much maths background, but it is filled with these kinds of tricks.


Not the same person but I guess he means the one by Graham, Knuth (yeah that one) and Patashnik.

Ronald L. Graham, Donald Ervin Knuth, Oren Patashnik

Discrete mathematics is the branch of math you're after.

This looks like it has some ok examples: https://www.tutorialspoint.com/discrete_mathematics/discrete...

to see it consider this:

S = 1 + 2 + 3 + ... + n-1 + n


S = n + n-1 + n-2 + ...+ 2 + 1


2S = n+1 + n+1 + n+1 + ... + n+1 + n+1

every column sums to n+1

I always understood it just by saying "Okay, if we take the last item and the first (so n+1), and then the second to last item and second item (so n-1 + 2 = n + 1), etc, we get to the middle in n/2 times. If it was odd, we have an extra n/2. But trying it out on a few series, and it's obvious it works out each way, odd or even, to n/2 * (n + 1).

Random fact: this only works if the series is finite. Otherwise you end up with sum(1...inf) equaling -1/12.

That's the sum of all integers on the complex plane, solved using an analytical continuation of the Riemann zeta function at -1 (fwiw, by the same definition, the sum of 13, 26, 39...inf is also -1/12).

It's disingenuous to assert that is same as the sum of that infinite series without the associated caveats. By the definitions of infinite series that we all learned in calculus, that is a divergent series with no sum.

Edit: Wolfram Alpha[0] has a good graphic showing why this series converges to -1/12 (the one with the red line, drawing a peach-like shape). It also gives an intuition as to how complex numbers are influencing the results despite being omitted from the equation.

[0] http://mathworld.wolfram.com/RiemannZetaFunction.html

Not true. Infinite sums are not defined for series that don’t converge, and sum(1..n) does not converge as n => infinity.

Yes, you can play a nice trick with that sum if you ignore the fact that inf-inf is meaningless.

It depends on how you define the summation of infinite series. With the standard convergence type definitions you are correct. But it is possible to define this sum in a consistent way (e.g. Ramanujan summation or Riemann Zeta analytic continuation) as shown in Hardy's “Divergent Series”. The cost is that they have properties like rearranging the order of the terms gives a different result. Apparently this sum can come up in Quantum Field Theory when calculating vacuum force between two conducting plates.

This can be disproven by noting that the naturals are closed under addition.

The math involved in reaching this identity is akin to dividing by zero.

I do not have an formal math education, but I'm fairly sure what you quote is part of the Arithmetic Progression concept (the sum formula more specifically), so taking a look at the arithmetic branch of math might be a good idea.

Wikipedia[0], MathWords[1] and Brilliant[2] might be some good resources for you.

[0] https://en.wikipedia.org/wiki/Lists_of_mathematics_topics [1] http://www.mathwords.com/ [2] https://brilliant.org/

Here are some purely visual proofs of that fact: http://gauravkumar.tech/math/visual-proofs/sum-of-first-n-na...

Read G.H. Hardy's Introduction to Number Theory, Then possibly A Course of Pure Mathematics, also by him.

Note that the level for which you're aiming, is a level wherein such summation is much closer to triviality, than it is to `black magic` - whatever that means.

If you mean Hardy and Wright's Introduction to the Theory of Numbers, I agree it is excellent, but you can solve the great majority of the project Euler problems without going to quite that level. I particularly enjoyed Daniel Shank's Solved and Unsolved Problems in Number Theory but even that goes beyond what is necessary.

I'll check Daniel Shanks' book out. But the OP was interested in reaching a level where the proof of such summation is not `black magic` - at least that was my impression - which implies reaching a level considerably higher than the minimum... Hardy would be helpful, and is at a sufficiently higher level than future Project Euler questions he might encounter e.g. those involving continued fractions, or Diophantine equations, or even modular arithmetic etc.

Any arithmetic book on Sequence and Series will provide you with the basic toolset to derive the above.

The best point to be made from this isn't that it's more computationally efficient. It's that, compared to something like

  sum [x | x <- [1..999], (mod x 3 == 0) || (mod x 5 == 0)]
which is really just bluntly translating the question into a programming language and letting it take care of the rest, your approach involves some actual insight into the underlying math.

You can do the same in Python, which steals Haskell’s list comprehension.

By the way doesn’t the original problem say exclude multiples of 15?

IMO Python’s generators and coroutines are one of its most useful yet least appreciated features. Being able to suspend a function, resume it, get values from it, send values or exceptions to it is a highly powerful feature. You can use them to implement user-space cooperative threads, write a scheduler for that, implement message-passing concurrency, and do highly efficient multiplexed I/O in the style of asyncio.

and Python got this from....? (which language)

Well Python got it from Haskell. I thought I made it clear enough.

See https://docs.python.org/3/howto/functional.html

Well years ago, I saw a discussion that put this in the context of python's generators being inspired by what was in Icon.

I'm just now looking at Icon code for the first time, but, to me, Python's list comprehension syntax looks more similar to Haskell's than Icon's.

Right. We don't actually know whether this Haskell code is less efficient - that depends entirely on the implementation.

Compared to grandparent's method of calculation (9 multiplications, 3 additions, no comparisons, no iteration), the Haskell code is almost certainly less efficient. I can't imagine the Haskell maintainers would spend time on an optimization that is so impractically purpose-specific.

I don't think it's unreasonable to expect it. E.g. clang -O1 (https://godbolt.org/g/7qzSF9 ) is able to use the closed form for a sum on a simple C++ loop. It's not unreasonable that a language with deeper introspection could identify more closed forms. I agree that I don't think the Haskell maintainers would put this specific example in, but I wonder whether they could build it up from simpler primitives.

Haskell optimizer does not feature an arithmetic Oracle nor polynomial optimizer. It cannot even optimize Peano arithmetic much less a series.

This might be fixed some time or never. There is little push for ultimate performance and actually identifying arithmetic forms in recursive loops in the front-end is hard. (Heck it sometimes fails to tail optimize.)

I'd be interested to see how this weighs out in 5-10 years. Since there's no I/O here, I don't see why a clever compiler writer couldn't optimize this whole expression away at compile time, generating an executable just prints a constant.

What language is this?

It’s a Haskell list comprehension. You read it as:

The sum of x for x from one to 999 where x mod three is zero or x mod five is zero.

well, the bit in square brackets is a comprehension. `sum `is just ordinary function application.


Oh cool!

I've been working with a continuation-pasing style variant of Joy (https://en.wikipedia.org/wiki/Joy_programming_language https://github.com/calroc/joypy) and tried it on the Project Euler problem 1: https://github.com/calroc/joypy/blob/master/docs/3.%20Develo...

I came up with a solution that generalizes to blocks of terms, but yours is much much nicer! Cheers!

""" Between 0 and 990 inclusive there are sixty-six "blocks" of seven terms each, starting with:

    [3 5 6 9 10 12 15]
And ending with:

    [978 980 981 984 985 987 990]
If we reverse one of these two blocks and sum pairs... """

The Advent of Code 2017 includes a puzzle involving a "spiral" memory grid and I had a similar thing where I was able to figure out a simple mathematical way to solve the puzzle: https://github.com/calroc/joypy/blob/master/docs/Advent%20of...

I'm not explaining it well 'cause I'm all excited to show it.

If you read the first paragraph of the website, "Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems."

http://rosalind.info (named after Rosalind Franklin) is similar, for bioinformatics. It has the advantage over Project Euler that it provides some background and hints to the solution to the problem it presents, plus an additional graph structure of concept dependencies.

Many of the bioinformatics problems are also pure Math and CS, so it's probably of broad interest beyond just an interest in biology.

Rosalind is a great intro to the fundamentals like graph and set theories, efficient string algorithms, combinatorics, etc.

My one criticism is that the examples for some problems are trivial and don't adequately account for any of the complexity of the problem. It can feel a bit like the "Learn to Drawn an Owl" meme: Step 1) Draw an oval. Step 2) Draw the rest of the owl.

shameless plug: I loved project euler and topcoder when I in high school. In 2011, there weren't really any nice, easy-to-use, interactive websites that allowed me to solve coding/algorithms challenges online easily, so that winter break my first year of college I made coderbyte.com for people to solve challenges online. Been running it ever since, but now there are like 20 similar websites as well.

Thank you! I love coderbyte. I especially love that you can immediately go back, correct your answer and get a perfect score. There is nothing more frustrating than a competitive screening tool that masquerades as an educational tool. Emphasizing mastery over getting it right on the first try is something that I deeply appreciate.

I haven't used Coderbyte yet, but I love the idea of going back and getting credit for showing what you learned / how you improved. (I mostly use Codewars which has a similar feature though.)

I've always wished academia worked this way. Seems logical to me. Everything else we do is iterative.

My favorite part of Project Euler is the solutions forum that you can access after entering the correct answer to a problem. Having different solutions to the same problem to browse though is fantastic for learning new idioms and tricks.

Sadly, only a small portion of the solutions posted are retained, so if you're not looking for Python or C you'll probably only see a couple of different variations in your language of interest. It would be a huge deal for learning new languages if we could retain all solutions and then sort or filter by language.

I like this idea but project Euler seems to focus much more on math than programming languages so it makes sense they don’t retain all answers.

I would really like to see something similar for actual programming challenges though. Some real-world examples, maybe with predefined test cases that you then solve and optimize for CPU/Memory/Time/lines/whatever.

That would be really cool.

I guess I'm becoming an old fart. I used to like programming puzzles, challenges, things like this. But as time marches on, I realize that the real-world problems I have to solve are already so challenging and require enough critical thinking, that I'm best served just focusing on them. Between family life, doing real-world challenges for income, downtime to breathe, diverse hobbies for the spiritual good of my person, I just don't see how to fit in Euler problems and other similar endeavors. Perhaps if I was a teenager again, I'd be jumping into them with much enjoyment.

I am the same though I'm only 30. I no longer seek out puzzles but to solve interesting real world problems. The time you put into a challenging Euler puzzle, you can use React/Rails/NodeJs/Go/Rust/lang du jour to solve real world problem, helping real people.

Also as a liberal arts in programming, Euler, is fun in the sense of a well done proof is fun in math. If that is your thing you'll enjoy Euler, otherwise as in most programming you will brute force your way to a solution.

I definitely agree that puzzles/challenges for their own sake are pretty pointlesss. However, I also think (guided) puzzles/challenges are really good for learning new tools/languages. It can be hard to just sit down in front of a real world type problem with even just one new tool and know what to do with it.

The best approach is probably somewhere in the middle. Best example I've seen of this are the "workshopper" lessons on NodeSchool.

I second that. The NodeSchool [1] workshops are awesome.

[1] http://nodeschool.io

A bit of a plug, but you should check out this thing I built! Go to https://hackattic.com - It's just a test of an idea, but I wanted to show people it's possible to come up with no-nonsense, more real-world-y challenges. I've never, ever really like the typical CS challenges proposed everywhere.

Just the opposite here: I'm in my 40's and work as tech lead on a multi-discipline team. Although I manage to keep my code time up close to 50 percent, most of the really challenging stuff is systems level design/architecture where it often takes months to find out if you took the right decision. This December I have been getting up early for the AdventOfCode challenges (release at 6am CET), and have been having a great time with the self-contained challenges.

The trick with Project Euler is that they are not programming problems.

Project Euler is nice for math problems. It has little real world value for developers. The first ones can be a nice hands on introduction to problem solving.

I guess I am just the opposite. I used to love solving Euler problems and I was solving it when I was younger and had a job. It was a big escape for me from reality. When I want to solve something in my free time or steal some time when I am at work I like problem preciseness like PE. This helps me focus for hours on end unlike real world problems which I usually have to break down into smaller parts to solve.

I just turned 39 but don't have the family bit (single, no kids, etc). I generally consider lazily doing PE problems and similar things as how I do take downtime to breathe. No pressure there, and my only goal is to learn some more math, but in a stubborn manner. I am only interested in learning it if I can learn it deeply so that it truly makes sense. I got enough of 'memorize this bullshit and regurgitate it later without understanding' in school. It's only since leaving school I've been able to ENJOY mathematics.

I couldn't agree more. And yet these kind of puzzles still form the back bone of many technical interviews. Which further grinds out any enthusiasm to get me out of the job I'm in.

How far do you go into your hobbies? If you were working in those fields, maybe you'd find your current efforts produced little satisfaction compared to efforts that would help you get your work done.

For a lot of people, programming has nothing to do with their work, it is just a hobby. Project Euler and the like are great fun for kinds like that.

It's normal to lose interest in hobbies when new ones take over

The UVA online judge also has some great programming problems that I went through in college for competitive events. Not sure if the site has answers now, haven't visited in many years.


If you like PE, you might love: https://brilliant.org/discussions/thread/forest-fires/ (includes in-browser Python runner, too).

Why is project Euler being shown in hackernews now ? This isn't something new and has been there for long time. I often use the easier problems in project Euler for interviews to test candidates.

Having said that the problems in project Euler are more math based in nature.

Because someone submitted it and people found it interesting. There's no requirement to submit only "new" things.

Can I ask how do you evaluate the candidates with these problems? I mean: do they have to solve similar problems on their daily job as well? Or what is the take-away in your specific case?

Sorry for late reply. I don't give the exact same problem but use these problems for references.

For instance I often start interview with asking candidate to write a program to find a palindrome. After they answer that my follow up question is to write a program to find the longest palindrome in a given string which is a question taken from project euler.

Here I am mainly interested in their logic and approach to problem solving rather than a workable solution first time round. I don't give take-away problems neither do candidates have to do this in their daily jobs.

Are there any 200+ PE readers here ? If so, how long did it take you to reach you level and what was the most challenging problem you solved ?

I've solved 273 as of now (https://projecteuler.net/profile/NabiNaga.png). It took me a little less than 2 years to get to 250 problems, but I was spending quite a bit of time on them haha. I've learned an incredible amount of math and algorithm skills from PE. There have been lots of really challenging ones, but one that stands out is 494. That was the first "really hard" one I solved, and my first time to be in the first 50 solvers.

That is quite an achievement. Can you comment on your background ? type of education, work.

I was finishing up the second year of a computer engineering degree when I discovered Project Euler, and after a few months of solving the problems I realized I wanted to study math instead, so I switched my major to applied math. Honestly I learned more from solving PE problems than school. Now I'm working in industry on AI.

That's encouraging to hear. I'm 30 problems in so far since starting ~1.5 months ago. I starting working through the PE problems to develop my python and general programming skills since I have been primarily using R as a data scientist. I'm glad someone else has found it useful for this field.

My routine was to solve the problem, then spend time reading through the solutions in the forum to see how I could optimize my code. Many times this meant completely rewriting my solution. For a lot of problems I spent more time making my code run as fast as possible than I did solving the problem in the first place. Doing this was critical for learning algorithms and techniques that I needed to solve future problems.

164 here. I did it on and off for many many years. Personally I don't think there is much value in grinding these. It's rather a fun pastime every now and then.

That said, I believe the 100-150 easiest (i.e. solved by the most people) problems are all OK. Many of them take one hour or less. I think, it never took more than a weekend for one.

Many of the ~2006 problems can be brute forced nowadays with a low level language, which makes them quite a bit easier.

In grad school (for math) I used to procrastinate by doing Project Euler problems. I've got that bad habit under control since then (for example, logging in just now, the site told me I haven't done a problem in 56 days!), and am currently at 322 (https://projecteuler.net/profile/oantolin.png).

Don't get sucked in!

I've solved 249 of them. I don't remember when I joined, but it must have been about 10 years ago. Solving PE problems was a great way to unwind in grad school (studying math) and learn some cool math in the process. There was a period where I was knocking them out pretty frequently, but I've only had the time to solve 4 problems in the past year.

Project Euler was so much fun when I discovered it, it also helped prepare me for an unexpected interview which included similar challenges and they seemed a breeze in comparison. Had I not been challenging myself, no way would I have passed.

Solved 38 problems and forgot my password after a short pause, haven't been able to log in for years :(

Back in the day I solved the first ~100 problems in order. It was a great practice to sharpen your programming logic and I learned a ton of math. The problems became harder. But I haven't done any in many years. Do you think the newer problems are very very hard ? I have to admire the dedication of those who have kept on it.

It is possible to sort them by difficulty. Some of the newer problems are easier than some of the first 100 problems, appearantly.

To ask people who solved many of these questions:

Once you find "the" trick, is there still a lot of computation involved? Do you still write loops? How many orders of magnitude times do those loops run? How do you know when your code is too computationally intensive and you haven't found "the" trick yet?

If you write it and it doesn't finish in a minute, I'm sure it's not that trick.

Somewhere in the instructions it says that your solution should run in less than a minute on ordinary computer hardware. Sometimes it's just as interesting to make your brute force solution more performant as it is to find 'the trick.'

It really depends on your goals but for coding interviews I've found leetcode.com to be the best by far.

Did any of you interview and having a good Project Euler account was positively recognized?

This never happened to me. No one seems to know the site. They seem to be mostly interested in Top Coder and similar platforms.

Happened to me once. I have my PE score on my resume and during the first technical interview on the phone the interviewer commented positively on it. I moved on to onsite interviews after that, but I'm unsure how much my PE score helped in that regard.

I had an interview screening question once that was very similar to Project Euler type questions. I solved it correctly, and quickly, and that probably helped get me in the door.

I've solved #555 and #561, which were a lot of fun. Any other good recommendations? Some of the questions in that area look pretty intimidating, but those two were surprisingly approachable.

#601 is pretty easy. Also, #512 and #521 if you have some background in prime number theory.

#208 is what got me started

DoSelect has some good programming problems including API based questions and competitive coding questions.


The best tool for solving these problems is a whiteboard; writing code should be seen as a last resort, and brute-force solutions should be shunned, as they provide no insight.

Some friends and I used to hold a hybrid drinking/Project Euler contest. You would have hated our solutions. I remember winning on the back of nine nested for-loops and, on a separate occasion, doing a primality check using a literal array containing the first 80,000 primes.

That's what happens when time-to-solution is what you optimize for. I'm sure it's familiar to startup programmers :).

Wow, that sounds like an awesome party =)

I agree that solving them with pen and paper is bad ass.

But many problems cannot be solved using brute force. They will give you one problem that can be solved using brute force, then in a later problem they increase some n to the point where it cannot be solved using brute force. So it forces you to find a better solution.

Well in TDD you tend to try to do that :)

good luck with that

His point is correct. There are usually efficient and inefficient ways to attack each problem. It's better to solve the math problem first, before the coding problem.

Only when the scale truly matters is the most efficient algorithm the best choice though.

For a lot of problems, especially in early stage startups, the brute force solution is more than sufficient and avoids premature optimization. Having perfect algorithms for everything comes with an opportunity cost in startup land that isn't aligned with whether or not your business succeeds most of the time.

(This really only applies when the efficient implementation doesn't already exist in the standard library or a package.)

Some problems simply will never return the result if you brute force it. I've run a brute-force solver and written the elegant approach while I waited for a result that'd never come.

Most of the elegant solutions do exist in libraries out there, but the point is to pass down the underlying knowledge.

I don't think it's really fair to liken something like mathematics to the startup world, something that has all sorts of nondeterministic factors involved.

Some of the answers are explicitly formulated in such a way that your brute force mechanism will not work even though in a practical setting that brute force answer would be more than accurate enough for use.

So project Euler does not always steer you simply to a correct answer, they also want you to achieve that answer in a particular way.

The context here is Project Euler though. (Math problems)

Project Euler gives me nostalgia for some unknown reasons. During my BE, I used to get lost in the problem space. Now, it's different.

Project Euler is a good place for teenagers to start learning programming, better than the routes of game or website design.

bright-shadows.net [1] was a Project-Eulerish site around security related challenges. I think it's pretty dead now but I remember lots of interesting problems that motivated to learn new stuff.


Shameless Plug

There are literally thousands of problems here www.mathalon.us

Plug for www.mathalon.us very similar and lot of questions

In a way, Project Euler was years ahead of its time. It's a set of problems for aspiring machine learning and data science specialists. They should really update their description.

a26a zbuild 1b c ratty

i would love to see problems that have bounties on them and you get a sciencecoin or something for solving it.


From the Project Euler website:

I learned so much solving problem XXX so is it okay to publish my solution elsewhere?

It appears that you have answered your own question. There is nothing quite like that "Aha!" moment when you finally beat a problem which you have been working on for some time. It is often through the best of intentions in wishing to share our insights so that others can enjoy that moment too. Sadly, however, that will not be the case for your readers. Real learning is an active process and seeing how it is done is a long way from experiencing that epiphany of discovery. Please do not deny others what you have so richly valued yourself.

Yeah why? Why would you publish strictly an answer key, with no solutions or discussion when the site itself, a well known and cherished part of the software development community has explicitly requested that you don't?

Why are you publishing the answers when the creators of Euler explicitly asked you not to?

Since when is HN voting used for enforcement of what Project Euler wants?

Since I got a vote.

Applications are open for YC Summer 2019

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact