✨ fucking fuck fuck die die got two stars though
This commit is contained in:
parent
ea5249a9b3
commit
cac9e2bffc
2
2020/6/.gitignore
vendored
Normal file
2
2020/6/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target/
|
||||
Cargo.lock
|
9
2020/6/Cargo.toml
Normal file
9
2020/6/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "day6"
|
||||
version = "0.1.0"
|
||||
authors = ["Stephan Stanisic <stephan@stanisic.nl>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
2081
2020/6/input
Normal file
2081
2020/6/input
Normal file
File diff suppressed because it is too large
Load Diff
45
2020/6/src/main.rs
Normal file
45
2020/6/src/main.rs
Normal file
@ -0,0 +1,45 @@
|
||||
use std::fs;
|
||||
use std::convert::TryInto;
|
||||
|
||||
fn main() {
|
||||
let contents = fs::read_to_string("input")
|
||||
.expect("Something went wrong reading the file");
|
||||
|
||||
let groups = contents.split("\n\n");
|
||||
|
||||
// Part 1
|
||||
let mut nums: Vec<u32> = Vec::new();
|
||||
for g in groups {
|
||||
let mut chars: Vec<char> = g.chars().collect();
|
||||
|
||||
// Remove duplicates
|
||||
chars.sort();
|
||||
chars.dedup();
|
||||
|
||||
// Remove the \n
|
||||
chars = chars.into_iter().filter(|x| *x != '\n').collect();
|
||||
|
||||
let size = chars.iter().count().try_into().unwrap();
|
||||
nums.push(size);
|
||||
}
|
||||
|
||||
let sum: u32 = nums.iter().sum();
|
||||
println!("Total number of answers is {}.", sum);
|
||||
|
||||
|
||||
let groups = contents.split("\n\n");
|
||||
let mut count = 0;
|
||||
// Part 2
|
||||
for g in groups {
|
||||
let lines = g.split("\n").count();
|
||||
let chars: Vec<char> = g.chars().filter(|x| *x != '\n').collect();
|
||||
let mut uniques = chars.clone();
|
||||
uniques.sort();
|
||||
uniques.dedup();
|
||||
|
||||
let totals: Vec<char> = uniques.into_iter().filter(|x| chars.iter().filter(|y| **y == *x).count() == lines).collect();
|
||||
count += totals.iter().count();
|
||||
}
|
||||
|
||||
println!("Die please fucking die this is stupid {}.", count);
|
||||
}
|
Loading…
Reference in New Issue
Block a user