Prime Number Optimisation Algorithm

preview_player
Показать описание
GET THE COURSE BELOW FREE - Solve this challenge and post in comments

SOCIAL:

WEBSITES:

-~-~~-~~~-~~-~-
Latest and Best Arduino Playlist in Collaboratio with DFRobot:
-~-~~-~~~-~~-~-
Рекомендации по теме
Комментарии
Автор

Hi Robotix, looking forward to taking this class! Thanks for making this :) - Al

seesaw
Автор

import time
primeList=[]
primeList.append(2)

def primeTest(testNum):
prime=True
for i in range (3, int(testNum/2), 2):
if testNum % i == 0:
prime = False
return prime

def allPrimes(maxNum):
for i in range(3, maxNum, 2):
if primeTest(i) == True:
primeList.append(i)

print("What is your maximum number?")
maxNum = int(input())
tic=time.clock()
allPrimes(maxNum)
toc=time.clock()
print("These are all primes under", primeList, " ", len(primeList))
print ("time to run=", toc-tic)


50% savings from your optimal solution!
Don't worry about the coupon. I just did this for fun. There is no sense in testing factors > 1/2 of the number being tested. If you are testing 11, there is no point in testing any factor > 5.5.

WashOralArguments
Автор

Just one fact: 1 is neither prime nor composite, according to most mathematicians today.

ThePianoman
visit shbcf.ru