views:

2469

answers:

11

I was searching around for questions related to Project Euler on Stack Overflow, and it seems that there were plenty of people asking about it, and even more people recommending it, whether for fun, to learn a new language, or to practice for interview questions. All this seems to imply to me that there are lots of people on SO that solve Project Euler problems now and then. I just started, so I was wondering:

What was your favorite Project Euler question? Why? Did you think of a clever trick, or did you learn some new math, or did you discover a feature of a new programming language?

(If possible, please include the actual question in your answer.)

+2  A: 

I've only gotten up to Problem 43. Most of them have been pretty straightforward.

This one was fun, especially seeing people's more and more efficient solutions on the forums once I completed it.

Claudiu
+2  A: 

Problem 229. Before that I was not aware just how fast and powerful sieving is.

starblue
+15  A: 
Ólafur Waage
+1 Amazing pronblem. I solved Problem 18. I thought that my solution is brute forcing the answer. But when I tried Problem 67, my algorithm worked perfectly :)
Canavar
I've written a function a to solve for the given triangle but there is some confusion on what the question means by "Starting at the top of the triangle below and moving to adjacent numbers on the row below.." My function does this but I can never seem to get the correct answer.
Dalin Seivewright
I like how it's the exact same problem as #18, only with a larger data set. Show's how naive algorithms can sometimes break down with large data sets. I am happy to say that I was able to solve #67 without a whole lot of trouble.
Kibbee
I don't understand the difficulty of this problem. I solved it in 20 lines of PHP. The answer returns almost as soon as I hit the enter key. The real trick to the question is not overengineering it. You are not asked to reproduce the route you took, so don't save that info.
jmucchiello
@joe_mucchiello: It's actually easy to save the route you took without making the algorithm slower.
A. Rex
A. Rex, by "difficulty" joe probably means lines of code, not algo complexity. But honestly, I aree with you both - this problem is fun to code, but has no challenge.
DK
Aye, its not that hard, but the fun in this question is how they tease you with the amount of time it takes to brute force it. My favorite since it shows how well a good algorithm works.
Ólafur Waage
@Ólafur Waage: The bounty period expired. You should have gotten some bounty points for your answer. The yellow checkmark indicates you got 50, although I think it should have been 100.
A. Rex
I got 50 rep, just wondering how it works.
Ólafur Waage
This problem can be solved nicely with a graph and shortest-path. Just set the cost to "inverted" value (100-cost), find the shortest path, and the "re-invert" the costs.
Svein Bringsli
+8  A: 
Canavar
Ah, combinatorics...
TraumaPony
yes it can be done using calc:)
dfens
yes solved the first one too, it's a nice problem
Nils
+8  A: 

My least favorite question is #54 about the poker hands, it's not mathematical and doesn't seem to lead to an elegant solution.

Motti
Yeah, that one was more about data processing than anything else. You do at least get a Poker hand evaluator out of it, though.
Bill the Lizard
there were not even interesting tie breaking situations it seemed to me. It was as if they did not spend time making specific cases for testing. But, I suspect if there were about 10 of those cases then you could guess the specific answer based on numbers close to incorrect (but close) solution.
Tim
Aside from data processing, the hand evaluator didn't have to be accurate to get the right answer... I'll leave out the details but several situations can be ignored.
Austin Salonen
+2  A: 

Problem 58 taught me once again that optimization should be done only after profiling. Naive method to check primes was working couple of times faster than finding them with sieve before hand and then check for them with the hash. Makes you think sometimes.

Problem 230 showed me once again how much C++ faster than Ruby. Makes you wonder every time.

BTW as much as I love solving those problems, it takes intensive amount of time, so much, that not only my side projects got abandoned but it really affects efficiency at my day-to-day job. So I just make myself stop after couple of weeks of solving them.

vava
+3  A: 

Two that I had a lot of fun doing were Question 59 which was about cracking a piece of (weakly) encrypted text and Question 96 which was a sudoku solver.

I have to admit, though, that they're questions that probably appeal more to programmers with weaker math backgrounds (such as myself).

Dana
+1  A: 

I liked the one with where you had to cross every path through a matrix only once. It's how I learned the importance of caching!

apphacker
Do you mean Problem 15?
A. Rex
+13  A: 

My favorite is number 227, because there is a funny story about it. In our university network, there is one quad-core computer that everyone can use for high-performance computations. My friend was complaining that it had been kind of laggy lately. We saw that there was a process named "prob-227-e" running, which had used already three weeks(!) of CPU time.

I immediately guessed that it must be Project Euler problem. I took a look at the problem, and within 20 minutes I had written a ten-line Octave-script that just solves a 100x100-system of equations and runs in a blink of an eye (and produces the correct answer). I then emailed that to the user, and the next day, he answered to thank me and explain what he had been doing, which was some kind of brute-force simulation.

Elegance always pays off : )


The question

The players sit around a table; the game begins with two opposite players having one die each. On each turn, the two players with a die roll it. If a player rolls a 1, he passes the die to his neighbour on the left; if he rolls a 6, he passes the die to his neighbour on the right; otherwise, he keeps the die for the next turn. The game ends when one player has both dice after they have been rolled and passed, that player has then lost.

In a game with 100 players, what is the expected number of turns the game lasts?

mattiast
+2  A: 

One of my faves is Problem 164.

It says:

How many 20 digit numbers n (without any leading zero) exist such that no three consecutive digits of n have a sum greater than 9?

You can't solve it by brute force (in a reasonable time, at least), but you can using concepts as Dynamic Programming and Memoization.

friol
+4  A: 

I really like the problem about the Heighway Dragon. I made a simple program, which made the moves, but then I realized how many steps does it have to make (using two recursive functions)... I haven't solved it yet, well I think, there must be some simplier way to solve it.

kwako
Ah, yes. You can solve it with a sort of dynamic programming, but it gets hairy. The thing you should compute is what kind of translation does "a" or "b" make when the rewrite rule is applied n times. Have fun!
mattiast