solution for day 6
parent
966962a792
commit
d2fc2be177
|
@ -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"
|
File diff suppressed because it is too large
Load Diff
|
@ -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);
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
abc
|
||||||
|
|
||||||
|
a
|
||||||
|
b
|
||||||
|
c
|
||||||
|
|
||||||
|
ab
|
||||||
|
ac
|
||||||
|
|
||||||
|
a
|
||||||
|
a
|
||||||
|
a
|
||||||
|
a
|
||||||
|
|
||||||
|
b
|
||||||
|
|
Loading…
Reference in New Issue