-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Added bead sort #2022
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
Added bead sort #2022
Conversation
sorts/bead_sort.py
Outdated
|
||
def bead_sort(sequence: list) -> list: | ||
""" | ||
>>> bead_sort([6,11, 12, 4, 1, 5]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> bead_sort([6,11, 12, 4, 1, 5]) | |
>>> bead_sort([6, 11, 12, 4, 1, 5]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please test [1, .9, 0.0, 0, -1, -.9] and "Hello World!"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering on "Hello world" ordering. Theory says that algorithm should be use for positive integers. I think checking types inside sort function is not efficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After a few moments, I decide to write two checks for it. I don't want to argue with the theory! 😄 @cclauss maybe you have a better idea for this?
sorts/bead_sort.py
Outdated
if isinstance(sequence, str): | ||
raise TypeError("Sequence must be list of positive integers") | ||
|
||
if min(sequence) < 0: | ||
raise TypeError("Sequence must be list of positive integers") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not sort these things? They should work just fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
* Added bead sort * Commit suggestion * Added checking before sort * Bead sort only works for sequences of nonegative integers Co-authored-by: Christian Clauss <cclauss@me.com>
Describe your change:
Added bead sort aka gravity sort
Checklist:
Fixes: #{$ISSUE_NO}
.