Last active
June 11, 2023 01:24
-
-
Save RIGIK93/ecb96d61af2eb809e15f80f7aeec2f4e to your computer and use it in GitHub Desktop.
Euclidean algorithm for computing greatest common divisor in rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use num::traits::{Zero, Rem}; | |
fn gcd<T>(a: T, b: T) -> T | |
where | |
T: Zero + Rem<Output = T> + std::cmp::PartialEq + Copy, | |
{ | |
if b == T::zero() { | |
return a; | |
} | |
gcd(b, a % b) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment