project-euler

Project Euler 298 - there must be a correct answer? (only pastebinned code)

Project Euler has a paging file problem (though it's disguised in other words). I tested my code(pastebinned so as not to spoil it for anyone) against the sample data and got the same memory contents+score as the problem. However, there is nowhere near a consistent grouping of scores. It asks for the expected difference in scores after ...

Project Euler #10, java

So, I'm attempting to solve Project Euler Problem 10 in Java, and I'm getting not the right answer. Here's my code: public class Problem10 { public static void main(String[] args) { long sum =0; for(int i =3;i<2000000;i+=2) { if(isPrime(i)) { sum+=i; } } System.out.println(sum); } ...

Question about Project Euler Problem #59

I have been trying to solve this question for a while, and I am having trouble because some of it seems somewhat more ambiguous than previous problems. As background, the problem says that the given text file is encrypted text with the ASCII saved as numbers. The encryption method is to XOR 3 lowercase letters cyclically with the plainte...

Puzzled over palindromic product problem

Hi, I've been learning Ruby, so I thought I'd try my hand at some of the project Euler puzzles. Embarrassingly, I only made it to problem 4... Problem 4 goes as follows: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest p...

Python - Sum of numbers

I am trying to sum all the numbers up to a range, with all the numbers up to the same range. I am using python: limit = 10 sums = [] for x in range(1,limit+1): for y in range(1,limit+1): sums.append(x+y) This works just fine, however, because of the nested loops, if the limit is too big it will take a lot of time to compu...

Lisp style question: memoization (caution: contains the solution for project euler #14)

Hello, I am just trying to learn some Lisp, so I am going through project euler problems. I found problem no. 14 interesting (so if you are planning to solve this problems stop reading now, because I pasted my solution at the bottom). With my algorithm it was so slow, but after using memoization (I copied the function from Paul Graham's...

Binary numbers with the same quantity of 0s and 1s

When I was solving Euler project problem #15 I realized that it can be solved with the # of combinations of ways of the route from start to end. The route generated always has the same size of right or down choices (or 0s and 1s) and the right routes always have the same qty of 0s and 1s. So qty of numbers with the same qty of 0s and 1s ...

Project Euler problem 67 not quite correct...

I have the following Python code, which I wrote for the sister problem 18. It works perfectly for problem 18, but is slightly out for problem 67. I can't for the life of me figure out why. triangle = [ [59], [73, 41], [52, 40, 9], [26, 53, 6, 34], [10, 51, 87, 86, 81], [61, 95, 66, 57, 25, 68], ... ] def max_adjacent(row,col): ret...

Ruby program almost all time is from sys time?

Hi, I am working on a Project Euler question. But it take quite a long time (30 Minutes last time) for my PC to get the answer. When doing time command on my Linux PC. I get result as this: real 1m42.417s user 0m18.204s sys 1m24.026s This is a time based on much smaller dataset than the question asked. So my question is, is...

Runtime Crash For A Very Basic Python Program

I work on a windows XP PC with a Python 2.6 install and I was trying to solve a Project Euler problem, but whenever I execute the code the interpreter hangs. I've debugged it through PyScripter, IDLE and MonkeyStudio, but it still doesn't work even for trivial values like 15. I simply don't understand why. Can you please help me out? H...

Is this Project Euler #5 solution more efficient than a known one?

Here's my solution to Project Euler problem #5: #include <stdio.h> #include <stdint.h> #define N 20 int main( int argc, char* argv[] ) { uint64_t r = 1; uint64_t i, j; for( i = 2; i <= N; ++i ) if( (j = r%i) ) r *= ( (i%j) ? i : (i/j) ); printf( "\n%llu\n", r ); return 0; } It is of O(n) efficiency. ...

I have a Python list of the prime factors of a number. How do I (pythonically) find all the factors?

I'm working on a Project Euler problem which requires factorization of an integer. I can come up with a list of all of the primes that are the factor of a given number. The Fundamental Theorem of Arithmetic implies that I can use this list to derive every factor of the number. My current plan is to take each number in the list of base p...

How to improve the performance of this Haskell program?

I'm working through the problems in Project Euler as a way of learning Haskell, and I find that my programs are a lot slower than a comparable C version, even when compiled. What can I do to speed up my Haskell programs? For example, my brute-force solution to Problem 14 is: import Data.Int import Data.Ord import Data.List searchTo = ...

Power of 2, trying to reach 2^1000, Segmentation fault.

I am building a program which will multiply by 2, and reach long accurate numbers. Here I build a program in which each digit is stored in a different variable. When I compile the program, and I type 2^63, It gives me the correct answer. But when I type 2^64, I get a “Segmentation fault”. What is it? What can I do? #include <stdio.h>...

Problem 9 (Project Euler) with Java - is it perfect program?

I am new to Java and even OOP, but I tried to write program for this task: A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a^(2) + b^(2) = c^(2) For example, 3^(2) + 4^(2) = 9 + 16 = 25 = 5^(2). There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. I want that y...

My Qustion 1: It's an assignmnt

The number 3797 has an interesting property...Being prime itself , it is possible to continuously remove digits from left to right,but remain prime at each stage....:3797,797,97,7....similarly we can work from right to left:3797,379,37,3. Find the of only 11 primes that are both truncatable from left to right....and right to left. Pls tr...

Why is my algorithm for Project Euler Problem 12 so slow?

Hi, I have created solution for PE P12 in Scala but is very very slow. Can somebody can tell me why? How to optimize this? calculateDevisors() - naive approach and calculateNumberOfDivisors() - divisor function has the same speed :/ import annotation.tailrec def isPrime(number: Int): Boolean = { if (number < 2 || (number != 2 && num...

Code works extremely slowly and does not print output

I'm working on Project Euler problem #2: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... Find the sum of all the even-valued terms in the sequence which do not exceed four million. My ...

Stackoverflow error in this recursion

What's wrong with this recursion in Java? public class findPyt { public static int sum = 0; public static void main(String[] args) { findP(3, 4, 5); } public static void findP(int a, int b, int c) { sum = a+b+c; if (sum == 1000) { System.out.println("The Triplets are:...

Fastest prime test for small-ish numbers

I'm playing through project Euler in my spare time, and it's come to the point where I need to do some refactoring. I've implemented Miller-Rabin, as well as a few sieves. I've heard before that sieves are actually faster for small-ish numbers, as in under a few million. Does anybody have any information on this? Google wasn't very helpf...