From 1d67f5c191ab08296c9173343974c8baaae0207c Mon Sep 17 00:00:00 2001 From: daviddoji Date: Thu, 2 Sep 2021 15:58:08 +0200 Subject: [PATCH] Solution to problem 35 --- src/Python/Problem035.py | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/Python/Problem035.py diff --git a/src/Python/Problem035.py b/src/Python/Problem035.py new file mode 100644 index 0000000..76856ec --- /dev/null +++ b/src/Python/Problem035.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +""" +Created on 02 Apr 2021 + +@author: David Doblas Jiménez +@email: daviddoji@pm.me + +Solution for problem 35 of Project Euler +https://projecteuler.net/problem=35 +""" + +from utils import timeit, is_prime + +def circular_number(n): + n = str(n) + result = [] + for i in range(len(n)): + result.append(int(n[i:] + n[:i])) + return result + +@timeit("Problem 35") +def compute(): + """ + The number, 197, is called a circular prime because all rotations of the + digits: 197, 971, and 719, are themselves prime. + + There are thirteen such primes below 100: + 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97. + + How many circular primes are there below one million? + """ + circular_primes = [] + for i in range(2, 1_000_000): + for j in circular_number(i): + if not is_prime(j): + break + else: + circular_primes.append(i) + + return len(circular_primes) + + +if __name__ == "__main__": + + print(f"Result for Problem 35: {compute()}") \ No newline at end of file