Created
December 15, 2017 17:43
-
-
Save fay59/25056c69f1ed890e83c19da29d73de47 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 mut sum = 0; | |
let mut last = digits[digits.len() - 1]; | |
for digit in digits { | |
if digit == last { | |
sum += digit; | |
} | |
last = digit; | |
} | |
println!("{}", sum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment