solution for day 6
This commit is contained in:
parent
966962a792
commit
d2fc2be177
10
2020/day_6/Cargo.toml
Normal file
10
2020/day_6/Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "day_6"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Ray Slakinski <ray.slakinski@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
counter = "0.5.2"
|
2086
2020/day_6/input
Normal file
2086
2020/day_6/input
Normal file
File diff suppressed because it is too large
Load Diff
42
2020/day_6/src/main.rs
Normal file
42
2020/day_6/src/main.rs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
use counter::Counter;
|
||||||
|
use std::{collections::HashMap, println};
|
||||||
|
fn main() {
|
||||||
|
let contents = std::fs::read_to_string("input").unwrap();
|
||||||
|
let mut groups = Vec::new();
|
||||||
|
let mut group = Vec::new();
|
||||||
|
let mut total_count = 0;
|
||||||
|
|
||||||
|
for line in contents.lines() {
|
||||||
|
if line.len() > 0 {
|
||||||
|
group.push(line.to_string());
|
||||||
|
} else {
|
||||||
|
groups.push(group.to_vec());
|
||||||
|
group.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for g in &groups {
|
||||||
|
let voters = g.len();
|
||||||
|
let mut all_votes: Vec<HashMap<char, usize>> = Vec::new();
|
||||||
|
for v in g {
|
||||||
|
let counts = v.chars().collect::<Counter<_>>();
|
||||||
|
all_votes.push(counts.into_map());
|
||||||
|
}
|
||||||
|
println!("{:?}", all_votes);
|
||||||
|
let mut vote_count = 0;
|
||||||
|
for c in b'a'..=b'z' {
|
||||||
|
for v in &all_votes {
|
||||||
|
let l = c as char;
|
||||||
|
// println!("{:?}", v[&l]);
|
||||||
|
if v.contains_key(&l) {
|
||||||
|
vote_count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if vote_count == voters {
|
||||||
|
total_count += 1;
|
||||||
|
}
|
||||||
|
vote_count = 0
|
||||||
|
}
|
||||||
|
all_votes.clear()
|
||||||
|
}
|
||||||
|
println!("Total unique people voted {}", total_count);
|
||||||
|
}
|
16
2020/day_6/test
Normal file
16
2020/day_6/test
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
abc
|
||||||
|
|
||||||
|
a
|
||||||
|
b
|
||||||
|
c
|
||||||
|
|
||||||
|
ab
|
||||||
|
ac
|
||||||
|
|
||||||
|
a
|
||||||
|
a
|
||||||
|
a
|
||||||
|
a
|
||||||
|
|
||||||
|
b
|
||||||
|
|
Reference in New Issue
Block a user