Solution to problem 49
This commit is contained in:
parent
7702c0bdee
commit
859c2d8321
41
src/Python/Problem049.py
Normal file
41
src/Python/Problem049.py
Normal file
@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Created on 18 Sep 2021
|
||||
|
||||
@author: David Doblas Jiménez
|
||||
@email: daviddoji@pm.me
|
||||
|
||||
Solution for problem 49 of Project Euler
|
||||
https://projecteuler.net/problem=49
|
||||
"""
|
||||
|
||||
from utils import timeit, list_primes
|
||||
|
||||
|
||||
@timeit("Problem 49")
|
||||
def compute():
|
||||
"""
|
||||
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms
|
||||
increases by 3330, is unusual in two ways:
|
||||
(i) each of the three terms are prime, and,
|
||||
(ii) each of the 4-digit numbers are permutations of one another.
|
||||
|
||||
There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes,
|
||||
exhibiting this property, but there is one other 4-digit increasing sequence.
|
||||
|
||||
What 12-digit number do you form by concatenating the three terms in this sequence?
|
||||
"""
|
||||
ans = []
|
||||
primes_list = sorted(set(list_primes(10_000)) - set(list_primes(1_000)))
|
||||
|
||||
for number in primes_list:
|
||||
if set(list(str(number))) == set(list(str(number+3330))) == set(list(str(number+6660))):
|
||||
if number+3330 in primes_list and number+6660 in primes_list:
|
||||
ans.append(str(number)+str(number+3300)+str(number+6660))
|
||||
# return the second one
|
||||
return ans[1]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
print(f"Result for Problem 49: {compute()}")
|
Loading…
x
Reference in New Issue
Block a user