From 588ddb088d412e2f48f76751350ffa1f3b51e48c Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 27 Feb 2019 12:58:02 -0500 Subject: [PATCH] A little code cleanup --- gcd/src/lib.rs | 18 +++++++++--------- iron-gcd/Cargo.toml | 2 +- iron-gcd/src/main.rs | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/gcd/src/lib.rs b/gcd/src/lib.rs index cad9dc9..c2dd1b2 100644 --- a/gcd/src/lib.rs +++ b/gcd/src/lib.rs @@ -1,16 +1,16 @@ -pub fn gcd(mut n: u64, mut m: u64) -> u64 { - assert!(n != 0 && m != 0); +pub fn gcd(mut a: u64, mut b: u64) -> u64 { + assert!(a != 0 && b != 0); - while m != 0 { - if m < n { - let t = m; - m = n; - n = t; + while b != 0 { + if b < a { + let temp = b; + b = a; + a = temp; } - m = m % n; + b = b % a; } - n + a } #[cfg(test)] diff --git a/iron-gcd/Cargo.toml b/iron-gcd/Cargo.toml index 59778f9..f518625 100644 --- a/iron-gcd/Cargo.toml +++ b/iron-gcd/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Timothy Warren "] edition = "2018" [dependencies] -gcd = { path = "../gcd", version = "0.1.0" } +gcd = { path = "../gcd" } iron = "0.5.1" mime = "0.2.3" router = "0.5.1" diff --git a/iron-gcd/src/main.rs b/iron-gcd/src/main.rs index cbb21df..af4a6b3 100644 --- a/iron-gcd/src/main.rs +++ b/iron-gcd/src/main.rs @@ -82,7 +82,7 @@ fn post_gcd(request: &mut Request) -> IronResult { response.set_mut(status::Ok); response.set_mut(mime!(Text/Html; Charset=Utf8)); response.set_mut( - format!("The greatest common divisor of the numbers {:?} is {}\n", numbers, d) + format!("The greatest common divisor of the numbers {:?} is {}\n", numbers, d) ); Ok(response)