blob: 94dd4dad7d0bf4382ab510f6bc442252a24b4614 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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)
}
|