#!/usr/bin/env python from math_tools import rotations, primes, is_prime """https://projecteuler.net/problem=35""" if __name__ == '__main__': result = 0 for prime in primes(1000000): result += all(is_prime(int("".join(rot))) for rot in rotations(list(str(prime)))) print(result)
#!/usr/bin/env python from math_tools import rotations, primes, is_prime """https://projecteuler.net/problem=35""" if __name__ == '__main__': result = 0 for prime in primes(1000000): result += all( is_prime(int("".join(rot))) for rot in rotations(list(str(prime)))) print(result)
#!/usr/bin/env python from math_tools import primes """https://projecteuler.net/problem=10""" if __name__ == '__main__': print(sum(primes(2000000)))
#!/usr/bin/env python from math_tools import primes """https://projecteuler.net/problem=46""" if __name__ == '__main__': primes_list = [] num = 9 for next_prime in primes(): while num < next_prime: if num not in primes_list: found = False for prime in primes_list: if ((num - prime) / 2) ** 0.5 % 1 == 0: found = True break if not found: print(num) exit() num += 2 primes_list.append(next_prime)
#!/usr/bin/env python from math_tools import is_prime, primes """https://projecteuler.net/problem=27""" if __name__ == '__main__': generator_product = None max_primes_generated = None for b in primes(1000): for a in range(-999, 1000, 2): n = 0 primes_generated = 0 while True: if not is_prime((n ** 2) + (a * n) + b): break primes_generated += 1 n += 1 if primes_generated > max_primes_generated: max_primes_generated = primes_generated generator_product = a * b print(generator_product)
#!/usr/bin/env python from math_tools import primes, is_prime """https://projecteuler.net/problem=49""" if __name__ == '__main__': for prime in primes(): prime2 = prime + 3330 prime3 = prime2 + 3330 if ( prime != 1487 and len(str(prime)) == 4 and sorted(str(prime)) == sorted(str(prime2)) == sorted(str(prime3)) and is_prime(prime2) and is_prime(prime3) ): print str(prime) + str(prime + 3330) + str(prime + 6660) exit()
#!/usr/bin/env python from math_tools import primes, is_pandigital """https://projecteuler.net/problem=41""" if __name__ == '__main__': for prime in primes(7654321)[::-1]: if is_pandigital(prime): print(prime) break
#!/usr/bin/env python from math_tools import primes """https://projecteuler.net/problem=37""" if __name__ == "__main__": primes_list = [] truncatable_primes = [] for prime in primes(): primes_list.append(prime) if len(truncatable_primes) >= 11: break prime = str(prime) if len(prime) <= 1: continue truncatable = True for i in range(1, len(prime)): if int(prime[i:]) not in primes_list or int(prime[:i]) not in primes_list: truncatable = False break if truncatable: truncatable_primes.append(int(prime)) print(sum(truncatable_primes))