Skip to content
Snippets Groups Projects
Commit f08d2b4d authored by Mihails VALTUSOVS's avatar Mihails VALTUSOVS :speech_balloon:
Browse files

gcd

parent 406ec9ff
No related branches found
No related tags found
No related merge requests found
/* gcd.rs
* Part of the Mental Poker project
* Course: MAA313-2020
* Members: Mihails Valtusovs,
* William Koch
* Olavi Äikäs
* See git history for contributions
*/
// use num_bigint::{ToBigUint, BigUint};
use num_bigint::BigUint;
use num_traits::Zero;
// use partial_application::partial!;
pub fn compute(a: &BigUint, b: &BigUint) -> BigUint {
return euclidean(a, b);
}
pub fn euclidean(a: &BigUint, b: &BigUint) -> BigUint {
// println!("euclidean {} {}", a, b);
if a > b {
if b.is_zero() {
let a : BigUint = a.clone();
return a;
}
return euclidean(b, &(a%b));
} else {
if a.is_zero() {
let b : BigUint = b.clone();
return b;
}
return euclidean(a, &(b%a));
}
}
\ No newline at end of file
use num_bigint::{ToBigUint, BigUint};
// use crate::jacobi::jacobi;
mod gcd;
fn main() {
let (m, n) = (1236u32.to_biguint(), 20003u32.to_biguint());
match (m, n) {
(Some(x), Some(y)) => println!("{} == 1",gcd::compute(&x,&y)),
_ => println!("Conversion failed!")
}
let (m, n) = (98u32.to_biguint(), 56u32.to_biguint());
match (m, n) {
(Some(x), Some(y)) => println!("{} == 14",gcd::compute(&x,&y)),
_ => println!("Conversion failed!")
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment