diff options
author | Jesse Luehrs <doy@tozt.net> | 2020-12-08 02:20:12 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2020-12-08 02:20:12 -0500 |
commit | 340c586e323d3c8838c0e5fd53870a4d07350c75 (patch) | |
tree | a29c27200d8f07f37f7599b5f6dda478e5ae55b4 /src/2020/6/mod.rs | |
parent | 935aa4ba68c865adbe36a99ae02bb6f40b73edc6 (diff) | |
download | advent-of-code-340c586e323d3c8838c0e5fd53870a4d07350c75.tar.gz advent-of-code-340c586e323d3c8838c0e5fd53870a4d07350c75.zip |
day 6
Diffstat (limited to 'src/2020/6/mod.rs')
-rw-r--r-- | src/2020/6/mod.rs | 43 |
1 files changed, 43 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) +} |