-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise_9_back.py
68 lines (50 loc) · 1.49 KB
/
exercise_9_back.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
from binary_search import make_word_list
def is_palindrome(word, start, length):
new_w = str(word)[start:(start + length)]
return new_w == new_w[::-1]
def has_three_consecutive_doubles(word):
i = 0
count = 0
string = ''
while i < len(word) - 1:
letter = word[i]
next_letter = word[i + 1]
if letter == next_letter:
count += 1
string += letter + next_letter
i += 1
return count == 3 and string in word
def odometer_puzzle(num1):
if is_palindrome(num1, 2, 4) and is_palindrome(num1 + 1, 1, 5) and is_palindrome(num1 + 2, 1, 4) and is_palindrome(
num1 + 3, 0, 6):
return num1
else:
return "No such numbers found"
def age_diff_puzzle(my_age):
new_my_age = str(my_age)
if len(new_my_age) == 1:
new_son_age = new_my_age.zfill(2)
mom_age = int(new_son_age[::-1])
else:
mom_age = int(new_my_age[::-1])
if mom_age - my_age == 18:
return my_age
else:
return "Not found"
# Fetch standard word list
word_list = make_word_list()
'''
# Get words which have three consecutive double letters
new_list = []
for word in word_list:
if has_three_consecutive_doubles(word):
new_list.append(word)
print(len(new_list), new_list)
# Enumerates all 6 digit numbers
for i in range(100000, 1000000):
if odometer_puzzle(i) == i:
print(i)
for age in range(1, 100):
if age_diff_puzzle(age) == age:
print(age)
'''