Skip to content

Commit 40e427d

Browse files
author
KitN
committed
Adding a few Exrcz on search
1 parent f98ae16 commit 40e427d

3 files changed

Lines changed: 147 additions & 10 deletions

File tree

‎exersizes/cartalk2.py‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
def first(word):
2+
"""Returns the first character of a string."""
3+
return word[0]
4+
5+
def last(word):
6+
"""Returns the last of a string."""
7+
return word[-1]
8+
9+
def middle(word):
10+
"""Returns all but the first and last characters of a string."""
11+
return word[1:-1]
12+
13+
def is_palindrome(word):
14+
"""Returns True if word is a palindrome."""
15+
if len(word) <= 1:
16+
return True
17+
if first(word) != last(word):
18+
return False
19+
return is_palindrome(middle(word))
20+
21+
if __name__=="__main__":
22+
for n in range(100000, 1000000):
23+
numstring = str(n)
24+
lastfour = numstring[-4:]
25+
lastfive = str(n+1)[-5:]
26+
middlefour = str(n+2)[1:5]
27+
allsix = str(n+3)
28+
flag = True
29+
for stage in (lastfour, lastfive, middlefour, allsix):
30+
if is_palindrome(stage):
31+
continue
32+
else:
33+
flag = False
34+
break
35+
if flag:
36+
print(n)
37+

‎exersizes/cartalk3.py‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
def first(word):
2+
"""Returns the first character of a string."""
3+
return word[0]
4+
5+
def last(word):
6+
"""Returns the last of a string."""
7+
return word[-1]
8+
9+
def middle(word):
10+
"""Returns all but the first and last characters of a string."""
11+
return word[1:-1]
12+
13+
def is_palindrome(word):
14+
"""Returns True if word is a palindrome."""
15+
if len(word) <= 1:
16+
return True
17+
if first(word) != last(word):
18+
return False
19+
return is_palindrome(middle(word))
20+
21+
def is_reverse(x,y):
22+
""" If two ages are the reverse of eachother, returns True."""
23+
stringx = str(x).zfill(2)
24+
stringy = str(y).zfill(2)
25+
if (stringx[0] == stringy[1] and
26+
stringx[1] == stringy[0]):
27+
return True
28+
else:
29+
return False
30+
31+
32+
agetuples = [
33+
(5, 19),
34+
(30, 3),
35+
(81, 18),
36+
(99, 50)
37+
]
38+
for pair in agetuples:
39+
print(is_reverse(pair[0], pair[1]))
40+
41+
for gap in range(16, 80):
42+
mom_age = gap
43+
kid_age = 0
44+
count = 0
45+
while mom_age < 100:
46+
if is_reverse(mom_age, kid_age):
47+
count += 1
48+
print(mom_age, kid_age)
49+
mom_age += 1
50+
if is_reverse(mom_age, kid_age):
51+
count += 1
52+
print(mom_age, kid_age)
53+
kid_age += 1
54+
if count >= 8:
55+
print(gap)

‎exersizes/moby.py‎

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,60 @@ def has_no_e(word):
88
return False
99
return True
1010

11-
with open(filepath) as wrdfile:
12-
number_of_words = 0
13-
no_e_words = 0
14-
for line in wrdfile:
15-
number_of_words += 1
16-
stripped = line.strip()
17-
if has_no_e(stripped):
18-
no_e_words += 1
11+
def avoids(word, taboos="xyz"):
12+
for letter in word:
13+
if letter in taboos:
14+
return False
15+
return True
16+
17+
def abecedarian(word):
18+
for letter in range(1, len(word)):
19+
n = word[letter]
20+
p = word[letter-1]
21+
follows = ord(n) > ord(p)
22+
if follows:
23+
continue
1924
else:
20-
pass
25+
return False
26+
return True
27+
28+
def tripledouble(word):
29+
if len(word) < 6:
30+
return False
31+
startplaces = (len(word) % 6) + 1
32+
for i in range(startplaces):
33+
section = word[i:i+6]
34+
if isnapoleon(section):
35+
return True
36+
return False
37+
38+
def isnapoleon(word):
39+
"""Only takes a six character string"""
40+
one = word[0] == word[1]
41+
two = word[2] == word[3]
42+
thr = word[4] == word[5]
43+
if one and two and thr:
44+
return True
45+
else:
46+
return False
47+
48+
49+
forbidfives = [
50+
"quxyz",
51+
"xyzwh",
52+
"qvxyz"
53+
]
2154

22-
print(no_e_words/number_of_words)
55+
if __name__=="__main__":
56+
print(avoids('manpage'))
57+
with open(filepath) as wrdfile:
58+
number_of_words = 0
59+
avoided = 0
60+
for line in wrdfile:
61+
number_of_words += 1
62+
stripped = line.strip()
63+
if tripledouble(stripped):
64+
print(stripped)
65+
else:
66+
pass
67+
print(avoided/number_of_words)

0 commit comments

Comments
 (0)