Skip to content

Instantly share code, notes, and snippets.

@ricrogz
Last active March 25, 2017 11:51
Show Gist options
  • Select an option

  • Save ricrogz/fd2a73d40d45a326b98fca6f93a5b659 to your computer and use it in GitHub Desktop.

Select an option

Save ricrogz/fd2a73d40d45a326b98fca6f93a5b659 to your computer and use it in GitHub Desktop.

Revisions

  1. ricrogz renamed this gist Mar 25, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt → factorize.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # Seen here: http://stackoverflow.com/questions/16996217/prime-factorization-list


    def primes(n):
    def factorize(n):
    primfac = []
    d = 2
    while d*d <= n:
  2. ricrogz created this gist Mar 25, 2017.
    14 changes: 14 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    # Seen here: http://stackoverflow.com/questions/16996217/prime-factorization-list


    def primes(n):
    primfac = []
    d = 2
    while d*d <= n:
    while (n % d) == 0:
    primfac.append(d) # supposing you want multiple factors repeated
    n //= d
    d += 1
    if n > 1:
    primfac.append(n)
    return primfac