1
0
Fork 0

Tiny tweak

This commit is contained in:
Vivianne 2022-12-02 22:36:14 -08:00
parent 74ecdd388c
commit 4c1bf47827
1 changed files with 7 additions and 3 deletions

View File

@ -1,4 +1,4 @@
#![feature(iterator_try_collect)]
#![feature(iterator_try_collect, iter_collect_into)]
use std::collections::HashSet;
use std::fs;
@ -32,10 +32,11 @@ fn to_priority(c: char) -> Result<u32, &'static str> {
fn part1(lines: &[String]) {
let mut sum: u32 = 0;
let mut left_set = HashSet::<char>::new();
let mut right_set = HashSet::<char>::new();
for line in lines {
let (left, right) = line.split_at(line.len() / 2);
let left_set: HashSet<char> = left.chars().collect();
let mut right_set = HashSet::<char>::new();
left.chars().collect_into(&mut left_set);
let outlier = right
.chars()
.find(|c| {
@ -47,6 +48,9 @@ fn part1(lines: &[String]) {
let priority = to_priority(outlier).unwrap();
println!("{} ({})", outlier, priority);
sum += priority;
left_set.clear();
right_set.clear();
}
println!("Sum: {}", sum);