project-euler

What is your favorite Project Euler question?

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, to learn a new language, or to practice for interview questions. All this seems to imply to me that there are lots of people on SO that sol...

Changing a function from iterative to recursive?

projectEuler3(600851475143); var projectEuler3 = function (composite) { var result = 2; while(composite > 1) { if (composite % result) { result++ } else { composite = composite / result; console.log(result); } } }; ...

Why does (int)55 == 54 in C++?

So I'm learning C++. I've got my "C++ Programming Language" and "Effective C++" out and I'm running through Project Euler. Problem 1...dunzo. Problem 2...not so much. I'm working in VS2008 on a Win32 Console App. Whats the Sum of all even terms of the Fibonacci Sequence under 4 million? It wasn't working so I cut down to a test c...

Euler problem number #4

Using Python, I am trying to solve problem #4 of the Project Euler problems. Can someone please tell me what I am doing incorrectly? The problem is to Find the largest palindrome made from the product of two 3-digit numbers. Here is what I have thus far. import math def main(): for z in range(100, 1000): for y in range(100,...

Project Euler #12 in python

Hi, I'm trying to solve Euler problem #12 which is 'What is the value of the first triangle number to have over five hundred divisors?' (A triangle number is a number in the sequence of the sum of numbers i.e. 1+2+3+4+5...)I'm pretty sure that this is working code but I don't know because my computer is taking too long to calculate it. D...

Pythagorean triplets

Hi, this is a program I wrote to calculate pythagorean triplets. When I run the program it prints each set of triplets twice beacuse of the if statement. is there any way I can tell the program to only print a new set of triplets once. thanks. import math def main(): for x in range (1, 1000): for y in range (1, 1000): ...

Python program to find fibonacci series. More Pythonic way.

There is another thread to discuss Fibo series in Python. This is to tweak code into more pythonic. How to write the Fibonacci Sequence in Python I am in love with this program I wrote to solve Project Euler Q2. I am newly coding in Python and rejoice each time I do it The Pythonic way! Can you suggest a better Pythonic way to do this? ...

Project Euler Problem 27 in F#

Hi all, I've been trying to work my way through Problem 27 of Project Euler, but this one seems to be stumping me. Firstly, the code is taking far too long to run (a couple of minutes maybe, on my machine, but more importantly, it's returning the wrong answer though I really can't spot anything wrong with the algorithm after looking thr...

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 to __main__, so I thought I'd share my solution. ...

final step: adding all the primes that the reverse are also primes.

like 17, is a prime, when reversed, 71 is also a prime. We manage to arrive at this code but we cant finish it. #include <stdio.h> main() { int i = 10, j, c, sum, b, x, d, e, z, f, g; printf("\nPrime numbers from 10 to 99 are the follwing:\n"); while (i <= 99) { c=0; for (j = 1; j <= i; j++) {...

a question on for loops in python

hi, I want to calaculate pythagorean triplets(code below) and I want to calculate infinitly how do I do it without using the three for loops? Could I use a for loop in some way? thanks. import math def main(): for x in range (10000, 1000): for y in range (10000, 1000): for z in range(10000, 1000): if x*x == y*y + ...

Project Euler Problem 233

I've decided to tackle Project Euler problem 233 next but I'm having some major problems! I've done some analysis and have made some quite nice progress but I've become stuck now. Here's my working: Lemma 1: Since the circle goes through the 4 corner points there are at least 4 solutions for any n. But for each point on the circumferenc...

The lisp-way to solve Fibonnaci

I wanted to try and learn lisp, but I very quickly gave up. I figured I'd try again. I'm looking at Problem 2 on Project Euler - finding the sum of all the even Fibbonacci numbers under 4 Million. I wrote the following code which works, but is all kinds of ugly. Chief among them is the fact that it's so slow - because it's doing naiv...

Quick divisibility check in ZX81 BASIC

Since many of the Project Euler problems require you to do a divisibility check for quite a number of times, I've been trying to figure out the fastest way to perform this task in ZX81 BASIC. So far I've compared (N/D) to INT(N/D) to check, whether N is dividable by D or not. I have been thinking about doing the test in Z80 machine code...

Haskell: recursion with array arguments

Disclaimer: I'm new to Haskell and I don't remember a lot about FP from university, so there may be more than one or two errors in my code. This is also my code for Euler Problem 3. I'm trying to recursively call a function with two arrays as arguments and an array as a result. The goal: assume n is 10 for this question create a lis...

Websites like projecteuler.net

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: design tasks, architecture tasks, something like "find most elegant C++ solution"? ...

Simple recursion problem

I'm taking my first steps into recursion and dynamic programming and have a question about forming subproblems to model the recursion. Problem: How many different ways are there to flip a fair coin 5 times and not have three or more heads in a row? If some could put up some heavily commented code (Ruby preferred but not esse...

Project Euler #16 - C# 2.0

I've been wrestling with Project Euler Problem #16 in C# 2.0. The crux of the question is that you have to calculate and then iterate through each digit in a number that is 604 digits long (or there-abouts). You then add up these digits to produce the answer. This presents a problem: C# 2.0 doesn't have a built-in datatype that can ha...

Where can I find small but fun challenges? (Project Euler for the weak)

Duplicates: What are your programming exercises? Where can you find fun/educational programming challenges? Algorithm Questions Website Web site for Some Good Programming Puzzles? Sometimes I like programming a self-contained, "small" problem just for leisure and fun. Project Euler's problems in this regard are to big and need to ...

Dynamic Programming Recursion and a sprinkle of Memoization

I have this massive array of ints from 0-4 in this triangle. I am trying to learn dynamic programming with Ruby and would like some assistance in calculating the number of paths in the triangle that meet three criterion: You must start at one of the zero points in the row with 70 elements. Your path can be directly above you one row (...