problem 7 template

master
mitchellhansen 4 years ago
parent 2f86fd2dec
commit 7b93826c56

@ -7,6 +7,7 @@ use crate::problem3::lib::Problem3;
use crate::problem4::lib::Problem4; use crate::problem4::lib::Problem4;
use crate::problem5::lib::Problem5; use crate::problem5::lib::Problem5;
use crate::problem6::lib::Problem6; use crate::problem6::lib::Problem6;
use crate::problem7::lib::Problem7;
mod problem1; mod problem1;
mod problem2; mod problem2;
@ -14,6 +15,7 @@ mod problem3;
mod problem4; mod problem4;
mod problem5; mod problem5;
mod problem6; mod problem6;
mod problem7;
mod util; mod util;
@ -47,7 +49,11 @@ fn main() {
// problem5.run_part1(); // problem5.run_part1();
// problem5.run_part2(); // problem5.run_part2();
let problem6 = Problem6::new(&util::get_problem(6)); // let problem6 = Problem6::new(&util::get_problem(6));
problem6.run_part1(); // problem6.run_part1();
problem6.run_part2(); // problem6.run_part2();
let problem7 = Problem7::new(&util::get_problem(7));
problem7.run_part1();
problem7.run_part2();
} }

@ -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…
Cancel
Save