Ejemplo n.º 1
0
def is_truncatable(p):
    p_str = str(p)
    if len(p_str) == 1:
        return False
    for length in range(1, len(p_str)):
        trunc_left = p_str[:length]
        trunc_right = p_str[-length:]
        if not (is_prime(int(trunc_left)) and is_prime(int(trunc_right))):
            return False
    return True
Ejemplo n.º 2
0
 def testPrimeOrNot(self):
     primes = [2, 3, 5, 7, 11, 13, 17, 19, 23]
     i = 0
     for j in range(2, 24):
         if is_prime(j):
             self.assertEqual(primes[i], j)
             i += 1
Ejemplo n.º 3
0
def test_permutations(digits):
    permuted_digits = itertools.permutations(digits)
    vals = sorted(set([digits_to_num(p) for p in permuted_digits]))
    subseqs = find_arithmetic_subsequences(vals)
    prime_subseqs = []
    for seq in subseqs:
        if all([is_prime(n) for n in seq]):
            prime_subseqs.append(seq)
    return prime_subseqs
Ejemplo n.º 4
0
def solve_with_permutations():
  # Go through all possible pandigital numbers from largest to smallest
  for num_digits in range(9,0,-1):
    digits = [str(i) for i in range(num_digits, 0, -1)]
    permutations = itertools.permutations(digits)
    for permutation in permutations:
      n = int(reduce(concat, permutation))
      if is_prime(n):
        return n
Ejemplo n.º 5
0
def disprove_goldbach():
    def satisfies_goldbach(n):
        for p in primes[primes < n]:
            r = n - p
            if sqrt(r / 2).is_integer():
                return True
        return False

    for n in itertools.count(9, 2):
        if is_prime(n):
            continue
        if not satisfies_goldbach(n):
            return n
Ejemplo n.º 6
0
 def testBuzzFizzForPrimesRegression(self):
     for i in range(4, 100):
         if is_prime(i) and i != 3 and i != 5:
             self.assertEqual("BuzzFizz", fizzbuzz(i))