dairydemon.net

a badge showing filifa's up-to-date Project Euler statistics (solved 168 as of 2025-07-27)

Eulerbooks

This is a collection of Jupyter notebooks containing solutions and discussions for the first 100 Project Euler problems using SageMath.

My main goal with these notebooks is not simply to provide working code for solving the problems. Frequently, solutions to these problems are short, but they’re not always easy to follow without understanding some important mathematical principles. Therefore, my aim is to provide insight into the underlying algorithms and mathematical concepts that make an efficient solution possible. I personally find that these topics are frequently even more interesting than the problems themselves, which I see as mainly existing to provide situations to apply the concepts after learning about them. In short, it’s more about the journey, not the destination, so these notebooks mainly exist to discuss the former.

Approach

Frequently, either Python or SageMath provide functions and libraries that make it trivially easy to write a solution. I don’t have a problem with presenting solutions that use these, since for practical purposes, it’s better to use what’s already available than to reinvent the wheel. It also tends to lead to code that is easy to read and understand, which is the best kind of code.

However, when a function already exists that does the heavy lifting, I also tend to provide my own basic implementation and an explanation of why it works. This is especially true if a solution or algorithm is based off of an important mathematical concept that is not especially intuitive.

When not especially tedious, I like writing up solutions that do not require programming at all, since these approaches often require interesting mathematical techniques.

Another thing to note is that I don’t prioritize a solution’s performance above all. When a solution is fast enough (using Project Euler’s own “one-minute rule” as a rule of thumb), I instead usually focus on making the code easy to read. You can basically always optimize, but there are frequently diminishing returns, and it tends to negatively impact readability. Once a solution is fast enough to solve the problem at hand, I only consider optimizing further if the concepts are reusable.

Solutions

Solutions are provided as non-interactive HTML renderings that you can view directly in your browser. Alternatively, you can download the Jupyter notebooks to play with them yourself. I've also marked some of my favorite problems.

Project Euler solutions
# HTML Notebook Favorite?
1 View Download
2 View Download
3 View Download Yes
4 View Download
5 View Download
6 View Download
7 View Download Yes
8 View Download
9 View Download
10 View Download
11 View Download
12 View Download
13 View Download
14 View Download
15 View Download
16 View Download
17 View Download
18 View Download
19 View Download
20 View Download
21 View Download Yes
22 View Download
23 View Download
24 View Download
25 View Download
26 View Download Yes
27 View Download
28 View Download
29 View Download
30 View Download
31 View Download Yes
32 View Download
33 View Download
34 View Download
35 View Download
36 View Download
37 View Download
38 View Download
39 View Download
40 View Download
41 View Download
42 View Download
43 View Download
44 View Download
45 View Download Yes
46 View Download
47 View Download
48 View Download
49 View Download
50 View Download
51 View Download
52 View Download
53 View Download
54 View Download
55 View Download
56 View Download
57 View Download
58 View Download
59 View Download Yes
60 View Download Yes
61 View Download Yes
62 View Download
63 View Download
64 View Download
65 View Download
66 View Download
67 View Download
68 View Download
69 View Download
70 View Download
71 View Download
72 View Download Yes
73 View Download
74 View Download Yes
75 View Download
76 View Download
77 View Download
78 View Download
79 View Download Yes
80 View Download
81 View Download Yes
82 View Download
83 View Download
84 View Download Yes
85 View Download
86 View Download
87 View Download
88 View Download
89 View Download
90 View Download
91 View Download
92 View Download Yes
93 View Download
94 View Download
95 View Download
96 View Download Yes
97 View Download
98 View Download
99 View Download
100 View Download