summaryrefslogtreecommitdiff
path: root/gcd.rs
blob: a07377b717fc6276a3498199ee3beed85f89716b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use std::env;

fn gcd2(mut a: u64, mut b: u64) -> u64
{
  while b != 0 {
    let c = b;
    b = a % b;
    a = c;
  }

  a
}


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, gcd2);

  println!("{}", gcd);
}