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 i9-13900K desktop, 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.734 ns
2 Even Fibonacci Numbers
3.766 ns
3 Largest Prime Factor
1.109 μs
4 Largest Palindrome Product
11.414 μs
5 Smallest Multiple
196.223 ns
6 Sum Square Difference
0.696 ns
7 10 001st Prime
1.216 ms
8 Largest Product in a Series
15.383 μs
9 Special Pythagorean Triplet
380.886 ns
10 Summation of Primes
897.664 μs
11 Largest Product in a Grid
2.568 μs
12 Highly Divisible Triangular Number
1.644 ms
13 Large Sum
11.039 μs
14 Longest Collatz Sequence
98.606 ms
15 Lattice Paths
0.698 ns
16 Power Digit Sum
990.952 ns
17 Number Letter Counts
97.852 μs
18 Maximum Path Sum I
1.903 μs
19 Counting Sundays
2.488 μs
20 Factorial Digit Sum
1.014 μs
21 Amicable Numbers
39.931 μs
22 Names Scores
963.274 μs
23 Non-Abundant Sums
5.128 ms
24 Lexicographic Permutations
435.123 ns
25 1000-digit Fibonacci Number
537.660 μs
26 Reciprocal Cycles
221.694 μs
27 Quadratic Primes
2.007 ms
28 Number Spiral Diagonals
0.734 ns
29 Distinct Powers
11.512 μs
30 Digit Fifth Powers
253.107 μs
31 Coin Sums
657.193 ns
32 Pandigital Products
119.240 μs
33 Digit Cancelling Fractions
12.484 μs

Bonus problems

Problem Difficulty Time
-1
√13
1.336 ms
Heegner
801.681 μs
18i
371.943 ms
Secret
84.235 ms
contfrac
1.107 s