-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71c2ad4
commit 1e65048
Showing
1 changed file
with
38 additions
and
27 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,38 @@ | ||
#!/usr/bin/python3 | ||
import sys | ||
|
||
|
||
def factorize(num): | ||
""" Generate 2 factors for a given number""" | ||
factor1 = 2 | ||
while (num % factor1): | ||
if (factor1 <= num): | ||
factor1 += 1 | ||
|
||
factor2 = num // factor1 | ||
return (factor2, factor1) | ||
|
||
|
||
if len(sys.argv) != 2: | ||
sys.exit(f"Wrong usage: {sys.argv[0]} <file_path>") | ||
|
||
filename = sys.argv[1] | ||
|
||
file = open(filename, 'r') | ||
lines = file.readlines() | ||
|
||
for line in lines: | ||
num = int(line.rstrip()) | ||
factor2, factor1 = factorize(num) | ||
print(f"{num} = {factor2} * {factor1}") | ||
#!/usr/bin/env python3 | ||
""" Factor numbers """ | ||
from sys import argv | ||
from math import sqrt | ||
|
||
|
||
def open_read_file(file_name): | ||
"""read from file | ||
add to array | ||
""" | ||
with open(file_name, encoding="utf-8") as file: | ||
lines = file.readlines() | ||
number_to_factor = [] | ||
for line in lines: | ||
number_to_factor.append(int(line)) | ||
return number_to_factor | ||
|
||
|
||
def find_and_times(n): | ||
"""factor each | ||
n given | ||
""" | ||
for i in range(2, n): | ||
if n == ((n // i) * i): | ||
print("{}={}*{}".format(n, (n // i), i)) | ||
break | ||
|
||
|
||
def fac_list(ls): | ||
"""factor each | ||
num in ls | ||
""" | ||
for i in ls: | ||
find_and_times(i) | ||
|
||
|
||
if len(argv) == 2: | ||
fac_list(open_read_file(argv[1])) |