diff --git a/robot_sort/robot_sort.py b/robot_sort/robot_sort.py index db6b1985b..7384856a6 100644 --- a/robot_sort/robot_sort.py +++ b/robot_sort/robot_sort.py @@ -96,8 +96,31 @@ def sort(self): """ Sort the robot's list. """ - # Fill this out - pass + # What comes to mind is a bubble sort solution, using the light to 'store' if a swap has occured or not + self.set_light_on() + + while self.light_is_on(): + self.set_light_off() + self.swap_item() + + while self.can_move_right(): + self.move_right() + + if self.compare_item() == 1: + self.swap_item() + self.set_light_on() + + self.move_left() + self.swap_item() + self.move_right() + self.swap_item() + + # Return last item if item in hand + if self.compare_item() is None: + self.swap_item() + + while self.can_move_left(): + self.move_left() if __name__ == "__main__":