# Tagged Questions

Project Euler is a collection of mathematical programming problems of varying difficulty.

82 views

### Project Euler “Largest product in a grid” (#11) in Java 8

I have come up with a Java 8 solution for the following problem: In the 20×20 grid below, four numbers along a diagonal line have been marked in red (bold here). 08 02 22 97 38 15 00 40 00 75 ...
78 views

### Project Euler “Largest prime factor” (#3) in Java

The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? I wrote the following code with help of some Java 8, I'll explain the equivalent ...
126 views

### Project Euler “Even Fibonacci numbers” in Java 8

I'm looking for general advice on my code on the following problem: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 ...
90 views

### Project Euler #15 in haskell

I've solved Project Euler #15 in Haskell, but I feel like there might be a better way to express my solution that I'm not seeing. I start out defining my types: import qualified Data.Map.Strict as ...
37 views

### Project Euler #41 - pandigital prime

I've written a solution to Euler 41: We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is ...
510 views

### What is the 10001st prime number?

Project Euler problem 7 says: By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10001st prime number? I believe that my code is ...
56 views

### Optimizing Python code for Project Euler #5 (LCM of all numbers from 1 to 20)

This is my solution for the 5th problem of Project Euler, which asks for the least common multiples of the numbers from 1 to 20 (inclusive). Is there any way to improve the while loop conditional ...
122 views

### Optimizing my code for Project Euler Problem #23 (Non-abundant sums)

Project Euler Problem 23 asks: A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be ...
107 views

### Helper function to solve Project Euler question 26

Project Euler problem 26 asks us to: Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part. I wrote this function in Python to find the ...
88 views

### More efficient solution for Project Euler #2 (sum of Fibonacci numbers under 4 million)

I would like to get some feedback on my code. I am starting to program after doing a few online Python courses. Would you be able to help me by following my track of thinking and then pinpointing ...
174 views

### Project Euler #12 - highly divisible triangular number

The following is a solution to Project Euler problem number 12: which is to find the first triangular number with more than 500 divisors. The code takes far too long to complete (over 10 minutes). Is ...
133 views

### Project Euler Problem 12 - Highly Divisible Triangular Number - Python Solution Optimization

