diff --git a/src/Python/Problems001-050/Problem049.py b/src/Python/Problems001-050/Problem049.py index bb89cfe..6d5e37f 100644 --- a/src/Python/Problems001-050/Problem049.py +++ b/src/Python/Problems001-050/Problem049.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python """ Created on 18 Sep 2021 @@ -9,33 +9,39 @@ Solution for problem 49 of Project Euler https://projecteuler.net/problem=49 """ -from utils import timeit, list_primes +from utils import list_primes, timeit @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, + 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. + 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? + 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)) + 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()}") \ No newline at end of file + print(f"Result for Problem 49 is {compute()}")