-
Notifications
You must be signed in to change notification settings - Fork 1
/
exercise_13.py
39 lines (32 loc) · 1.01 KB
/
exercise_13.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
#!/usr/bin/env python
import unittest
class TestRotationPoint(unittest.TestCase):
def find_rotation_point(self, words):
# aaabcd
# aaabbc
# find first letter between `a`, and `b` that is different
# the first letter that is different. if `b` is greater, than skip to next item
# if `b` at the index is less than, that is the rotation point
char_of_words = [ list(word) for word in words ]
for i, item in enumerate(char_of_words[:-1]):
for letter_index, letter in enumerate(char_of_words[i]):
if letter < char_of_words[i+1][letter_index]:
break
else:
return i + 1
def setUp(self):
self.words = [
'ptolemaic',
'retrograde',
'supplant',
'undulate',
'xenoepist',
'asymptote', # <-- rotates here!
'babka',
'banoffee',
'engender',
'karpatka',
'othellolagkage',
]
def test_find_rotation_point(self):
self.assertEquals(self.find_rotation_point(self.words),5)