This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LIMIT = 20001 | |
NATURALS = range(3,LIMIT, 2) | |
PRIMES = [2] | |
current = 0 | |
max = LIMIT | |
while len(NATURALS) > 0: | |
current = NATURALS.pop(0) | |
PRIMES.append(current) | |
i = current |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import time | |
def euler_sieve(n): | |
# source: http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes | |
# Create a candidate list within which non-primes will | |
# marked as None, noting that only candidates below | |
# sqrt(n) need be checked. | |
candidates = range(n+1) | |
fin = int(n**0.5) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Think of the array in this manner: | |
# _ i --> _ | |
# ARRAY = |00 | In the top level list, indices are i | |
# | 11 | In the nested lists, indices are j | |
# j | 22 | | |
# | | 33 | | |
# V | 44 | | |
# |_ 55 _| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if 0 | |
SAFEARRAY psa; | |
VARIANT vNewData; | |
BindVariantToData(i, &vNewData, &psa); | |
#else | |
SAFEARRAY aSa; | |
VARIANT vNewData; | |
BindVariantToData(i, &vNewData, &aSa); | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def prime_factorization(inputvalue, sieve = True, primes = None): | |
""" | |
Takes an Integer argument and returns a the prime factorization as a list. | |
e.g. prime_factorization(45) => [3, 3, 5] | |
Optional arguments are 'sieve' and 'primes'; default values are 'True' and | |
'None' respectively. Setting sieve to 'False' commits the user to providing | |
a set of primes as a list. | |
e.g. prime_factorization(45, sieve=False, primes=[3]) => [3, 3] | |
""" |