Browse Source

A little code cleanup

master
Timothy Warren 3 years ago
parent
commit
588ddb088d
  1. 18
      gcd/src/lib.rs
  2. 2
      iron-gcd/Cargo.toml
  3. 2
      iron-gcd/src/main.rs

18
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)]

2
iron-gcd/Cargo.toml

@ -5,7 +5,7 @@ authors = ["Timothy Warren <tim@timshomepage.net>"]
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"

2
iron-gcd/src/main.rs

@ -82,7 +82,7 @@ fn post_gcd(request: &mut Request) -> IronResult<Response> {
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 <B>{}</b>\n", numbers, d)
format!("The greatest common divisor of the numbers {:?} is <strong>{}</strong>\n", numbers, d)
);
Ok(response)

Loading…
Cancel
Save