Пример #1
0
def challenge058():

    current = 1
    total = 1
    nPrimes = 0
    diagonals = 1

    primeChecker = PrimeChecker()

    # Cycle through layers
    sidestep = 2
    while True:
        for j in xrange(1, 4):
            current += sidestep
            
            if primeChecker.isPrime(current):
                nPrimes += 1

        current += sidestep

        diagonals += 4

        if nPrimes * 10 < diagonals:
            return sidestep + 1

        sidestep += 2
Пример #2
0
def challenge077():
    pc = PrimeChecker()

    nums = dict()

    num = 2
    while True:
        sums = set()

        # Is the current number a prime?
        if pc.isPrime(num):
            sums.add(tuple([num]))

        # Check for previous sums
        for a in xrange(2, num // 2 + 1):
            b = num - a

            # Collect each a sum to each b sum
            for abSums in [sorted(aSum + bSum) for aSum in nums[a] for bSum in nums[b]]:
                sums.add(tuple(abSums))

        nums[num] = sums

        if len(sums) > 5000:
            return num

        num += 1
Пример #3
0
def challenge051():
    pc = PrimeChecker()
    step = cycle([2, 4])
    current = 5
    while True:
        # Check current
        if pc.isPrime(current) and has3SameDigits(current):
            # Substitute 0 to 9
            w = str(current)
            for i in xrange(0, 10):
                nPrimes, smallest = substitutePrimes(w, str(i), pc)
                if nPrimes == 8:
                    return smallest

        current += step.next()