Project Euler is a collection of mathematical programming problems of varying difficulty. Please be aware that the purpose of Project Euler is to encourage people to think and learn so publishing the solution or working code would render this process useless.

learn more… | top users | synonyms

401
votes
29answers
72k views

Fastest way to determine if an integer's square root is an integer

I'm looking for the fastest way to determine if a long value is a perfect square (i.e. its square root is another integer). I've done it the easy way, by using the built-in Math.sqrt() function, but ...
198
votes
9answers
50k views

How can you profile a Python script?

I've seen a quite a few questions on the Project Euler and other places asking how to time the execution of their solutions. Sometimes the given answers are somewhat kludgey - i.e., adding timing code ...
118
votes
19answers
21k views

Fastest way to list all primes below N in python

This is the best algorithm I could come up with after struggling with a couple of Project Euler's questions. def get_primes(n): numbers = set(range(n, 1, -1)) primes = [] while numbers: ...
98
votes
16answers
12k views

Websites like projecteuler.net [closed]

Sometimes I'm solving problems on projecteuler.net. Almost all problems are solvable with programs, but these tasks are more mathematical than programmatical. Maybe someone knows similar sites with: ...
48
votes
6answers
19k views

How do I break out of a loop in Scala?

How do I break out a loop (for problem 4 of Project Euler)? var largest=0 for(i<-999 to 1 by -1) { for (j<-i to 1 by -1) { val product=i*j if (largest>product) ...
46
votes
15answers
29k views

How do I check if a number is a palindrome?

Any language. Any algorithm (except making the number a string and then reversing the string). Also, I actually have to do this, and I'll be posting my solution too.
34
votes
8answers
3k views

Why is this Java code 6x faster than the identical C# code?

UPDATE 2: Changing the target from x86 to anycpu has lowered the average execution time to 84ms per run, down from 282ms. Maybe I should split this off into a second thread? UPDATE: Thanks to Femaref ...
33
votes
12answers
33k views

Find all combinations of coins when given some dollar value

I found a piece of code that I was writing for interview prep few months ago. According to the comment I had, it was trying to solve this problem: Given some dollar value in cents (e.g. 200 = 2 ...
32
votes
12answers
5k views

What is your favorite Project Euler question? [closed]

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, ...
28
votes
6answers
7k views

Project Euler - Problem 8 - Help with understanding requirement

I am working through the problems on project Euler and am not to certain if my understanding of the question is correct. Problem 8 is as follows: Find the greatest product of five consecutive ...
25
votes
7answers
22k views

Python: List vs Dict for look up table

I have about 10million values that I need to put in some type of look up table, so I was wondering which would be more efficient a list or dict? I know you can do something like this for both: if ...
23
votes
16answers
5k views

Is there a simple algorithm that can determine if X is prime, and not confuse a mere mortal programmer?

I have been trying to work my way through Project Euler, and have noticed a handful of problems ask for you to determine a prime number as part of it. 1) I know I can just divide x by 2, 3, 4, 5, ...
23
votes
5answers
5k views

How can I represent a very large integer in .NET?

Does .NET come with a class capable of representing extremely large integers, such as 100 factorial? If not, what are some good third party libraries to accomplish this?
22
votes
13answers
5k views

Project Euler #15

Last night I was trying to solve challenge #15 from Project Euler : Starting in the top left corner of a 2×2 grid, there are 6 routes (without backtracking) to the bottom right corner. ...
19
votes
5answers
3k views

No overflow exception for int in C#?

I had this weird experience with problem number 10 on Project Euler (great site by the way). The assignment was to calculate the sum of all the prime numbers below two million. I used an int for the ...

1 2 3 4 5 57
15 30 50 per page