-
-
Notifications
You must be signed in to change notification settings - Fork 46.2k
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
Remove duplicate implementation of Collatz sequence #8836
Remove duplicate implementation of Collatz sequence #8836
Conversation
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.
Looking cool! Do these changes effect performance?
@cclauss I don't think performance is really affected in most cases since the algorithm itself is basically unchanged. However, I think there'd be slightly better performance if one were to iterate over the algorithm's output: for num in collatz_sequence(n):
# do something with num since having a generator means not needing to create and store the entire sequence in memory. However, I haven't timed this generator implementation against the original list implementation, so I don't know how much of a difference it makes. |
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!
* updating DIRECTORY.md * Remove duplicate implementation of Collatz sequence * updating DIRECTORY.md * Add suggestions from PR review --------- Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Describe your change:
Fixes #8061
maths/3n_plus_1.py
in favor ofmaths/collatz_sequence.py
because the latter is the more well-known name for the problemmaths/3n_plus_1.py
tomaths/collatz_sequence.py
collatz_sequence
function to a generator to save memoryChecklist: