grimoire/python/number.py

34 lines
836 B
Python

# https://web.archive.org/web/20180612183650if_/https://github.com/jorgegonzalez/beginner-projects#whats-my-number
import collections
def prime(number):
for factor in range(2, number):
if number % factor == 0:
return False
return True
def shatter(number):
digits = collections.deque()
while number > 0:
digits.insert(0, number % 10)
number = int(number / 10)
return digits
def numbers(min=1, max=1000):
for number in range(min, max + 1):
if number > 9 and prime(number):
yield number, shatter(number)
for number, digits in numbers():
if digits[-1] != len(digits) or (digits[0] + digits[1]) % 2 == 0:
continue
elif sum(digits) > 10 or digits[-2] % 2 != 0 or digits[-2] < 2:
continue
elif len([digit for digit in digits if digit in [1, 7]]) > 0:
continue
print(number)