master
mitchellhansen 4 years ago
parent 9c9db529ed
commit 2f86fd2dec

@ -6,12 +6,14 @@ use crate::problem2::lib::Problem2;
use crate::problem3::lib::Problem3; 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;
mod problem1; mod problem1;
mod problem2; mod problem2;
mod problem3; mod problem3;
mod problem4; mod problem4;
mod problem5; mod problem5;
mod problem6;
mod util; mod util;
@ -41,7 +43,11 @@ fn main() {
// problem4.run_part1(); // problem4.run_part1();
// problem4.run_part2(); // problem4.run_part2();
let problem5 = Problem5::new(&util::get_problem(5)); // let problem5 = Problem5::new(&util::get_problem(5));
problem5.run_part1(); // problem5.run_part1();
problem5.run_part2(); // problem5.run_part2();
let problem6 = Problem6::new(&util::get_problem(6));
problem6.run_part1();
problem6.run_part2();
} }

@ -0,0 +1,52 @@
/*
Specifically, they need you to find the two entries that sum to 2020 and then multiply those two numbers together.
*/
use crate::Problem;
use std::collections::HashSet;
pub struct Problem6 {
groups: Vec<HashSet<char>>,
}
impl Problem6 {}
impl Problem for Problem6 {
fn new(input: &String) -> Self {
Problem6 {
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) {
let mut v = 0;
for i in &self.groups {
v += i.len();
}
println!("{}\n{:?}", v, self.groups);
}
fn run_part2(&self) {
}
}

@ -0,0 +1 @@
pub mod lib;
Loading…
Cancel
Save