Skip to content

Instantly share code, notes, and snippets.

@AlyoshaS
Created December 16, 2020 17:48
Show Gist options
  • Save AlyoshaS/c6169b560fd7fd2f2b39b6565aa1ec9e to your computer and use it in GitHub Desktop.
Save AlyoshaS/c6169b560fd7fd2f2b39b6565aa1ec9e to your computer and use it in GitHub Desktop.
fn sum_or_product(list: &[i64], n: usize) -> String {
let first_numbers: &[i64] = &list[0 .. n];
let last_numbers: &[i64] = &list[list.len() - n.. list.len()] ;
let sum:i64 = first_numbers.iter().sum();
let product:i64 = last_numbers.iter().product();
if sum > product {
return println!("sum")
} else {
return "product"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment