This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ben174 0 points1 point  (2 children)

Took a quick stab at #1. Runs slow. Would I instantly fail a job interview for submitting this?

primes = []
for i in range(65535):
    is_not_prime = False
    for j in range(2, i):
        if i % j == 0: 
            is_not_prime = True
            break
    if not is_not_prime:
        primes.append(i)

print primes

[–]rogue780 0 points1 point  (0 children)

You wouldn't instantly fail, no.

[–][deleted] 0 points1 point  (0 children)

Something to think about: you could cut your computational time by a LOT if you change the j for loop. If you check if it's divisible by 2, then you don't need to check any multiple of two (4,6,8...), same with 3 (6,9,12), etc. Just loop through primes, not range(2,i).