Project Euler

This Python 3 notebook contains some solutions for the Project Euler challenge.

/!\ Warning: do not spoil yourself the pleasure of solving these problems by yourself!

I (Lilian Besson) started to work again on Project Euler in October 2020 I should try to work on it again, hence this notebook...

Badge giving the number of solved problems

Common tool

Let's write here a few efficient functions that are used in lots of problems.

Problem 51: prime digit replacements (pastis ! 51 je t'aime)

By replacing the 1st digit of the 2-digit number x3, it turns out that six of the nine possible values: 13, 23, 43, 53, 73, and 83, are all prime.

By replacing the 3rd and 4th digits of 56xx3 with the same digit, this 5-digit number is the first example having seven primes among the ten generated numbers, yielding the family: 56003, 56113, 56333, 56443, 56663, 56773, and 56993. Consequently 56003, being the first member of this family, is the smallest prime with this property.

Find the smallest prime which, by replacing part of the number (not necessarily adjacent digits) with the same digit, is part of an eight prime value family.

Who it doesn't seem easy, I can't (yet) think of an efficient solution.

Let's try to obtain the examples given in the problem statement, with the smallest prime giving a 6-sized family being 13 and the smallest prime giving a 7-sized family being 56003.

The code seems to work pretty well. It's not that fast... but let's try to obtain the smallest prime giving a 8-sized family.


Problem 52: Permuted multiples

It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.

Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.

Done, it was quick.

Problem 53: Combinatoric selections

There are exactly ten ways of selecting three from five, 12345: 123, 124, 125, 134, 135, 145, 234, 235, 245, and 345.

In combinatorics, we use the notation, ${5 \choose 3} = 10$. In general, $${n \choose r} = \frac{n!}{r! (n-r)!}$$

It is not until $n=23$, that a value exceeds one-million: ${23 \choose 10} = 1144066$.

How many, not necessarily distinct, values of ${n \choose r}$ for $1 \leq n \leq 100$, are greater than one-million?

That was quite easy.

Problem 54:


Problem 55: