diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/2020/6/mod.rs | 43 | ||||
-rw-r--r-- | src/2020/mod.rs | 4 | ||||
-rw-r--r-- | src/main.rs | 2 |
3 files changed, 49 insertions, 0 deletions
diff --git a/src/2020/6/mod.rs b/src/2020/6/mod.rs new file mode 100644 index 0000000..94dd4da --- /dev/null +++ b/src/2020/6/mod.rs @@ -0,0 +1,43 @@ +pub fn part1() -> anyhow::Result<i64> { + let input = crate::util::read_file_str("data/6.txt")?; + let mut yes = std::collections::HashSet::new(); + let mut total = 0; + for line in input.lines() { + if line == "" { + total += yes.len() as i64; + yes = std::collections::HashSet::new(); + } else { + for c in line.chars() { + yes.insert(c); + } + } + } + total += yes.len() as i64; + Ok(total) +} + +pub fn part2() -> anyhow::Result<i64> { + let input = crate::util::read_file_str("data/6.txt")?; + let mut yes = std::collections::HashSet::new(); + for c in 'a'..='z' { + yes.insert(c); + } + let mut total = 0; + for line in input.lines() { + if line == "" { + total += yes.len() as i64; + yes = std::collections::HashSet::new(); + for c in 'a'..='z' { + yes.insert(c); + } + } else { + for c in 'a'..='z' { + if !line.contains(c) { + yes.remove(&c); + } + } + } + } + total += yes.len() as i64; + Ok(total) +} diff --git a/src/2020/mod.rs b/src/2020/mod.rs index 8919f5f..47f5150 100644 --- a/src/2020/mod.rs +++ b/src/2020/mod.rs @@ -8,6 +8,8 @@ mod day3; mod day4; #[path = "5/mod.rs"] mod day5; +#[path = "6/mod.rs"] +mod day6; pub fn run(day: u8, puzzle: u8) -> anyhow::Result<i64> { match (day, puzzle) { @@ -21,6 +23,8 @@ pub fn run(day: u8, puzzle: u8) -> anyhow::Result<i64> { (4, 2) => day4::part2(), (5, 1) => day5::part1(), (5, 2) => day5::part2(), + (6, 1) => day6::part1(), + (6, 2) => day6::part2(), _ => Err(anyhow::anyhow!("unknown puzzle {}-{}", day, puzzle)), } } diff --git a/src/main.rs b/src/main.rs index af137fd..3905d9b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![allow(clippy::collapsible_if)] + mod util; #[path = "2020/mod.rs"] mod year2020; |