Skip to content

A simple real-time prime factorization program for the command line. Also supports imports as a python library with generators for primes and prime factors.

MarcelGarus/factorize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

factorize

A small prime factorization program that can be called with a number:

python factorize.py 2595925957847039

In case you're in the mood for extending this functionality, the file also offers two generators: primes and factorize.

from factorize import primes, factorize

primes

primes is a simple generator for creating prime numbers.

for prime in primes():
    print(prime)
# prints 2, 3, 5, 7, ...

Optionally, you can provide a maximum number n of primes you want to get:

print(list(primes(5)))
# prints [2, 3, 5, 7, 11]

Or declare a limit for the largest prime (primes you get <= limit):

print(list(primes(limit=100)))
# prints [2, 3, ..., 89, 97]

factorize

factorize is a generator that lets you factorize a number into its primes.

for factor in factorize(2595925957847039):
    print(factor)
# prints 38047, 140281, and 486377 with a break between each number as it takes
# some time to calculate each factor

The generator yields factors as they become available.

About

A simple real-time prime factorization program for the command line. Also supports imports as a python library with generators for primes and prime factors.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages