project-euler

Project Euler #211 - efficiency issue

I've been slowly working my way through the list of Project Euler problems, and I've come to one that I know how to solve, but it seems like I can't (given the way my solution was written). I am using Common Lisp to do this with and my script has been running for over 24 hours (well over their one minute goal). For the sake of concisen...

Project Euler problem 214- totients, does it make sense?

I have been trying to tackle this problem, but I am having difficulty understanding it: Let φ be Euler's totient function, i.e. for a natural number n, φ(n) is the number of k, 1 <= k <= n, for which gcd(k,n) = 1. By iterating φ, each positive integer generates a decreasing chain of numbers ending in 1. E.g. if we start with 5...

Project Euler #219

I'm trying to do project Euler number 219 but am failing to get a grasp of it. I'm trying to use Python which according to project Euler should be able to do it within a minute! This leads me to think that they can't possibly want me to compute each individual bitstring since that would be too slow in Python - there has to be a sub O(n) ...

How to work with very long strings in Python?

I'm tackling project euler's problem 220 (looked easy, in comparison to some of the others - thought I'd try a higher numbered one for a change!) So far I have: D = "Fa" def iterate(D,num): for i in range (0,num): D = D.replace("a","A") D = D.replace("b","B") D = D.replace("A","aRbFR") D = D.replace("B","LFaLb...

Odd question relating to project euler 72 (lisp)

I recognize that there's an obvious pattern in the output to this, I just want to know why lispbox's REPL aborts when I try to run anything > 52. Also, any suggestions on improving the code are more than welcome. ^-^ (defun count-reduced-fractions (n d sum) (setf g (gcd n d)) (if (equal 1 d) (return-from count-reduced-fractio...

C stack overflow on Project Euler Problem 27

I just have started to learn Haskell and combine reading books and tutorials with solving problems from Project Euler. I have stuck on Problem 27 because I get "C stack overflow" error using this code: euler.hs divisors n = [x | x <- [1..n `div` 2], n `mod` x == 0] ++ [n] is_prime n = divisors n == [1, n] f a b = [n^2 + a * n + b | n ...

Project Euler (P14): recursion problems

Hi I'm doing the Collatz sequence problem in project Euler (problem 14). My code works with numbers below 100000 but with numbers bigger I get stack over-flow error. Is there a way I can re-factor the code to use tail recursion, or prevent the stack overflow. The code is below: import java.util.*; public class v4 { // use a HashM...

Sum of the digits of the number 2^1000

2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 2 power of 1000 (2^1000)? Can anyone provide the solution or algorithm for this problem in java? ...

should we solve project Euler problems in SO?

I don't like the idea of solving project euler Qs as algorithm problems in stackoverflow. Project euler is for enjoyment and to discover new areas of thinking you have and not to get the problems solved. If you think reading others' code will promote your abilities of coding then wait till you solve the problem, and others' code will b...

Finding Integers With A Certain Property - Project Euler Problem 221

I've become very addicted to Project Euler recently and am trying to do this one next! I've started some analysis on it and have reduced the problem down substantially already. Here's my working: A = pqr and 1/A = 1/p + 1/q + 1/r so pqr/A = pq + pr + qr And because of the first equation: pq+pr+qr = 1 Since...

Understanding the wikipedia entry on Dragon Curves

I'm playing around with Project Euler's Problem 220, and I'm a little confused about the Wikipedia article on the topic, Dragon Curve. On the topic of calculating the direction of the nth turn without having to draw the entire curve, it says: First, express n in the form k * 2^m where k is an odd number. The direction of the nth turn...

Quickest Method to Reverse in String in C#.net

Thank you for your entries. Here is my response. I'm currently writing a quick solution for Euler Problem #4 where one must find the largest palindromic number from the product of two 3-digit numbers. To identify if a number is palindromic, you would obviously compare a reverse of the number with the original. Since C# doesn't have a ...

(ProjectEuler) Sum Combinations

From ProjectEuler.net: Prob 76: How many different ways can one hundred be written as a sum of at least two positive integers? I have no idea how to start this...any points in the right direction or help? I'm not looking for how to do it but some hints on how to do it. For example 5 can be written like: 4 + 1 3 + 2 3 + 1 + 1 2 + 2 + ...

Algorithm for ProjectEuler Problem 99

From http://projecteuler.net/index.php?section=problems&amp;id=99 Comparing two numbers written in index form like 211 and 37 is not difficult, as any calculator would confirm that 211 = 2048 37 = 2187. However, confirming that 632382518061 > 519432525806 would be much more difficult, as both numbers contain ...

Prime factor of 300 000 000 000?

I need to find out the prime factors of over 300 billion. I have a function that is adding to the list of them...very slowly! It has been running for about an hour now and i think its got a fair distance to go still. Am i doing it completly wrong or is this expected?! (Please no solutions for my code to give it away, but some subtle hi...

What are the 10 most marketable programming languages to learn (in order)?

I have been thinking about participating in Project Euler (where one solves various problems presented as a "thinking exercise". However, I thought back to my college days in computer science, and remembered a class in "comparative programming" where we were made to solve various problems in different languages to contrast and compare ...

How best to implement BCD as an exercise?

I'm a beginner (self-learning) programmer learning C++, and recently I decided to implement a binary-coded decimal (BCD) class as an exercise, and so I could handle very large numbers on Project Euler. I'd like to do it as basically as possible, starting properly from scratch. I started off using an array of ints, where every digit of t...

How do you make REALLY large boolean arrays using Java?

When I try to make a very large boolean array using Java, such as: boolean[] isPrime1 = new boolean[600851475144]; I get a possible loss of precision error? Is it too big? ...

Project Euler #5 php doubt!!!

problem euler #5 i found the solution but i don't know why this first code is faster (i put 14 in order to try to make more clear the code) the only difference is that i eliminate the for i wrote for a huge if if($num%14==0 && $num%13==0 &&$num%12==0 &&$num%11==0 &&$num%10==0 && $num%9==0 && $num%8==0 && $num%7==0 && $num%6==0 && $num%...

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 something in dict_of_stuff: pass and if something in list_of_stuff: pass My thought is the dict will be faster and more efficien...