diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2017-05-10 22:02:56 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2017-05-10 22:13:49 +0300 |
commit | d0577298fd2be72ec4e51ae4703ec563e63119a6 (patch) | |
tree | 1ce2398878510d7eccbf540e343da217df0876a9 | |
parent | 65ed5fb564d11a2f36bc5ce8e63daca48c9bc919 (diff) | |
download | gcd-d0577298fd2be72ec4e51ae4703ec563e63119a6.tar.gz |
Rust
-rw-r--r-- | gcd.rs | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -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); +} + |