Skip to content

Commit

Permalink
Problem 10 passed, profile script started
Browse files Browse the repository at this point in the history
  • Loading branch information
James Raikes authored and James Raikes committed Jul 15, 2016
1 parent d07c753 commit 4457762
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion problem10.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ def sieve(upper):
int_list = [x for x in int_list if x % prime_list[-1]]
return prime_list

def sieve2(upper):
'''Version of sieve that follows Wikipedia's pseudocode
Avoids using list comprehension which is apparently quite slow
Further optimisation may be possible using numpy arrays'''
A = [True] * (upper - 2) # Don't need bool for 1 or upper'
for i in range(2, int(upper ** 0.5) + 1):
if A[i - 2]:
for j in range(i ** 2, upper, i):
A[j - 2] = False
return [x + 2 for x in range(len(A)) if A[x]]

def main():
print(sum(sieve(60000)))
print(sum(sieve2(2000000)))


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions profile_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
''''

0 comments on commit 4457762

Please sign in to comment.