Skip to content

Commit 584b4c1

Browse files
committed
Move factorize into a new module next to image_to_text
1 parent 5cc124b commit 584b4c1

File tree

8 files changed

+18
-14
lines changed

8 files changed

+18
-14
lines changed

12-evil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from auth import get_last_src_url
1414
from auth import read_url
15-
from image import image_to_text
15+
from etc import image_to_text
1616
from io import BytesIO
1717
from PIL import Image
1818
from PIL import ImageFile

16-mozart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from auth import get_last_src_url
1414
from auth import read_url
1515
from cache import cached
16-
from image import image_to_text
16+
from etc import image_to_text
1717
from io import BytesIO
1818
from PIL import Image
1919

18-balloons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from auth import get_nth_comment
1515
from auth import read_url
1616
from difflib import Differ
17-
from image import image_to_text
17+
from etc import image_to_text
1818
from io import BytesIO
1919
from PIL import Image
2020

24-ambiguity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from auth import read_url
1515
from cache import autocached
1616
from cache import cached
17-
from image import image_to_text
17+
from etc import image_to_text
1818
from io import BytesIO
1919
from PIL import Image
2020
from PIL import UnidentifiedImageError

25-lake.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from auth import get_last_src_url
1414
from auth import read_url
1515
from cache import autocached
16-
from image import image_to_text
16+
from etc import image_to_text
1717
from itertools import chain
1818
from PIL import Image
1919

26-decent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# http://www.pythonchallenge.com/pc/hex/decent.html
1212

1313
from auth import read_riddle
14-
from image import image_to_text
14+
from etc import image_to_text
1515
from importlib import import_module
1616
from io import BytesIO
1717
from PIL import Image

30-yankeedoodle.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
from auth import get_last_src_url
1414
from auth import read_riddle
15+
from etc import factorize
1516
from itertools import chain
16-
from math import sqrt
1717

1818

1919
def read_csv_cells(url):
@@ -23,13 +23,6 @@ def read_csv_cells(url):
2323
return list(chain.from_iterable(rows))
2424

2525

26-
def factorize(length):
27-
"""Obtains the factors of `length`"""
28-
for n in range(2, int(sqrt(length))):
29-
if length % n == 0:
30-
return n, length // n
31-
32-
3326
def extract_formula(cells, width, height):
3427
"""Extracts the formula hidden in the CSV"""
3528
it = iter(cells)

image.py renamed to etc.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99

1010
# http://www.pythonchallenge.com/
1111

12+
from math import sqrt
13+
14+
15+
def factorize(number):
16+
"""Obtains the factors of `number`"""
17+
factors = []
18+
for factor in range(2, int(sqrt(number))):
19+
if number % factor == 0:
20+
factors.extend([factor, number // factor])
21+
return factors
22+
1223

1324
def image_to_text(image, threshold=10, skip=6, white="##", black=" "):
1425
"""Converts an image to text, lighting pixel greater than a threshold and

0 commit comments

Comments
 (0)