Add 9 first days

This commit is contained in:
2021-01-08 23:41:37 +11:00
parent 4846e7c811
commit 2fd73ae5d1
49 changed files with 9734 additions and 0 deletions

1
6-custom_customs/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

23
6-custom_customs/Cargo.lock generated Normal file
View File

@@ -0,0 +1,23 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "custom_customs"
version = "0.1.0"
dependencies = [
"itertools",
]
[[package]]
name = "either"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "itertools"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b"
dependencies = [
"either",
]

View File

@@ -0,0 +1,10 @@
[package]
name = "custom_customs"
version = "0.1.0"
authors = ["Guilhem MARION <gmarion@netc.fr>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
itertools = "0.9.0"

File diff suppressed because it is too large Load Diff

1
6-custom_customs/element Normal file
View File

@@ -0,0 +1 @@
E: You must give at least one search pattern

1
6-custom_customs/riot Normal file
View File

@@ -0,0 +1 @@
E: You must give at least one search pattern

View File

@@ -0,0 +1,81 @@
use std::{collections::HashSet, todo};
use itertools::Itertools;
fn count_scores(input: &str) -> Vec<usize> {
input
.split("\n\n")
.map(|l| l.chars()
.unique()
.filter(|&c| c != '\n')
.count())
.collect()
}
fn count_scores_v2(input: &str) -> Vec<usize> {
input
.split("\n\n")
.map(|group| {
group
.lines()
.map(|l| l.chars().collect::<HashSet<char>>())
.fold1(|acc: HashSet<char>, hset| {
acc.intersection(&hset).cloned().collect()
})
.unwrap()
.len()
})
.collect()
}
fn main() {
let input = include_str!("../data/input.txt");
let scores = count_scores(input);
println!("Sum of scores : {}", scores.iter().sum::<usize>());
println!("Sum of scores v2 : {}", count_scores_v2(input).iter().sum::<usize>())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_count_scores() {
let input = r#"abc
a
b
c
ab
ac
a
a
a
a
b"#;
assert_eq!(count_scores(input).iter().sum::<usize>(), 11)
}
#[test]
fn test_count_scores_v2() {
let input = r#"abc
a
b
c
ab
ac
a
a
a
a
b"#;
assert_eq!(count_scores_v2(input).iter().sum::<usize>(), 6);
}
}