• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Vest / aoc-rust / 4005027531

pending completion
4005027531

Pull #19

github

GitHub
Merge 74f46dcbf into 0e0e3157b
Pull Request #19: Updated versions

2556 of 3992 branches covered (64.03%)

Branch coverage included in aggregate %.

1560 of 1560 new or added lines in 44 files covered. (100.0%)

5981 of 6247 relevant lines covered (95.74%)

624811.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.0
/adv2020/src/day6.rs
1
use std::collections::{HashMap, HashSet};
2

3
pub fn find_answer1(input: &str) -> usize {
2✔
4
    let mut result = 0usize;
2✔
5

6
    let mut set: HashSet<char> = HashSet::new();
2✔
7

8
    for line in input.lines() {
17✔
9
        if line.is_empty() {
15✔
10
            result += set.len();
4✔
11
            set.clear();
4✔
12
        } else {
13
            line.chars().for_each(|c: char| {
26✔
14
                set.insert(c);
15✔
15
            })
15✔
16
        }
17
    }
18

19
    result + set.len()
2✔
20
}
2✔
21

22
pub fn find_answer2(input: &str) -> usize {
2✔
23
    let mut result = 0usize;
2✔
24

25
    let mut map_stats: HashMap<char, usize> = HashMap::new();
2✔
26
    let mut lines = 0usize;
2✔
27

28
    for line in input.lines() {
2!
29
        if line.is_empty() {
×
30
            result += map_stats.iter().filter(|&(_, v)| *v == lines).count();
×
31
            lines = 0;
×
32
            map_stats.clear();
×
33
        } else {
34
            line.chars().for_each(|c: char| {
×
35
                if map_stats.contains_key(&c) {
×
36
                    let value = map_stats.get(&c).unwrap();
×
37
                    let value = *value + 1;
×
38
                    map_stats.insert(c, value);
×
39
                } else {
40
                    map_stats.insert(c, 1);
×
41
                }
42
            });
×
43

44
            lines += 1;
×
45
        }
46
    }
47

48
    result + map_stats.iter().filter(|&(_, v)| *v == lines).count()
2✔
49
}
2✔
50
/*
51
struct AggregateIterator<'a, T: Iterator<Item=&'a str> + 'a> {
52
    input: T,
53
}
54

55
impl AggregateIterator<T> {
56
    fn new(input: &str) -> AggregateIterator<T> {
57
        AggregateIterator {
58
            input: input.lines()
59
        }
60
    }
61
}
62

63
impl Iterator for AggregateIterator<T> {
64
    type Item = String;
65

66
    fn next(&mut self) -> Option<Self::Item> {
67
        let mut vec: Vec<String> = Vec::new();
68

69
        for str in self.input.map(&str::trim) {
70
            if str.is_empty {
71
                break;
72
            }
73
            vec.append(str);
74
        }
75

76
        if vec.is_empty() {
77
            None
78
        } else {
79
            Some(vec.join(" "))
80
        }
81
    }
82
}*/
83

84
#[cfg(test)]
85
mod tests {
86
    use super::*;
87

88
    #[test]
89
    fn test_empty_answers() {
2✔
90
        assert_eq!(
1✔
91
            find_answer1(
1!
92
                r#"abc
93

94
a
95
b
96
c
97

98
ab
99
ac
100

101
a
102
a
103
a
104
a
105

106
b"#
107
            ),
108
            11
109
        );
110
        assert_eq!(find_answer2(""), 0);
1!
111
    }
2✔
112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc