summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2017-05-10 22:02:56 +0300
committerIgor Pashev <pashev.igor@gmail.com>2017-05-10 22:13:49 +0300
commitd0577298fd2be72ec4e51ae4703ec563e63119a6 (patch)
tree1ce2398878510d7eccbf540e343da217df0876a9
parent65ed5fb564d11a2f36bc5ce8e63daca48c9bc919 (diff)
downloadgcd-d0577298fd2be72ec4e51ae4703ec563e63119a6.tar.gz
Rust
-rw-r--r--gcd.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/gcd.rs b/gcd.rs
new file mode 100644
index 0000000..9e73a44
--- /dev/null
+++ b/gcd.rs
@@ -0,0 +1,27 @@
+use std::env;
+
+fn gcd2(a: u64, b: u64) -> u64
+{
+ let mut a1 = a;
+ let mut b1 = b;
+
+ while b1 != 0 {
+ let c1 = b1;
+ b1 = a1 % b1;
+ a1 = c1;
+ }
+
+ a1
+}
+
+
+fn main ()
+{
+ // XXX skip(1) to skip program name:
+ let nums = env::args().skip(1).map(|s| s.parse().unwrap());
+
+ let gcd = nums.fold(0, |g, n| gcd2(g, n));
+
+ println!("{}", gcd);
+}
+