Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions robot_sort/robot_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down