Created
December 15, 2017 17:44
-
-
Save fay59/c3a222f3daf199790e99c18362d0d05b 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 digits_to_vec(digits: String) -> Vec<u32> { | |
let mut result = Vec::new(); | |
for c in digits.chars() { | |
match c.to_digit(10) { | |
Some(v) => result.push(v), | |
None => {} | |
} | |
} | |
return result; | |
} | |
fn main() { | |
let mut digits_string = String::new(); | |
std::io::stdin().read_line(&mut digits_string).expect("wtf?"); | |
let digits = digits_to_vec(digits_string); | |
let length = digits.len(); | |
let halfway = length / 2; | |
let mut compare_to = Vec::new(); | |
compare_to.extend(digits[halfway..length].iter().cloned()); | |
compare_to.extend(digits[0..halfway].iter().cloned()); | |
let mut result = 0; | |
for (a, b) in digits.iter().zip(compare_to.iter()) { | |
if a == b { | |
result += a; | |
} | |
} | |
println!("{}", result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment