solution for day 6

main
Ray Slakinski 2020-12-07 14:45:53 -05:00
parent 966962a792
commit d2fc2be177
4 changed files with 2154 additions and 0 deletions

View 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 100644

File diff suppressed because it is too large Load Diff

View 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 100644
View File

@ -0,0 +1,16 @@
abc
a
b
c
ab
ac
a
a
a
a
b