Skip to content

Instantly share code, notes, and snippets.

@dstoza
Created December 1, 2017 18:42
Show Gist options
  • Save dstoza/2f78cd706f870ef61c76dad20af64884 to your computer and use it in GitHub Desktop.
Save dstoza/2f78cd706f870ef61c76dad20af64884 to your computer and use it in GitHub Desktop.
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