Skip to content

Instantly share code, notes, and snippets.

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