Skip to content

Instantly share code, notes, and snippets.

@chutten
Created December 1, 2017 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chutten/13bcfcf32fea203af4e28b20f6df4276 to your computer and use it in GitHub Desktop.
Save chutten/13bcfcf32fea203af4e28b20f6df4276 to your computer and use it in GitHub Desktop.
dec1 part 2
use std::io;
fn main() {
let mut captcha = String::new();
io::stdin().read_line(&mut captcha)
.expect("Failed to read line");
let captcha = captcha.trim();
let mut chars = captcha.chars().cycle();
let mut total: u32 = 0;
for _ in 0..captcha.len() {
let c = chars.next();
match chars.nth(captcha.len() / 2 - 1) {
Some(d) if Some(d) == c => {
total += d.to_string().parse()
.expect("Failed to parse digit");
},
_ => (),
}
}
println!("Total: {}", total);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment