Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def is_prime(x):
if x < 2:
return False
if x == 2:
return True
if x % 2 == 0:
return False
i = 3
while i < x:
if x % i == 0:
return False
i += 2
return True
def generate_primes(limit):
i = 1
while i < limit:
i += 1
if not is_prime(i):
continue
yield i
def highest_prime_for(n):
primes = generate_primes(n)
current_prime = 2
for x in range(n):
if n % current_prime != 0:
current_prime = primes.next()
continue
n = n / current_prime
if is_prime(n):
return n
def main():
n = raw_input("Which number? ")
print "Highest prime factor for", n, "is", highest_prime_for(int(n))
main()
@AlexDT

This comment has been minimized.

Copy link

commented Sep 13, 2013

Python visualizer:
http://www.pythontutor.com/visualize.html

Is een handige tool om je code door te nemen.

  • Hij geeft aan dat er return op regel 3 moet unindenten
  • Op regel 26 geeft hij een memory error ofzo
@AlexDT

This comment has been minimized.

Copy link

commented Sep 13, 2013

oh ja en newline aan het eind van je bestand jonge, kom op melvin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.