Skip to content
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

Perfect Cube Implementation #651

Merged
merged 7 commits into from
Jan 8, 2024
Merged

Perfect Cube Implementation #651

merged 7 commits into from
Jan 8, 2024

Conversation

octavianarmasu
Copy link
Contributor

Description

The perfect cube function provides two functions to check if a given number is a perfect cube.

perfect_cube(n: i32) -> bool

  • Checks if a number is a perfect cube using floating-point arithmetic.
  • Calculates the cube root of the given number and checks if cubing it equals the original number.

perfect_cube_binary_search(n: i64) -> bool

  • Checks if a number is a perfect cube using binary search.
  • Handles negative numbers by returning false for negative inputs.
  • Performs a binary search to find the cube root within the range [0, abs(n)].

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I ran bellow commands using the latest version of rust nightly.
  • I ran cargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.
  • I ran cargo fmt just before my last commit.
  • I ran cargo test just before my last commit and all tests passed.
  • I added my algorithm to the corresponding mod.rs file within its own folder, and in any parent folder(s).
  • I added my algorithm to DIRECTORY.md with the correct link.
  • I checked COUNTRIBUTING.md and my code follows its guidelines.

@codecov-commenter
Copy link

codecov-commenter commented Jan 8, 2024

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (3a1724d) 94.58% compared to head (2cdd4d8) 94.56%.

Files Patch % Lines
src/math/perfect_cube.rs 86.36% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #651      +/-   ##
==========================================
- Coverage   94.58%   94.56%   -0.02%     
==========================================
  Files         283      284       +1     
  Lines       22801    22845      +44     
==========================================
+ Hits        21566    21604      +38     
- Misses       1235     1241       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@octavianarmasu octavianarmasu marked this pull request as ready for review January 8, 2024 12:07
Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@siriak siriak merged commit 5f1c45a into TheAlgorithms:master Jan 8, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants