Skip to content

adding input option and increasing the number of doctest #1281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 6, 2019
Merged
Changes from 1 commit
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
19 changes: 15 additions & 4 deletions sorts/stooge_sort.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
def stooge_sort(arr):
"""
>>> arr = [2, 4, 5, 3, 1]
>>> stooge_sort(arr)
>>> print(arr)
[1, 2, 3, 4, 5]
Examples:
>>> stooge_sort([0, 5, 3, 2, 2])
[0, 2, 2, 3, 5]

>>> stooge_sort([])
[]

>>> stooge_sort([-2, -5, -45])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good but let’s mix positive int, positive float, zero, negative int, and negative float all in one test.

[-45, -5, -2]
"""
stooge(arr, 0, len(arr) - 1)
return arr


def stooge(arr, i, h):
Expand All @@ -29,3 +35,8 @@ def stooge(arr, i, h):

# Recursively sort first 2/3 elements
stooge(arr, i, (h - t))

if __name__ == "__main__":
user_input = input("Enter numbers separated by a comma:\n").strip()
unsorted = [int(item) for item in user_input.split(",")]
print(stooge_sort(unsorted))