-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhats_my_number.py
36 lines (29 loc) · 1.02 KB
/
whats_my_number.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'''Author Anurag Kumar(mailto:anuragkumarak95@gmail.com)
Whats My Number..?
Only one number available from 1 - 1000 that satisfies below rules,
find it.
RULES:
- The number has two or more digits.
- The number is prime.
- The number does NOT contain a 1 or 7 in it.
- The sum of all of the digits is less than or equal to 10.
- The first two digits add up to be odd.
- The second to last digit is even and greater than 1.
- The last digit is equal to how many digits are in the number.
'''
# 1, 3, 7, 6, 4, 5, 2 is the rule sequence i used.
def check_prime(num):
for i in range(num):
if i==0 or i==1: continue
if num%i==0:return False
return True
for i in range(10,1000): # 1
digits = [int(j) for j in str(i)]
l = len(digits)
if 1 in digits or 7 in digits: continue # 3
if digits[l-1] != l: continue # 7
if digits[l-2]<=1 or digits[l-2]%2!=0: continue # 6
if sum(digits)>10: continue # 4
if sum(digits[:2])%2==0: continue # 5
if check_prime(i): # 2
print(i)