d3p1 optimized
This commit is contained in:
parent
ab9d8fb2b1
commit
e802d8dd91
@ -8,21 +8,17 @@ fn main() {
|
||||
let mut sum: u64 = 0;
|
||||
for line in input.lines() {
|
||||
let mut left_chars: HashSet<char> = HashSet::new();
|
||||
let mut dupe_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) {
|
||||
dupe_chars.insert(c);
|
||||
}
|
||||
}
|
||||
|
||||
for c in dupe_chars {
|
||||
if c >= 'a' && c <= 'z' {
|
||||
sum += (c as u64) - ('a' as u64) + 1;
|
||||
} else {
|
||||
sum += (c as u64) - ('A' as u64) + 27;
|
||||
if c >= 'a' && c <= 'z' {
|
||||
sum += (c as u64) - ('a' as u64) + 1;
|
||||
} else {
|
||||
sum += (c as u64) - ('A' as u64) + 27;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user