29 lines
716 B
Rust
29 lines
716 B
Rust
|
use std::env;
|
||
|
use std::fs;
|
||
|
use std::collections::HashSet;
|
||
|
|
||
|
fn main() {
|
||
|
let input = fs::read_to_string(&env::args().nth(1).unwrap()).unwrap();
|
||
|
|
||
|
let mut sum: u64 = 0;
|
||
|
for line in input.lines() {
|
||
|
let mut left_chars: HashSet<char> = HashSet::new();
|
||
|
|
||
|
for (i, c) in line.char_indices() {
|
||
|
if i < line.len()/2 {
|
||
|
left_chars.insert(c);
|
||
|
} else if left_chars.contains(&c) {
|
||
|
if c >= 'a' && c <= 'z' {
|
||
|
sum += (c as u64) - ('a' as u64) + 1;
|
||
|
} else {
|
||
|
sum += (c as u64) - ('A' as u64) + 27;
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
println!("{:?}", sum);
|
||
|
}
|
||
|
|