parent
2f86fd2dec
commit
7b93826c56
@ -0,0 +1,46 @@
|
||||
|
||||
|
||||
use crate::Problem;
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub struct Problem7 {
|
||||
groups: Vec<HashSet<char>>,
|
||||
}
|
||||
|
||||
|
||||
impl Problem7 {}
|
||||
|
||||
impl Problem for Problem7 {
|
||||
fn new(input: &String) -> Self {
|
||||
Problem7 {
|
||||
groups: input
|
||||
.split("\n\n")
|
||||
.filter_map(|s| {
|
||||
let s = s.trim().split("\n");
|
||||
let mut sets = Vec::new();
|
||||
for i in s {
|
||||
let v : HashSet<char> = i.chars().filter_map(|c| {
|
||||
if c.is_whitespace() {
|
||||
None
|
||||
} else {
|
||||
Some(c)
|
||||
}
|
||||
}).collect::<HashSet<char>>();
|
||||
sets.push(v);
|
||||
}
|
||||
let mut iter = sets.iter();
|
||||
let intersection : HashSet<char> =
|
||||
iter.next().map(|set| iter.fold(set.clone(), |set1, set2| set1.intersection(set2).map(|c| *c).collect())).unwrap().clone();
|
||||
Some(intersection)
|
||||
}).collect(),
|
||||
}
|
||||
}
|
||||
|
||||
fn run_part1(&self) {
|
||||
|
||||
}
|
||||
|
||||
fn run_part2(&self) {
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
pub mod lib;
|
Loading…
Reference in new issue