euclidean_algo

Crates.ioeuclidean_algo
lib.rseuclidean_algo
version0.3.1
sourcesrc
created_at2024-04-09 15:06:39.052481
updated_at2024-04-09 21:36:53.0495
descriptionImplementation of the euclidean algorithm to find the greatest common divisor.
homepage
repositoryhttps://github.com/CarlosGRodriguezL/euclidean_algo
max_upload_size
id1202519
size10,408
Carlos Rodriguez (CarlosGRodriguezL)

documentation

README

Euclidean algorithm

There are two ways of implementing the euclidean algorithm. In the first a very simple function is called recursivly. The second is a function that is looping and manipulating the integer.

The main.rs is providing a binary, to test the two approaches and compare their runtime.

The function can be used by adding the dependency to the Cargo.toml and importing the function.

use crate::euclidean_algo::{eucl_algo_recursive, eucl_algo_loop};

// As with Rust adding integer to a function we are provided by a copy and don't need to make the initial integer to mutable them to mutable.
let x: u64 = 15;
let y: u64 = 30;

let gcd_recursive = eucl_algo_recursive::run(x,y);
let gcd_loop = eucl_algo_loop::run(x,y);

println!("The gcd is {gcd_recursive} (loop: {gcd_loop})");

For bigger integers a run_big function is provided. You can call ::run_bigint(x,y) instead of run, using num::BigUint to process bigger numbers.

Commit count: 14

cargo fmt