-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add Euler's Totient
function implementation
#875
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #875 +/- ##
=======================================
Coverage 95.49% 95.49%
=======================================
Files 316 317 +1
Lines 22919 22948 +29
=======================================
+ Hits 21887 21915 +28
- Misses 1032 1033 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
This functionality is (almost) provided by compute_totient.rs
. Both implementations are similarly efficient. @siriak what do you suggest?
/// Calculate the **Euler's Totient** function of a given number `n`. | ||
/// | ||
/// Uncyclopedia: https://en.wikipedia.org/wiki/Euler%27s_totient_function | ||
pub fn euler_totient(mut n: i64) -> i64 { |
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.
What do you think about having the following signature:
pub fn euler_totient(mut n: i64) -> i64 { | |
pub fn euler_totient(n: u64) -> Result<u64, &'static str> { |
assert_eq!(euler_totient(1), 1); | ||
assert_eq!(euler_totient(325), 240); | ||
assert_eq!(euler_totient(746), 372); | ||
assert_eq!(euler_totient(3_639), 2_424); | ||
assert_eq!(euler_totient(98_354), 49_176); | ||
assert_eq!(euler_totient(123_456), 41_088); | ||
assert_eq!(euler_totient(493_123_235), 347_518_080); | ||
assert_eq!(euler_totient(945_243_784_032), 315_074_904_192); | ||
assert_eq!(euler_totient(372_036_854_775_808), 185_661_377_740_800); |
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.
What do you think about having more parametrized approach like in test_aliquot_sum
.
Oops! I hadn’t noticed this algorithm was already here. Thanks for pointing it out! Closing the PR. |
Adds the implementation of the Euler's Totient function with a unit test.
Type of change
Checklist:
cargo clippy --all -- -D warnings
just before my last commit and fixed any issue that was found.cargo fmt
just before my last commit.cargo test
just before my last commit and all tests passed.mod.rs
file within its own folder, and in any parent folder(s).DIRECTORY.md
with the correct link.COUNTRIBUTING.md
and my code follows its guidelines.