From 7b93826c567dc193d989c300b781ae7065378f02 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Sun, 6 Dec 2020 16:10:49 -0800 Subject: [PATCH] problem 7 template --- src/main.rs | 12 +++++++++--- src/problem7/lib.rs | 46 +++++++++++++++++++++++++++++++++++++++++++++ src/problem7/mod.rs | 1 + 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/problem7/lib.rs create mode 100644 src/problem7/mod.rs diff --git a/src/main.rs b/src/main.rs index 595cd10..f0906f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ use crate::problem3::lib::Problem3; use crate::problem4::lib::Problem4; use crate::problem5::lib::Problem5; use crate::problem6::lib::Problem6; +use crate::problem7::lib::Problem7; mod problem1; mod problem2; @@ -14,6 +15,7 @@ mod problem3; mod problem4; mod problem5; mod problem6; +mod problem7; mod util; @@ -47,7 +49,11 @@ fn main() { // problem5.run_part1(); // problem5.run_part2(); - let problem6 = Problem6::new(&util::get_problem(6)); - problem6.run_part1(); - problem6.run_part2(); + // let problem6 = Problem6::new(&util::get_problem(6)); + // problem6.run_part1(); + // problem6.run_part2(); + + let problem7 = Problem7::new(&util::get_problem(7)); + problem7.run_part1(); + problem7.run_part2(); } diff --git a/src/problem7/lib.rs b/src/problem7/lib.rs new file mode 100644 index 0000000..985848b --- /dev/null +++ b/src/problem7/lib.rs @@ -0,0 +1,46 @@ + + +use crate::Problem; +use std::collections::HashSet; + +pub struct Problem7 { + groups: Vec>, +} + + +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 = i.chars().filter_map(|c| { + if c.is_whitespace() { + None + } else { + Some(c) + } + }).collect::>(); + sets.push(v); + } + let mut iter = sets.iter(); + let intersection : HashSet = + 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) { + } +} + diff --git a/src/problem7/mod.rs b/src/problem7/mod.rs new file mode 100644 index 0000000..965f28e --- /dev/null +++ b/src/problem7/mod.rs @@ -0,0 +1 @@ +pub mod lib;