-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path06.rs
More file actions
19 lines (16 loc) · 646 Bytes
/
06.rs
File metadata and controls
19 lines (16 loc) · 646 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use std::{io::stdin, collections::HashSet};
fn main() {
let sets = stdin().lines()
.map(|l| l.unwrap().chars().collect::<HashSet<_>>())
.collect::<Vec<_>>();
let groups = sets
.split(|set| set.is_empty())
.collect::<Vec<_>>();
let p1: usize = groups.iter()
.map(|s| s.iter().fold(s[0].clone(), |acc, curr| acc.union(curr).cloned().collect()))
.fold(0, |acc, l| acc+l.len());
let p2: usize = groups.iter()
.map(|s| s.iter().fold(s[0].clone(), |acc, curr| acc.intersection(curr).cloned().collect()))
.fold(0, |acc, l| acc+l.len());
println!("{}\n{}", p1, p2);
}