Created
December 1, 2017 16:20
-
-
Save chutten/13bcfcf32fea203af4e28b20f6df4276 to your computer and use it in GitHub Desktop.
dec1 part 2
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
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