-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Add perfect cube binary search #10477
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
Add perfect cube binary search #10477
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.
Could you modify your algorithm to support negative numbers? For instance, -27 = (-3)^3
Hi, thanks for the reply - I've made the changes, let me know if everything's OK now. To add support for negative perfect cubes to the other non binary search algorithm in the same file, I can open another PR. |
maths/perfect_cube.py
Outdated
>>> perfect_cube_binary_search("a") | ||
Traceback (most recent call last): | ||
... | ||
TypeError: '<=' not supported between instances of 'int' and 'str' |
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 add your own TypeError check for invalid inputs like this rather than relying on the built-in error message for <=
A TypeError check was added, thanks for the reply. |
Ugh, not this file again... |
Thanks for your contribution! |
* Add perfect cube binary search algorithm * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add support for testing negative perfect cubes * Add TypeError check for invalid inputs * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Describe your change:
This pull request adds a new algorithm within the existing perfect_cube.py file, including a doctest. While similar files such as perfect_square.py have added an improved time complexity binary search algorithm, perfect_cube.py lacks another faster algorithm that can be used as an alternative. This PR aims to bring the set of algorithms up to standard (such as perfect_square.py) with a new binary search implementation.
Checklist: