Live data from Hacker News

Project Euler

projecteuler.net

81–90 of 172 posts

Re: Project Euler

#81
post #52
post #40

Earlier quoted context omitted.

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.

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.

Re: Project Euler

#84

Earlier quoted context omitted.

> 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

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.

Author(s)?

Re: Project Euler

#85
post #52

Earlier quoted context omitted.

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.

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).

Re: Project Euler

#86

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.

Re: Project Euler

#87
post #70

Earlier quoted context omitted.

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).

Re: Project Euler

#88

Earlier quoted context omitted.

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!

Re: Project Euler

#89

Earlier quoted context omitted.

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.)

Re: Project Euler

#90
post #74

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 for…

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.
Post reply on HN