コード例 #1
0
def exp_representaion(factors):
	uniq_primes = np.unique(factors)
	num = 1
	for f in factors:	num*=f
	primes = [np.asscalar(p) for p in get_primes(num) if p < num]

	exp_repr = []
	for p in primes:
		count = 0
		for f in factors:
			if p == f:
				count+=1
		exp_repr.append(count)
	return exp_repr
コード例 #2
0
def exp_representaion(factors):
    uniq_primes = np.unique(factors)
    num = 1
    for f in factors:
        num *= f
    primes = [np.asscalar(p) for p in get_primes(num) if p < num]

    exp_repr = []
    for p in primes:
        count = 0
        for f in factors:
            if p == f:
                count += 1
        exp_repr.append(count)
    return exp_repr
コード例 #3
0
def get_prime_factors(num):
    if num < 2: raise Exception('not decomposable into prime factors')
    primes = [np.asscalar(p) for p in get_primes(num) if p < num]
    composite = np.asscalar(np.copy(num))
    factors = []
    index = 0
    while index < len(primes):
        primf = primes[index]
        # check if the composite number is factorable
        # by a primefactor
        while composite % primf == 0:
            composite /= primf
            factors.append(primf)
        index += 1

    if not [int(k) for k in factors]: return [1, num]
    else: return [int(k) for k in factors]
コード例 #4
0
def get_prime_factors(num):
	if num < 2:		raise Exception('not decomposable into prime factors')
	primes = [np.asscalar(p) for p in get_primes(num) if p < num]
	composite = np.asscalar(np.copy(num))
	factors = []
	index = 0
	while index < len(primes):
		primf = primes[index]
		# check if the composite number is factorable
		# by a primefactor
		while composite%primf == 0:
			composite /= primf
			factors.append(primf)
		index += 1
	
	if not [int(k) for k in factors]: return [1, num]
	else: 	return [int(k) for k in factors]
コード例 #5
0
	def test_assert_input_is_not_float(self):
		self.assertRaises(TypeError,get_primes(5))
コード例 #6
0
	def test_assert_input_is_not_list(self):
		self.assertRaises(TypeError,get_primes([1,3]))
コード例 #7
0
	def test_assert_input_is_not_string(self):
		self.assertRaises(TypeError,get_primes('a_string'))
コード例 #8
0
	def test_asserts_input_not_negative(self):
		self.assertIs(get_primes(-10),'Please don\'t input negatives')
コード例 #9
0
	def test_returns_correct_primes(self):
		self.assertTrue(get_primes(20),[1,3,5,7,11,13,17,19])
コード例 #10
0
ファイル: euler_p10.py プロジェクト: mishra14/ProjectEuler
import prime_numbers

primes = prime_numbers.get_primes(2000000-1)
res = sum(primes)

print "Answer: {}".format(res)
コード例 #11
0
	def test_returns_primes_in_array(self):
		# Result should be an array
		self.assertIsInstance(get_primes(20), List)
		def test_assert_input_not decimal(self):
			 self.assertIs(get_primes)(5.2),'dont imput floating points' )