Created
December 1, 2017 18:42
-
-
Save dstoza/2f78cd706f870ef61c76dad20af64884 to your computer and use it in GitHub Desktop.
This file contains 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 main() { | |
let ints: Vec<u8> = b"1234" | |
.into_iter() | |
.map(|c| c - 48) | |
.collect(); | |
let length = ints.len(); | |
let mut sum = 0; | |
for i in 0..length { | |
/* | |
if ints[i] == ints[(i + 1) % length] { | |
sum += i32::from(ints[i]); | |
} | |
*/ | |
if ints[i] == ints[(i + length / 2) % length] { | |
sum += i32::from(ints[i]); | |
} | |
} | |
println!("{}", sum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment