Skip to content

Instantly share code, notes, and snippets.

@fay59
Created December 15, 2017 17:44
Show Gist options
  • Save fay59/c3a222f3daf199790e99c18362d0d05b to your computer and use it in GitHub Desktop.
Save fay59/c3a222f3daf199790e99c18362d0d05b to your computer and use it in GitHub Desktop.
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