The Student Room Group

Project Euler Discussion

This thread is for TSR and f38 to discuss solutions to the problems on Project Euler, or general chit-chat about the Project itself.

The first few problems are definitely accessible to most people on the forum, and I think many will find it a fun challenge. ;yes;

To make things run a little smoother, I suggest we:
[1] Use spoilers to post solutions
[2] Post our solution when asking a question about a problem, and
[3] We only ask for assistance on general mathematical difficulties related to the problem, if we haven't yet solved it. I think working hard at a problem by yourself, and trying to solve related problems to get an insight into the unsolvable problem, is one of the most important parts of the Project, so let's make sure we respect that.

Enjoy!

(If this thread gets a little large, I'll add some help navigating it in the top post, if I have the time.)

Scroll to see replies

Reply 1
General comment: I think it would be very against the spirit of Project Euler if this turned into a "solutions thread" in the same way as the STEP threads.

So I think at most people should post "you might want to try this approach", not "the answer is 1983891" etc.
Reply 2
Out of curiosity how many problems have you guys done? and what languages do you use? I've only done 17 at the moment. I use mainly python.
Reply 3
i just finished A-level maths, can anyone recommend anything to teach me programming which is used to solve these problems?
Reply 4
Mr.A
i just finished A-level maths, can anyone recommend anything to teach me programming which is used to solve these problems?


http://docs.python.org/tut/
Reply 5
DFranklin
General comment: I think it would be very against the spirit of Project Euler if this turned into a "solutions thread" in the same way as the STEP threads.

So I think at most people should post "you might want to try this approach", not "the answer is 1983891" etc.
Definitely. I was a little nervous about creating this thread, as it has the potential to detract from the problems... (although if done properly, I think it could be useful).

steelmole
Out of curiosity how many problems have you guys done? and what languages do you use? I've only done 17 at the moment. I use mainly python.
I've done 14 in Matlab in a little under a week, but am currently redoing them in Ruby (which I prefer).
Reply 6
The one I've not been doing so well with for a while is number 11:

http://projecteuler.net/index.php?section=problems&id=11

I just don't know a good way to parse the information really.
Reply 7
steelmole
Out of curiosity how many problems have you guys done?195 or so, using C++.
Reply 8
I've done 16. Using C++ and a bit of mathematica. Really need to learn about strings and arrays.
Reply 9
Re: problem 11. I don't know Python well enough to make suggestions, but you can often make life easier using a text editor. Nothing to stop you replacing every space with a comma, for example (and then actually including the data in the source code).
Reply 10
Hadn't heard of this until I saw this thread - now I have something to keep me occupied until I can find a job! :biggrin:

18 solved so far, using Mathematica/pen+paper. There are a few that I can see ways to do in PHP, but I don't have PHP installed yet.
Reply 11
You can do problem 11 by inspection fairly easily.
Your eyes are obviously a lot sharper than mine!
Reply 13
I've only done 5 so far, but this is a great site, thanks for letting me know about it.
Reply 14
Speleo
You can do problem 11 by inspection fairly easily.


haha agreed! [only after you said that though]
Reply 15
I just did problem 12. I've never been so happy to solve a programming problem. My original way of counting factors, by trial division, took about 30 seconds to find the first one with over 300 factors and, now that I know the answer, would have taken about an hour to get the first with over 500.
Then I put some actual thought into the maths behind this and made a program that took about half a second. So there goes my "making a program 5000 times more efficient" virginity :p: .

edit: found out how to get the time taken to run. It actually takes 0.11 seconds on my AMD 1GHz laptop. Down from 0.6 ish after a small change to reuse the number of factors of n+1 (from the calculation of the number of factors of n(n+1)/2 ) in the calculation of the number of factors of (n+1)(n+2)/2.
How many will I be able to do with GCSE maths knowledge ? I know my way around C well enough to implement most things.

edit: first one :redface: looks do-able, but i'm not going to attempt it at 2:45am

edit2: wooohoo completed it! and it took me 24 minutes exact (judging by the time I edited this post last) First one is actually pretty easy as long as you know how use arrays and loops efficiently :wink:

edit3: Hmm, that 20x20 grid one looks like a complete ****. Also I would have finished the first one quicker if my compiler wasn't being a gimp + I didn't have so many syntax errors :mad:

I think it would be useful if you were also to note what you were solving them in. I'm using C
This looks very interesting indeed. My crummy office job finishes in a week and a half's time, and I've been meaning to find a way to get back in to C. I'm looking forward to it! Thank you, Kolya.
trance addict
How many will I be able to do with GCSE maths knowledge ?
The later problems are the ones that tend to be more math intensive. But a lot of problems are to do with divisibility, and although in principle you don't need more than GCSE maths and a lot of intuition, in practice it's probably unrealistic without some help.

A couple of particular things that are useful to know:

Suppose you've decomposed n as a product of primes: n=p1a1p2a2...pkakn = p_1^{a_1}p_2^{a_2}...p_k^{a_k} (where the p_i are distinct primes), then:

The number of divisors of n is (a1+1)(a2+1)...(ak+1)(a_1+1)(a_2+1)...(a_k+1) and the sum of the divisors of n is

(1+p1+p12+...+p1a1)(1+p2+p22+...+p2a2)...(1+pk+pk2+...+pkak)(1+p_1+p_1^2+...+p_1^{a_1})(1+p_2+p_2^2+...+p_2^{a_2})...(1+p_k+p_k^2+...+p_k^{a_k})

I don't know if you've noticed, but for some of the earlier problems, there are pdf files which give some hints/advice about how to approach them.
Reply 19
I guess the idea is that advanced mathematical knowledge isn't going to be much help (or, rather, isn't required), but mathematical maturity is a big plus.