1
0
Fork 0
This commit is contained in:
Vivianne 2022-12-02 22:27:00 -08:00
parent 0db7712260
commit 74ecdd388c

View file

@ -1,9 +1,8 @@
#![feature(iterator_try_collect)]
use std::collections::HashSet;
use std::fs;
use std::io::{self, BufRead};
use std::collections::HashSet;
fn main() {
let filename = "etc/p03.txt";
@ -11,7 +10,10 @@ fn main() {
let reader = io::BufReader::new(file);
println!("PART ONE ---------------");
let lines: Vec<String> = reader.lines().try_collect().expect("Expected all lines to be valid");
let lines: Vec<String> = reader
.lines()
.try_collect()
.expect("Expected all lines to be valid");
part1(&lines);
println!("\n PART TWO ---------------");
@ -34,10 +36,13 @@ fn part1(lines: &[String]) {
let (left, right) = line.split_at(line.len() / 2);
let left_set: HashSet<char> = left.chars().collect();
let mut right_set = HashSet::<char>::new();
let outlier = right.chars().find(|c| {
right_set.insert(*c);
left_set.contains(c)
}).expect("Expected at least one duplicate item");
let outlier = right
.chars()
.find(|c| {
right_set.insert(*c);
left_set.contains(c)
})
.expect("Expected at least one duplicate item");
let priority = to_priority(outlier).unwrap();
println!("{} ({})", outlier, priority);
@ -47,8 +52,7 @@ fn part1(lines: &[String]) {
println!("Sum: {}", sum);
}
fn part2(_lines: &[String]) {
}
fn part2(_lines: &[String]) {}
#[cfg(test)]
mod tests {