From 8722d0a963219e28ecd56719dbceaa1a05a82bb1 Mon Sep 17 00:00:00 2001 From: steven-y-e Date: Wed, 2 Aug 2023 12:54:28 -0400 Subject: [PATCH] feat(solution): problem #49 --- solutions/049/primepermutations.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 solutions/049/primepermutations.py diff --git a/solutions/049/primepermutations.py b/solutions/049/primepermutations.py new file mode 100644 index 0000000..e47084b --- /dev/null +++ b/solutions/049/primepermutations.py @@ -0,0 +1,30 @@ +from itertools import permutations +import math + +def is_prime(n): + for i in range(2, math.floor(math.sqrt(n) + 1)): + if n % i == 0: + return False + return True + +def list_to_int(list): + n = 0 + for i in list: + n = (n * 10) + int(i) + return n + +for i in range(1000,10000): + if is_prime(i): + iPermutations = list(permutations(list(str(i)))) + primePermutations = [] + primePermutations.append(i) + primeCounter = 1 # starting number is already a prime + for i in iPermutations: + currentPermutation = list_to_int(i) + if currentPermutation == primePermutations[-1] + 3330 and int(i[0]) != 0 and is_prime(currentPermutation): + if not currentPermutation in primePermutations: + primePermutations.append(currentPermutation) + primeCounter += 1 + if primeCounter == 3: + print(primePermutations) +