Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 061e659cfb
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 55 lines (48 sloc) 1.779 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
import math

def is_prime(n):
    if n < 2:
        return False
    if n != 2 and n % 2 == 0:
        return False
    for j in xrange(3, math.sqrt(n) + 1, 2):
        if n % j == 0:
            return False
    return True

primes = [x for x in xrange(10000) if is_prime(x)]

def test_nums(group):
    for i in xrange(len(group)):
        for j in xrange(len(group)):
            if j != i:
                if not (is_prime(int(str(group[i]) + str(group[j]))) and \
                        is_prime(int(str(group[j]) + str(group[i])))):
                    return False
    return True

def run_test(primes):
    for i in xrange(len(primes) - 5):
        for j in xrange(i + 1, len(primes)):
            if not test_nums([primes[i], primes[j]]):
                continue
            for k in xrange(j + 1, len(primes)):
                if not test_nums([primes[i], primes[j], primes[k]]):
                    continue
                for l in xrange(k + 1, len(primes)):
                    if not test_nums([primes[i], primes[j], primes[k], primes[l]]):
                        continue
                    for m in xrange(l + 1, len(primes)):
                        if not test_nums([primes[i], primes[j], primes[k], primes[l], primes[m]]):
                            continue
                        else:
                            group = [
                                primes[i],
                                primes[j],
                                primes[k],
                                primes[l],
                                primes[m]
                            ]
                            print group
                            print sum(group)
                            return

# remove 2 & 5
del(primes[0])
del(primes[1])

run_test(primes)
Something went wrong with that request. Please try again.