clean up part 2 a bit

This commit is contained in:
David 2022-12-03 09:04:06 -05:00
parent 51525f1e93
commit 894ddd8ca7

View File

@ -1,10 +1,10 @@
#![allow(dead_code)]
use std::collections::hash_map::RandomState;
use std::collections::HashMap;
use std::collections::HashSet;
use std::fs::File;
use std::io;
use std::io::BufRead;
use std::iter::FromIterator;
use std::path::Path;
use std::time::Instant;
@ -64,10 +64,7 @@ fn part_two() {
for line in lines {
if let Ok(contents) = line {
// build the group
let mut knapsack = HashSet::new();
for item in contents.chars() {
knapsack.insert(item);
}
let knapsack = HashSet::from_iter(contents.chars());
group.push(knapsack);
if group.len() != 3 {
continue;
@ -75,14 +72,13 @@ fn part_two() {
if let (Some(one), Some(two), Some(three)) =
(group.get(0), group.get(1), group.get(2))
{
let intermediate_one: _ = two
.intersection(three)
.collect::<HashSet<&char, RandomState>>();
let intermediate_two: _ = one
.intersection(three)
.collect::<HashSet<&char, RandomState>>();
let intermediate_one: HashSet<&char> =
HashSet::from_iter(two.intersection(three));
let intermediate_two: HashSet<&char> =
HashSet::from_iter(one.intersection(three));
let mut result = intermediate_one.intersection(&intermediate_two);
if let Some(item) = result.next() {
// double pointers!
if **item as u32 > 96 {
priorities += **item as u32 - 96
} else {