-
Notifications
You must be signed in to change notification settings - Fork 4
/
whats_my_number.py
73 lines (57 loc) · 2.07 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def recursive():
def whats_my_num(primes, current, i):
if "1" not in str(primes[current]) and "7" not in str(primes[current]):
sum = 0
for digit in str(primes[current]):
sum += int(digit)
if sum <= 10:
first = str(primes[current])[0]
second = str(primes[current])[1]
last = str(primes[current])[-1]
if (int(first) + int(second)) % 2 > 0 and int(last) == len(str(primes[current])):
second_to_last = str(primes[current])[1]
if int(second_to_last) % 2 == 0 and int(second_to_last) > 1:
return primes[current]
return whats_my_num(primes, current + 1, 2)
primes = []
for num in range(10, 1000):
for i in range(2,num + 1):
if i == num and "1" not in str(num) and "7" not in str(num):
primes.append(num)
elif (num % i) == 0:
break
print(whats_my_num(primes,0,2))
def do_a_loop():
primes = []
for num in range(10,1000 + 1):
for i in range(2,num + 1):
if i == num and "1" not in str(num) and "7" not in str(num):
primes.append(num)
elif (num % i) == 0:
break
less_or_equal = []
for num in primes:
sum = 0
for digit in str(num):
sum += int(digit)
if sum <= 10:
less_or_equal.append(num)
else:
continue
first_and_last = []
for num in less_or_equal:
first = str(num)[0]
second = str(num)[1]
last = str(num)[-1]
if (int(first) + int(second)) % 2 > 0 and int(last) == len(str(num)):
first_and_last.append(num)
else:
continue
for num in first_and_last:
second_to_last = str(num)[1]
if int(second_to_last) % 2 == 0 and int(second_to_last) > 1:
print(num)
print("Using 2 loops and recursion:")
recursive()
print("Using a mess of loops:")
do_a_loop()