Project Euler / programming problems

Here are some examples:

Problems 18: Maximum path sum I and 67: Maximum path sum II are the same puzzle, just at different scales. It is possible (but needlessly slow) to brute-force problem 18 by checking all 16384 paths. However, problem 67 has 2^99 possible routes, making it completely infeasible to take the brute-force approach. Of course, both problems have very efficient solutions that should run within a fraction of a second on any basic PC.

In a similar vein, another nice set of problems are 81: Path sum: two ways, 82: Path sum: three ways, and 83: Path sum: four ways.

Solving these five efficiently involves applying concepts like this:

1 Like

Dynamic programming was also used to calculate the number of legal 19x19 go positions:

Maybe if I solve those five Project Euler problems first I’ll have a better chance of understanding that paper next time I read it :grin:

1 Like

Those 4 you linked are much closer to what I would like, indeed.

2 Likes

The good news is that you’ve already solved two of them!

1 Like

I didn’t remember exactly how I solved them at first, but I think I got it now after thinking for some minutes. No idea yet how it will generalize to the last one though!

1 Like

I do wonder how seriously they would take their message

Please do not deprive others of going through the same process by publishing your solution outside of Project Euler. Members found to be spoiling problems beyond the first one-hundred problems will have their accounts locked.

So I guess don’t discuss the problems after #100?

2 Likes

We’re still on #6? Let’s move on in a few hours.

1 Like

If one covers a solution with a spoiler tag, can it really be said to be spoiling the experience of other solvers? :sweat_smile::smiling_imp: but idk yeah if it’s really #100 where the rule comes into effect, I guess we’ll get to that when (or if) we get to it haha

1 Like

After skimming through most of the first 100 problems, I think that #15 Lattice Paths seems like the “most mathematical” problem in the sense that the correct approach should not require any real programming. Of course, there is a naive, brute-force programming solution that could be feasible (with complexity of roughly 2^37 iterations), but the correct approach is trivial:

Solution to problem 15

Since each path must make exactly 40 steps, with 20 “rights” and 20 “downs”, the total number of possible paths can be found as “40 choose 20” (see Combination - Wikipedia). Computing that is fairly straightforward, and can even be done by just typing “40 choose 20” into Google.

On the other hand, it seems like #54 Poker hands is the “most programmatic” problem. I don’t think there are any clever mathematical shortcuts, but it is fairly straightforward, albeit a bit tedious, to program a poker hand comparison function. Instead of comparing two hands directly, one could first write a function that converts each hand to a number, where comparing the numbers corresponding to any hands is equivalent to comparing the hands. Making this trickier would be to require that the numbers produced by the function must be integers that range from 1 to the total number of hand equivalence classes. Of course, all of that is just making the problem needlessly more complex just to add more meat to it. Another thing that could be interesting is to compose a regular expression that would precisely match the lines where player 1 has the winning hand.

1 Like

Just came across this unbelievably cursed regex. Thank god I’m not working in sinosphere IT.

1 Like

I think it might be an attempt by them to dissuade people from just looking for a repository with all the solutions, making an account and submitting all the answers.

I did read some other snobby comments about how one should learn by yourself and not learning from others telling you how to do something and if you think otherwise it’s a failure of your education system etc Is it allowed to ask questions from Project Euler here? - Mathematics Meta Stack Exchange

Of course there’s no reason to think that that is the current or official stance of anything to do with project Euler.

I do get the idea, they want their little flair to mean something, “I solved this many problems myself”. It probably does mean that for a lot of people.

I’m not sure I see a reason to be so strict otherwise.

1 Like

I think it’s nice to try to be respectful of the “no sharing solutions” rule. But of course there are already solution repositories available to be found if you go looking for them. So keeping solutions behind spoiler tags and not sharing any solutions beyond 100 seems a good compromise.

(We’ll have plenty of material for this thread without going beyond the first 100, I think)

2 Likes

Erling Ellingsen has produced some interesting programming themed games:

I haven’t checked this in much detail, but here is a massive hub for programming challenges:

Okay this may be me being too lazy to look it up, but can someone tell me real quick what the issue is? I haven’t made an account on Project Euler and don’t intend to as I don’t see any point to it, I can easily work on the tasks that people share in this thread. Is there any form of competition going on? Is there anything to gain from submitting a solution?

1 Like

Easier to track your progress and verify solutions.

I haven’t made an account either though, perfectly fine to just follow along here I think.

But then I really see no issue with sharing solutions. In what way is anyone’s experience compromised by being able to look up a solution somewhere online for a problem they voluntarily try to solve?

Indeed, they can’t threaten to lock your account if you never made an account :slight_smile:

Yes I agree though, no-one’s experience is compromised unless you buy into the whole “you have to try it yourself or you’re not learning”. I think it’s fine to do the fun ones, read others and discuss others solutions. I don’t see anything inherently wrong with being given a solution or not attempting every problem solely by oneself. At the end of the day time is finite, and one shouldn’t expect everyone to reinvent every bit of mathematics or programming knowledge needed.

However

also a reasonable point of view. If they don’t want discussion/solutions past problem 100 (which is probably a compromise I’d say on their side) then one could choose to be respectful of it.

1 Like

Thanks to make me discover the online gdb.

1 Like

Np, if you’re into online c++ tools, you may also be interested in godbolt.org

1 Like

This was the best programming game I’ve ever played: http://ants.aichallenge.org/

It’s so sad that the challenges are discontinued, I spent so much time building ants, almost lost a job because boss saw me writing Java during work time :cry:

2 Likes