コード例 #1
0
def show_diff(n):
	p=1
	num_trues=0
	num_falses=0
	while p <= n:
		num=generateprimes.genprime(p)
		num1=generateprimes.genprime(p+1)
		#num_log=math.log(num)
		#num_log=int(abs(num_log))
		num1_log=math.log(num1)
		num1_log=int(round(num1_log))
		diff=num1-num
		isit=False
		#num1_log_p=num1/num1_log
		if diff <= num1_log:
			isit=True
			num_trues+=1
		else:
			isit=False
			num_falses+=1
		print num1, "-", num, "=", diff, "-is diff <= log(", num1, ")", "...", isit
		p+=1
	num_falses=float(num_falses)
	num_trues=float(num_trues)
	total=num_falses+num_trues
	percent_true=num_trues/total*100
	percent_false=num_falses/total*100
	print "Total 'True's: ", num_trues, "   ", percent_true,"%"
	print "Total 'False's: ", num_falses, "   ", percent_false,"%"
コード例 #2
0
ファイル: factorization.py プロジェクト: myano/primes
def f(k,j):
        '''
	This function 'f' takes a give number 'k' and produces the Prime-Factorization in the form of a list, excluding the number one and the given number.

	'j' here is a counter for the 'j'th prime number.

	If you would like this in a pretty print format I have made a for loop inside "numlist_prime.py" which turns the list into "a * b * c" etc.. 
	'''
	global listofprimefactors
        if k==0:
		temp=0
		print temp #I've never encountered this, but just in case ;)
	elif k==1:
		temp=0 #basically do nothing, this still has to be here so it doesn't do the "else" statement an extra time
        elif k==2:
                listofprimefactors.append(2) #Adds 2 as a factor if k is equal 2
        elif k==3:
                listofprimefactors.append(3) #Adds 3 as a factor if k is equal to 3
        elif k % 2 == 0:
		#If divisble by add 2 as a factor to k
                listofprimefactors.append(2)
                f(k/2,j) #call to recursion, but the new value of k is half of k, because we havae just accounted for k being divisble by 2
        elif k % generateprimes.genprime(j)==0:
		#This is a bit copmlicated, but basically what this does is: if the value of k is evenly divisble by the 'j'th prime number then add that 'j'th prime nubmer as a factor. The first time this elif statement runs the "generateprimes.genprime(j)" will equal 3
                primenum=generateprimes.genprime(j)
                listofprimefactors.append(primenum)
                b=k/primenum #since we have just accounted for the "prime factor" we need to move on, so we divide k by that prime number and send that new value of k (b) to the call of recursion
                j=1 #j is always set to 1 here because the first time a number (k) is divisble by a prime number, the next time it goes to the call of recursion the value of j will be 2. 
                f(b,j+1) #j will be equal to 2, the first time this elif statement runs through. 
        else:
                f(k,j+1) #if k was not divisble by anthing above, increase the value of j. This allows the 'j'th prime number to increase by one. So the first time this runs if k is not divisble by the (j=2) 2nd prime number (which is 3), then increase j to 3 (j=3). This way the second time through it will check to see if k is evenly divisble by the 3rd prime number (which is 5). and so on...

	return listofprimefactors
コード例 #3
0
ファイル: findlowbounds4primes.py プロジェクト: myano/primes
def newfunc(m):
    m = int(m)
    for eachnum in range(2, m):
        k = 3 / 2
        compareme = eachnum ** k
        print "here is the 'compare-me' to the power of 3/2: ", compareme
        comparemeagain = compareme / 2
        comparemeagain = int(comparemeagain)
        generatedprime = generateprimes.genprime(eachnum)
        if comparemeagain < generatedprime:
            print eachnum, " is TRUE for this case. Here is the prime ", generatedprime, "here is the 'compare-me': ", comparemeagain
        else:
            print eachnum, " is FALSE."
        eachnum += 1