From 45c2b9783505235d868e3e6e956acf55d810e0b6 Mon Sep 17 00:00:00 2001 From: Joshua Chinchilla Date: Sat, 10 Oct 2020 10:28:41 -0700 Subject: [PATCH] completed mvp --- robot_sort/robot_sort.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) 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__":