From 5a5cae93a325e9eb73b3c9e56fd7813ef4e04947 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Tue, 28 Apr 2020 13:49:52 +0200 Subject: Eliminate temp vars --- gcd.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/gcd.rs b/gcd.rs index 9e73a44..7b5e753 100644 --- a/gcd.rs +++ b/gcd.rs @@ -1,17 +1,14 @@ use std::env; -fn gcd2(a: u64, b: u64) -> u64 +fn gcd2(mut a: u64, mut b: u64) -> u64 { - let mut a1 = a; - let mut b1 = b; - - while b1 != 0 { - let c1 = b1; - b1 = a1 % b1; - a1 = c1; + while b != 0 { + let c = b; + b = a % b; + a = c; } - a1 + a } -- cgit v1.2.3