Guess a number given specific criteria
This commit is contained in:
parent
c906f77062
commit
bb067ceffe
|
@ -0,0 +1,41 @@
|
||||||
|
# https://web.archive.org/web/20180612183650if_/https://github.com/jorgegonzalez/beginner-projects#whats-my-number
|
||||||
|
|
||||||
|
import collections
|
||||||
|
|
||||||
|
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):
|
||||||
|
yield number, shatter(number)
|
||||||
|
|
||||||
|
def prime(number):
|
||||||
|
for factor in range(2, number):
|
||||||
|
if number % factor == 0:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
for number, digits in numbers():
|
||||||
|
if len(digits) < 2:
|
||||||
|
continue
|
||||||
|
elif not prime(number):
|
||||||
|
continue
|
||||||
|
elif len([digit for digit in digits if digit == 1 or digit == 7]) > 0:
|
||||||
|
continue
|
||||||
|
elif sum(digits) > 10:
|
||||||
|
continue
|
||||||
|
elif (digits[0] + digits[1]) % 2 == 0:
|
||||||
|
continue
|
||||||
|
elif digits[-2] < 2 or digits[-2] % 2 != 0:
|
||||||
|
continue
|
||||||
|
elif digits[-1] != len(digits):
|
||||||
|
continue
|
||||||
|
|
||||||
|
print(number)
|
Loading…
Reference in New Issue