mirror of https://github.com/HeNine/aoc2020
Day 6
parent
dfef1ef1c7
commit
f67ef8d2bc
@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "day6"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["henine <matija@rezar.biz>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,35 @@
|
|||||||
|
use std::collections::HashSet;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{BufRead, BufReader};
|
||||||
|
use std::iter::FromIterator;
|
||||||
|
use std::result::Result::{Err, Ok};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = match File::open("input") {
|
||||||
|
Ok(file) => file,
|
||||||
|
Err(e) => panic!(e)
|
||||||
|
};
|
||||||
|
|
||||||
|
let input_buffer = BufReader::new(&file);
|
||||||
|
|
||||||
|
let mut sum = 0;
|
||||||
|
|
||||||
|
let mut seen_chars = HashSet::from_iter((b'a'..=b'z').map(char::from));
|
||||||
|
// seen_chars.extend();
|
||||||
|
for rline in input_buffer.lines() {
|
||||||
|
let line = rline.unwrap();
|
||||||
|
|
||||||
|
if line.trim() == "" {
|
||||||
|
sum += seen_chars.len();
|
||||||
|
seen_chars = HashSet::from_iter((b'a'..=b'z').map(char::from));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let line_chars: HashSet<char> = HashSet::from_iter(line.chars());
|
||||||
|
seen_chars = HashSet::from_iter(seen_chars.intersection(&line_chars).map(|x|*x));
|
||||||
|
}
|
||||||
|
|
||||||
|
sum += seen_chars.len();
|
||||||
|
|
||||||
|
println!("{}", sum);
|
||||||
|
}
|
Loading…
Reference in New Issue