Skip to content

Instantly share code, notes, and snippets.

@AngelOnFira
Created November 20, 2020 15:14
Show Gist options
  • Select an option

  • Save AngelOnFira/a92328c71d8024d9c4a61df1f4f2f93f to your computer and use it in GitHub Desktop.

Select an option

Save AngelOnFira/a92328c71d8024d9c4a61df1f4f2f93f to your computer and use it in GitHub Desktop.
pub fn gcd(numbers: Vec<i32>) -> i32 {
let mut lcd = *numbers.iter().max().unwrap();
for i in 0..(numbers.len()) {
let mut x: i32 = lcd;
let mut y: i32 = numbers[i];
lcd = {
while y != 0 {
let temp = x % y;
x = y;
y = temp;
}
x
}
}
lcd
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment