Exemplo n.º 1
0
  def testIsPrime(self):
    p = primes.Primes()

    self.assertFalse(p.is_prime(0))
    self.assertFalse(p.is_prime(1))
    self.assertFalse(p.is_prime(4))
    self.assertFalse(p.is_prime(100))

    self.assertTrue(p.is_prime(5))
    self.assertTrue(p.is_prime(2))
    self.assertTrue(p.is_prime(3))
    self.assertTrue(p.is_prime(97))
Exemplo n.º 2
0
  def testSieve(self):
    p = primes.Primes()

    self.assertEqual(p.sieve(0), [ 0 ])
    self.assertEqual(p.sieve(1), [ 0, 0 ])
    self.assertEqual(p.sieve(2), [ 0, 0, 2 ])
    self.assertEqual(p.sieve(3), [ 0, 0, 2, 3 ])
    self.assertEqual(p.sieve(4), [ 0, 0, 2, 3, 0 ])
    self.assertEqual(p.sieve(5), [ 0, 0, 2, 3, 0, 5 ])
    self.assertEqual(p.sieve(6), [ 0, 0, 2, 3, 0, 5, 0 ])
    self.assertEqual(p.sieve(10), [ 0, 0, 2, 3, 0, 5, 0, 7, 0, 0, 0 ])
    self.assertEqual(p.sieve(10), [ 0, 0, 2, 3, 0, 5, 0, 7, 0, 0, 0 ])
    self.assertEqual(p.sieve(6), [ 0, 0, 2, 3, 0, 5, 0 ])
    self.assertEqual(p.sieve(5), [ 0, 0, 2, 3, 0, 5 ])
    self.assertEqual(p.sieve(4), [ 0, 0, 2, 3, 0 ])
    self.assertEqual(p.sieve(3), [ 0, 0, 2, 3 ])
    self.assertEqual(p.sieve(2), [ 0, 0, 2 ])
    self.assertEqual(p.sieve(1), [ 0, 0 ])
    self.assertEqual(p.sieve(0), [ 0 ])
Exemplo n.º 3
0
 def __init__(self, bits=64, prefilter=False):
     self.prefilter = prefilter
     self.primes = primes.Primes(bits)
     self.pascal = pascal.Pascal(bits)
        pickle.dump([k_current, list_A321221], f)


def restore_previous_results(file_output_pickle):
    global k_current, list_A321221
    if os.path.exists(file_output_pickle):
        with open(file_output_pickle, 'rb') as f:
            k_current, list_A321221 = pickle.load(f)


#############################################################
# Main
#############################################################

print("Initialize objects...")
p = primes.Primes(caching_primality_results)
gp = goldbach.GoldbachPartition(p)
print("DONE")
print("Loading helper sets...")
p.init_set(file_input_primes, 1)
p.init_set(file_input_twinprimes, 2)
p.init_set(file_input_nonprimes, 3)
print("DONE")
print("Sorting primes...")
p.sort_primes_set()
p.sort_twinprimes_set()
print("DONE")
print("Restoring previous results...")
restore_previous_results(file_output_pickle)
if k_current > 0:
    min_num = k_current
Exemplo n.º 5
0
 def testPrimeMask(self):
   p = primes.Primes()
   self.assertEqual(p.prime_mask([ 10, 20, 30, 40, 50 ]), [ 30, 40 ])
   self.assertEqual(p.prime_mask([ 10, 20, 30, 40, 50, 60, 70 ]), [ 30, 40, 60 ])
   self.assertEqual(p.prime_mask([ 10, 20, 30, 40 ]), [ 30, 40 ])
Exemplo n.º 6
0
 def testGetMax(self):
   p = primes.Primes(1024)
   self.assertTrue(p.get_max(), 1024)