parent
9c9db529ed
commit
2f86fd2dec
@ -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…
Reference in new issue