Project Euler Solutions

Source Code

Project Euler is a massive collection of cool problems that combine math and coding. They're pretty fun to solve and I enjoy writing up my solutions and benchmarking them, especially on much larger inputs. Sometimes I also like to tackle more general problems than the ones presented. I solve the problems using Julia. The code is available on GitHub in ProjectEulerSolutions.jl along with tests and benchmarks.

Project Euler strongly discourages the sharing or publishing of any solutions beyond the first 100 problems. I disagree with this stance though. I think nobody should be sharing or publishing the numerical answers so that others can just copy paste without putting in any effort or learning anything. But I also think we should be encouraging high-quality explanations and derivations, good quality code, and explorations beyond the original problems. I do learn a lot by getting stuck and struggling through problems (some of which I keep revisiting for years) but I also learn a ton from others who share their solutions.

Benchmarks

I benchmark code using the BenchmarkTools.jl package. It produces beautiful and insightful unicode plots which I embed here. You can click on any timing to see more information about each benchmark and compare benchmarks across CPUs.

Right now I benchmark on a bunch of different AMD and Intel CPUs. For AMD we have the Ryzen Threadripper 7960X workstation, the Ryzen 9 5900X desktop, a dual EPYC 7402 server, a dual EPYC 9374F server, and an ancient Phenom II X4 970 desktop server. For Intel we have the Core Ultra 5 238V from a Microsoft Surface Pro, the Core i7-7700HQ from an older Dell XPS laptop, the Core i7-4810MQ from an older Dell Precision laptop, and the ancient Core 2 Duo E7400 desktop server.

Problems

# Problem Difficulty Time
1 Multiples of 3 or 5
0.900 ns
2 Even Fibonacci Numbers
3.766 ns
3 Largest Prime Factor
1.109 μs
4 Largest Palindrome Product
14.803 μs
5 Smallest Multiple
196.223 ns
6 Sum Square Difference
0.900 ns
7 10 001st Prime
1.609 ms
8 Largest Product in a Series
25.400 μs
9 Special Pythagorean Triplet
488.667 ns
10 Summation of Primes
972.300 μs
11 Largest Product in a Grid
2.681 μs
12 Highly Divisible Triangular Number
2.207 ms
13 Large Sum
12.409 μs
14 Longest Collatz Sequence
153.296 ms
15 Lattice Paths
1.000 ns
16 Power Digit Sum
1.460 μs
17 Number Letter Counts
152.100 μs
18 Maximum Path Sum I
3.467 μs
19 Counting Sundays
2.642 μs
20 Factorial Digit Sum
1.014 μs
21 Amicable Numbers
46.099 μs
22 Names Scores
1.283 ms
23 Non-Abundant Sums
7.571 ms
24 Lexicographic Permutations
730.519 ns
25 1000-digit Fibonacci Number
597.108 μs
26 Reciprocal Cycles
221.694 μs
27 Quadratic Primes
2.403 ms
28 Number Spiral Diagonals
1.000 ns
29 Distinct Powers
18.698 μs
30 Digit Fifth Powers
388.800 μs
31 Coin Sums
657.193 ns

Bonus problems

Problem Difficulty Time
-1
√13
1.707 ms
Heegner
801.681 μs
18i
371.943 ms
Secret
171.756 ms