diff --git a/recursive_count_th/count_th.py b/recursive_count_th/count_th.py index 07456a00b..ecad6ac16 100644 --- a/recursive_count_th/count_th.py +++ b/recursive_count_th/count_th.py @@ -5,6 +5,15 @@ ''' def count_th(word): - # TBC + # Verify if the length of the word is not less than "th"; else, it contains it - pass + if len(word) < len('th'): + return 0 + + #Furthermore, verify if the first two letters equals "th", return 1 + elif word[:2] == 'th': + return count_th(word[2:]) + 1 + + #Else, proceed with the next letter of the word + else: + return count_th(word[1:]) diff --git a/robot_sort/robot_sort.py b/robot_sort/robot_sort.py index db6b1985b..81c5df273 100644 --- a/robot_sort/robot_sort.py +++ b/robot_sort/robot_sort.py @@ -97,7 +97,28 @@ def sort(self): Sort the robot's list. """ # Fill this out - pass + self.set_light_on() + + while self.light_is_on(): + self.set_light_off() + + while self.can_move_right(): + self.move_right() + + if self.compare_item() == 1: + self.swap_item() + self.set_light_on() + + while self.can_move_left(): + self.swap_item() + self.move_left() + + if self.compare_item() == -1: + self.swap_item() + self.set_light_on() + self.move_right() + self.swap_item() + self.move_left() if __name__ == "__main__":