<commit_before>"""
 Problem 13

"""
import unittest


def find_rotation(word_list):
    lower_bound = 0
    upper_bound = len(word_list) - 1
    while True:
        split_point = (upper_bound + lower_bound) // 2
        if word_list[split_point] < word_list[upper_bound]:
            upper_bound = split_point
        if word_list[split_point] > word_list[lower_bound]:
            lower_bound = split_point
        if upper_bound == lower_bound:
            return -1
        if upper_bound - lower_bound == 2:
            return lower_bound + 1


class MyTestCase(unittest.TestCase):
    def test_find_rotation(self):
        words = ['ptomeaic',
                 'retrograde',
                 'supplant',
                 'undulate',
                 'xenoepist',
                 'asymptote',
                 'babka',
                 'banoffee',
                 'engender',
                 'karpatka',
                 'othellolagkage']
        self.assertEqual(find_rotation(words), 4)
        words = ['a',
                 'b',
                 'c',
                 'd',
                 'e',
                 'f']
        self.assertEqual(find_rotation(words), -1)<commit_msg>Feat: Simplified the algorithm and took care of an edge case where there are no rotations<commit_after>"""
 Problem 13

"""
import unittest


def find_rotation(word_list):
    lower_bound = 0
    upper_bound = len(word_list) - 1
    fird_word = word_list[0]

    while lower_bound < upper_bound:
        mid_point = lower_bound + (upper_bound-lower_bound) // 2
        if word_list[lower_bound] < word_list[mid_point]:
            lower_bound = mid_point
        else:
            upper_bound = mid_point
        if lower_bound + 1 == upper_bound:
            if word_list[lower_bound] < word_list[upper_bound]:
                return -1
            return lower_bound


class MyTestCase(unittest.TestCase):
    def test_find_rotation(self):
        words = ['ptomeaic',
                 'retrograde',
                 'supplant',
                 'undulate',
                 'xenoepist',
                 'asymptote',
                 'babka',
                 'banoffee',
                 'engender',
                 'karpatka',
                 'othellolagkage']
        self.assertEqual(find_rotation(words), 4)
        words = ['g',
                 'a',
                 'b',
                 'c',
                 'd',
                 'e',
                 'f']
        self.assertEqual(find_rotation(words), 0)
        words = ['a',
                 'b',
                 'c',
                 'd',
                 'e',
                 'f']
        self.assertEqual(find_rotation(words), -1)
{'fraction_non_alphanumeric': 0.10244988864142539, 'fraction_numerical': 0.0077951002227171495, 'mean_word_length': 1.3702726473175022, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7646997', 'n_tokens_mistral': 774, 'n_tokens_neox': 738, 'n_words': 158}