Esempio n. 1
0
    """
    num_string = str(number)
    for i in range(len(num_string)):
        if not util_euler.is_prime(int(num_string)):
            return False
        num_string = rotate(num_string)
    return True

if __name__ == "__main__":
    import doctest
    doctest.testmod()
    LIMIT = 1000000

    circular_primes = []

    prime = util_euler.prime_generator(LIMIT)
    primes = []
    for i in prime:
        primes.append(i)

    for i in primes:
        if i in circular_primes:
            continue
        num_string = str(i)
        if is_circular_prime(i):
            for j in range(len(num_string)):
                if int(num_string) not in circular_primes:
                    circular_primes.append(int(num_string))
                num_string = rotate(num_string)

    print(circular_primes)
Esempio n. 2
0
from itertools import combinations
import util_euler

def is_permutation(a, b):
    assert type(a).__name__ == 'int'
    assert type(b).__name__ == 'int'

    list_a = [c for c in str(a)]
    list_b = [c for c in str(b)]
    list_a.sort()
    list_b.sort()
    if list_a == list_b:
        return True
    return False

if __name__ == "__main__":
    primes = [i for i in util_euler.prime_generator(maximum=9999) if i > 999]
    unusual_sequence = [sequence for sequence in combinations(primes, 3)
                        if sequence[1] - sequence[0] == sequence[2] - sequence[1]
                        and is_permutation(sequence[0],sequence[1])
                        and is_permutation(sequence[1],sequence[2])
                        and not sequence[0] == 1487]
    answer = unusual_sequence[0]
    print(str(answer[0]) + str(answer[1]) + str(answer[2]))
Esempio n. 3
0
import util_euler

def is_pandigital(number):
    """if a number includes all the digits 1 to n exactly once, the number is pandigital
    >>> is_pandigital(1254)
    False
    >>> is_pandigital(233145)
    False
    >>> is_pandigital(1)
    True
    >>> is_pandigital(193728465)
    True
    """
    num_string = str(number)
    for d in range(len(num_string)):
        if not num_string.count(str(d+1)) == 1:
            return False
    return True

if __name__ == "__main__":
    import doctest
    doctest.testmod()

    prime = util_euler.prime_generator(7654321)
    result = 0
    for i in prime:
        if is_pandigital(i):
            result = i
    print(result)
Esempio n. 4
0
import util_euler

LIMIT = 1000000

#maximum_n_phi = 0
#for n in range(1, LIMIT + 1):
#    prime_factors = set(util_euler.find_prime_factors(n))
#    relatively_prime = len([p for p in range(1, n + 1) if all(not p % q == 0 for q in prime_factors)])
#    n_phi = n / relatively_prime
#    if n_phi > maximum_n_phi:
#        maximum_n_phi = n_phi
#        answer = n
#        print(n)
#

# the code above indicates that the answer is the product of primes.
# 2, 6, 30, 210, 2310, 30030
# so...

gen = util_euler.prime_generator()
answer = 1
for i in gen:
    answer *= i
    if answer * i > LIMIT:
        break

print("answer: {0}".format(answer))
Esempio n. 5
0
import util_euler
import re

def pattern_generator(length_of_number):
    if length_of_number - 1 < 1:
        return None
    pass

if __name__ == "__main__":
    maximum = 100
    while maximum <= 10000:
        gen = util_euler.prime_generator(maximum=maximum, minimum=int(maximum/10))
        primes = [n for n in gen]

        patterns = pattern_generator(len(str(maximum)) - 1)
        for p in patterns:
            match_cases = re.findall(p, str(primes))
            if len(match_cases) == 6:
                answer = "".join([d for d in match_cases[0]])
                break
        maximum *= 10

        print("answer: {0}".format(answer))