Project Euler Problem 12 asks (paraphrased): Considering triangular numbers Tn = 1 + 2 + 3 + … + n, what is the first Tn with over 500 divisors? (For example, T7 = 28 has six divisors: 1, 2, 4, ...
48 views

### Project Euler Problem 1 - Multiples of 3 and 5

I wrote this function for Project Euler Problem 1. prob001 :: (Integral a) => [a] -> [a] -> a prob001 a b = sum [x | x <- a, product ( map (x `rem`) b ) == 0] The use is like this ...
253 views

### Smallest prime factor of a large number (using BigInteger)

I'm working on a Project Euler problem and am trying to get the smallest prime factor of a BigInteger: private static BigInteger smallestPrimeFactor( BigInteger n ){ for( BigInteger i = new ...
155 views

### Performance of modular square root

Here's Project Euler problem 451: Consider the number 15. There are eight positive numbers less than 15 which are coprime to 15: 1, 2, 4, 7, 8, 11, 13, 14. The modular inverses of these ...
286 views

### Checking for circular primes - Project Euler Problem 35

I have been trying to solve Project Euler problem number 35. The problem is to find: How many circular primes are there below one million? A circular prime is a prime where all the rotations of ...
116 views

### Project Euler #82 - path sum: three ways

Project Euler problem 82 asks: Here's my solution: def main(): matrix = [ [131, 673, 234, 103, 18], [201, 96, 342, 965, 150], [630, 803, 746, 422, 111], ...
113 views

### Function to find sum of digits in the number a^b where a, b are positive integers

I was solving Project Euler problem 16, which asks to find the sum of digits of the number 2 raised to the power 1000. Using Python, it can be solved in one line of code: sum(map(int, ...
308 views

### Suggestions for improvement on Project Euler #7

Here is a solution for Project Euler Problem #7. By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10,001st prime number? I've ...
137 views

### Project Euler #12 in C++ - highly divisible triangular number

Project Euler Problem 12 asks (paraphrased): The nth triangular number Tn = 1 + 2 + … + n. T7 = 28 has 6 divisors (1, 2, 4, 7, 14, 28). What is the first Tn to have over 500 divisors? After ...
261 views

### Alternative to a large switch

Wanted to consolidate solutions to disparate problems into a single program. I am worried that there is a interface, command pattern, or dictionary solution to what will become a massive switch ...
125 views

### Largest product in a grid

Project Euler problem 11 says: In the 20×20 grid below, four numbers along a diagonal line have been marked in bold. [red in the original] 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 ...
422 views

### Summation of primes takes forever

Project Euler Problem 10 asks: "What is the sum of all prime numbers below 2 million?" How do I speed up my code? It's taking forever and I have never gotten the answer. However, I am sure that my ...
213 views

### Finding the Pythagorean triplet that sums to 1000

Project Euler problem 9 says: A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52. There ...
25 views

### Caml light and finding the prime factors

I wrote the following Caml light code to find prime factors of a number (part of an early Project Euler question). Largest prime factor The prime factors of 13195 are 5, 7, 13 and 29. ...
120 views

### Euler problem c++ / std::library usage

Euler problems (projecteuler.net) often invites to quick and dirty solutions. While hurrying through Problem 32 I found myself in want of the std:: toolkit. Not sure what it is though. The problem ...
193 views

### How Pythonic is my Project Euler #5? (LCM of [1, 2, …, 20])

I have implemented a solution to Project Euler problem 5: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive ...
371 views

### Project Euler Question #2: Sum of even Fibonacci numbers under 4 million

The question is: 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, ...
170 views

### Project Euler: Problem 13 - Large Sum

I've written some code to solve this problem: Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. My solution functions correctly, but I'm having some trouble ...
115 views

### Better way of calculating Project Euler #2 (Fibonacci sequence)

Even Fibonacci numbers 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, ...
107 views

### Does this code violate the Single Responsibility Principle?

This is my solution to Project Euler problem 2: By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. The class ...
153 views

### Roman numeral converter in Ruby

For a Project Euler problem, I made a Ruby roman numeral converter: def romanize(num) digits = { 1000 => "M", 900 => "CM", 500 => "D", 400 => "CD", 100 => "C", ...
523 views

### Project Euler Problem 7: Find 10001st prime number

I was able to complete the problem, but I would like to improve my code and make it more idiomatic. Here is the challenge description: Problem 7 - 10001st prime By listing the first six ...
217 views

### Pythagorean number decomposition

I have a pretty interesting problem that I'm trying to solve, and I am kind of stuck. I want to count the triplets of distinct combinations a, b, c, that are smaller than LIMIThave the following ...
788 views

### Project Euler #4 - Largest Palindrome Product

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 palindrome made from the product of two ...
300 views

### Project Euler problem 92 - square digit chains

Link to problem. A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before. For example, 44 -> 32 -> 13 ...
90 views

### Attempting to efficiently compute the largest prime factor

As per the help, here's what I'm looking for from this post: best practice and practical advice about (what I think is describable as) buffering the output of a function. So I'm working on the third ...
166 views

### Please review my solution to Project Euler program 1

Can someone give me suggestions on how to improve this program? The objective is to find the sum of all the multiples of 3 or 5 below 1000. #include <stdio.h> main() { int S, s3,s2,S1; ...
156 views

### Project Euler #1 - Multiples of 3 and 5

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. ...
102 views

### Code optimization for euler's problem 28

I have found the solution for euler's problem using recursion.Is it okay or is there any other way to optimize the code? static long GetSumofDiagonals(int cubeSize) { long sum = 0; ...
165 views

### Simple code that finds number of factors crashes my computer. Is there a workaround for a large number?

This is my attempt at problem 12 from Project Euler. However, my code freezes my old, linux computer when I run it. I've only got 512MB of RAM and an old Intel Core 2 Duo processor on my machine ...
181 views

### Project Euler #13 efficiency

Okay, so I finally tackled #13 from Project Euler. I'm said to announce it took me almost 2 hours to come up with this solution, after about an hour of thinking on how to do it. Here's what I did: ...
326 views

### Project Euler #14 (Longest Collatz Sequence) in Haskell

You can check the problem here: http://projecteuler.net/problem=14 My first approach in Haskell was this: import Data.Ord import Data.List computeCollatzSequenceLength n = let compute l n ...
127 views

### Truncating an integer from left to right and right to left

Project Euler problem 37 says: The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: ...
477 views

### Is there any way to make my project Euler#14 solution faster?

I'm solving project euler problems and uploading my solutions to github. Some of my solutions are just based on math and are thanks to that very fast, but #14 is way too slow, and I have no idea how ...
1k views

### Ruby multiples of 3 and 5 code challenge

I have implemented the first coding challenge on http://projecteuler.net/. I would love to get it reviewed by some expert rubyists! Thanks in advance :) # Multiples of 3 and 5 # # If we list all of ...
246 views

### Lowest Common Multiple of 1 to n in Ruby

Project Euler problem 5 asks: What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? I'm learning Ruby by going through Project Euler problems, and ...
528 views

### Project Euler 407: Is there any more optimal way to solve this idempotent equation (modulo n ring)?

Project Euler problem 407: If we calculate a2 mod 6 for 0 ≤ a ≤ 5 we get: 0, 1, 4, 3, 4, 1. The largest value of a such that a2 mod 6 = a is 4. Let's call M(n) the largest value of a < n ...