Created
December 16, 2020 17:48
-
-
Save AlyoshaS/c6169b560fd7fd2f2b39b6565aa1ec9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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