Adopted new convention from template

This commit is contained in:
David Doblas Jiménez 2022-10-02 18:38:07 +02:00
parent d464a0f434
commit 4fbb158c70

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python
""" """
Created on 18 Sep 2021 Created on 18 Sep 2021
@ -9,33 +9,39 @@ Solution for problem 49 of Project Euler
https://projecteuler.net/problem=49 https://projecteuler.net/problem=49
""" """
from utils import timeit, list_primes from utils import list_primes, timeit
@timeit("Problem 49") @timeit("Problem 49")
def compute(): def compute():
""" """
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms The arithmetic sequence, 1487, 4817, 8147, in which each of the terms
increases by 3330, is unusual in two ways: increases by 3330, is unusual in two ways:
(i) each of the three terms are prime, and, (i) each of the three terms are prime, and,
(ii) each of the 4-digit numbers are permutations of one another. (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, There are no arithmetic sequences made up of three 1-, 2-, or 3-digit
exhibiting this property, but there is one other 4-digit increasing sequence. 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? What 12-digit number do you form by concatenating the three terms in this
sequence?
""" """
ans = [] ans = []
primes_list = sorted(set(list_primes(10_000)) - set(list_primes(1_000))) primes_list = sorted(set(list_primes(10_000)) - set(list_primes(1_000)))
for number in primes_list: for number in primes_list:
if set(list(str(number))) == set(list(str(number+3330))) == set(list(str(number+6660))): if (
if number+3330 in primes_list and number+6660 in primes_list: set(list(str(number)))
ans.append(str(number)+str(number+3300)+str(number+6660)) == 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 the second one
return ans[1] return ans[1]
if __name__ == "__main__": if __name__ == "__main__":
print(f"Result for Problem 49 is {compute()}")
print(f"Result for Problem 49: {compute()}")