parent
e43fb3f11c
commit
d76047fabc
@ -0,0 +1,9 @@ |
||||
[package] |
||||
name = "day06" |
||||
version = "0.1.0" |
||||
authors = ["inga-lovinde <52715130+inga-lovinde@users.noreply.github.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
@ -0,0 +1,28 @@ |
||||
use std::collections::HashMap; |
||||
use std::io::{self, BufRead}; |
||||
|
||||
fn main() { |
||||
let stdin = io::stdin(); |
||||
let mut answers = HashMap::new(); |
||||
let mut result_anybody = 0; |
||||
let mut result_everybody = 0; |
||||
let mut group_size = 0; |
||||
for line_result in stdin.lock().lines() { |
||||
let line = line_result.unwrap(); |
||||
if line == "" { |
||||
let group_anybody = answers.len(); |
||||
let group_everybody = answers.values().filter(|&&count| count == group_size).count(); |
||||
result_anybody += group_anybody; |
||||
result_everybody += group_everybody; |
||||
println!("Group: {}/{}, total: {}/{}", group_everybody, group_anybody, result_everybody, result_anybody); |
||||
answers.clear(); |
||||
group_size = 0; |
||||
} else { |
||||
group_size += 1; |
||||
for ch in line.chars() { |
||||
let count = answers.entry(ch).or_insert(0); |
||||
*count += 1; |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue