[Rust/2020/06] Add solution

This commit is contained in:
Felix Bargfeldt 2023-10-26 22:52:33 +02:00
parent aca99e0b9a
commit 9f68df1afa
Signed by: Defelo
GPG key ID: 2A05272471204DD3
6 changed files with 63 additions and 2 deletions

View file

@ -19,10 +19,10 @@
|[**20**](https://adventofcode.com/2021/day/20) [<img height=12 src=".assets/rs.svg">](Rust/2021/20.rs "Rust solution for 2021/20") [<img height=12 src=".assets/py.svg">](Python/2021/20.ipynb "Python solution for 2021/20")|[**21**](https://adventofcode.com/2021/day/21) [<img height=12 src=".assets/rs.svg">](Rust/2021/21.rs "Rust solution for 2021/21") [<img height=12 src=".assets/py.svg">](Python/2021/21.ipynb "Python solution for 2021/21")|[**22**](https://adventofcode.com/2021/day/22) [<img height=12 src=".assets/rs.svg">](Rust/2021/22.rs "Rust solution for 2021/22") [<img height=12 src=".assets/py.svg">](Python/2021/22.ipynb "Python solution for 2021/22")|[**23**](https://adventofcode.com/2021/day/23) [<img height=12 src=".assets/rs.svg">](Rust/2021/23.rs "Rust solution for 2021/23") [<img height=12 src=".assets/py.svg">](Python/2021/23.ipynb "Python solution for 2021/23")|[**24**](https://adventofcode.com/2021/day/24) [<img height=12 src=".assets/rs.svg">](Rust/2021/24.rs "Rust solution for 2021/24") [<img height=12 src=".assets/py.svg">](Python/2021/24.ipynb "Python solution for 2021/24")|[**25**](https://adventofcode.com/2021/day/25) [<img height=12 src=".assets/rs.svg">](Rust/2021/25.rs "Rust solution for 2021/25") [<img height=12 src=".assets/py.svg">](Python/2021/25.ipynb "Python solution for 2021/25")|26|
|27|28|29|30|31|||
## [2020](https://adventofcode.com/2020) ([<img height=18 src=".assets/py.svg"> Python](Python/2020): 25/25 | [<img height=18 src=".assets/rs.svg"> Rust](Rust/2020): 5/25)
## [2020](https://adventofcode.com/2020) ([<img height=18 src=".assets/py.svg"> Python](Python/2020): 25/25 | [<img height=18 src=".assets/rs.svg"> Rust](Rust/2020): 6/25)
|Mo|Tu|We|Th|Fr|Sa|Su|
|-|-|-|-|-|-|-|
||[**1**](https://adventofcode.com/2020/day/1) [<img height=12 src=".assets/rs.svg">](Rust/2020/01.rs "Rust solution for 2020/01") [<img height=12 src=".assets/py.svg">](Python/2020/01.ipynb "Python solution for 2020/01")|[**2**](https://adventofcode.com/2020/day/2) [<img height=12 src=".assets/rs.svg">](Rust/2020/02.rs "Rust solution for 2020/02") [<img height=12 src=".assets/py.svg">](Python/2020/02.ipynb "Python solution for 2020/02")|[**3**](https://adventofcode.com/2020/day/3) [<img height=12 src=".assets/rs.svg">](Rust/2020/03.rs "Rust solution for 2020/03") [<img height=12 src=".assets/py.svg">](Python/2020/03.ipynb "Python solution for 2020/03")|[**4**](https://adventofcode.com/2020/day/4) [<img height=12 src=".assets/rs.svg">](Rust/2020/04.rs "Rust solution for 2020/04") [<img height=12 src=".assets/py.svg">](Python/2020/04.ipynb "Python solution for 2020/04")|[**5**](https://adventofcode.com/2020/day/5) [<img height=12 src=".assets/rs.svg">](Rust/2020/05.rs "Rust solution for 2020/05") [<img height=12 src=".assets/py.svg">](Python/2020/05.ipynb "Python solution for 2020/05")|[**6**](https://adventofcode.com/2020/day/6) [<img height=12 src=".assets/py.svg">](Python/2020/06.ipynb "Python solution for 2020/06")|
||[**1**](https://adventofcode.com/2020/day/1) [<img height=12 src=".assets/rs.svg">](Rust/2020/01.rs "Rust solution for 2020/01") [<img height=12 src=".assets/py.svg">](Python/2020/01.ipynb "Python solution for 2020/01")|[**2**](https://adventofcode.com/2020/day/2) [<img height=12 src=".assets/rs.svg">](Rust/2020/02.rs "Rust solution for 2020/02") [<img height=12 src=".assets/py.svg">](Python/2020/02.ipynb "Python solution for 2020/02")|[**3**](https://adventofcode.com/2020/day/3) [<img height=12 src=".assets/rs.svg">](Rust/2020/03.rs "Rust solution for 2020/03") [<img height=12 src=".assets/py.svg">](Python/2020/03.ipynb "Python solution for 2020/03")|[**4**](https://adventofcode.com/2020/day/4) [<img height=12 src=".assets/rs.svg">](Rust/2020/04.rs "Rust solution for 2020/04") [<img height=12 src=".assets/py.svg">](Python/2020/04.ipynb "Python solution for 2020/04")|[**5**](https://adventofcode.com/2020/day/5) [<img height=12 src=".assets/rs.svg">](Rust/2020/05.rs "Rust solution for 2020/05") [<img height=12 src=".assets/py.svg">](Python/2020/05.ipynb "Python solution for 2020/05")|[**6**](https://adventofcode.com/2020/day/6) [<img height=12 src=".assets/rs.svg">](Rust/2020/06.rs "Rust solution for 2020/06") [<img height=12 src=".assets/py.svg">](Python/2020/06.ipynb "Python solution for 2020/06")|
|[**7**](https://adventofcode.com/2020/day/7) [<img height=12 src=".assets/py.svg">](Python/2020/07.ipynb "Python solution for 2020/07")|[**8**](https://adventofcode.com/2020/day/8) [<img height=12 src=".assets/py.svg">](Python/2020/08.ipynb "Python solution for 2020/08")|[**9**](https://adventofcode.com/2020/day/9) [<img height=12 src=".assets/py.svg">](Python/2020/09.ipynb "Python solution for 2020/09")|[**10**](https://adventofcode.com/2020/day/10) [<img height=12 src=".assets/py.svg">](Python/2020/10.ipynb "Python solution for 2020/10")|[**11**](https://adventofcode.com/2020/day/11) [<img height=12 src=".assets/py.svg">](Python/2020/11.ipynb "Python solution for 2020/11")|[**12**](https://adventofcode.com/2020/day/12) [<img height=12 src=".assets/py.svg">](Python/2020/12.ipynb "Python solution for 2020/12")|[**13**](https://adventofcode.com/2020/day/13) [<img height=12 src=".assets/py.svg">](Python/2020/13.ipynb "Python solution for 2020/13")|
|[**14**](https://adventofcode.com/2020/day/14) [<img height=12 src=".assets/py.svg">](Python/2020/14.ipynb "Python solution for 2020/14")|[**15**](https://adventofcode.com/2020/day/15) [<img height=12 src=".assets/py.svg">](Python/2020/15.ipynb "Python solution for 2020/15")|[**16**](https://adventofcode.com/2020/day/16) [<img height=12 src=".assets/py.svg">](Python/2020/16.ipynb "Python solution for 2020/16")|[**17**](https://adventofcode.com/2020/day/17) [<img height=12 src=".assets/py.svg">](Python/2020/17.ipynb "Python solution for 2020/17")|[**18**](https://adventofcode.com/2020/day/18) [<img height=12 src=".assets/py.svg">](Python/2020/18.ipynb "Python solution for 2020/18")|[**19**](https://adventofcode.com/2020/day/19) [<img height=12 src=".assets/py.svg">](Python/2020/19.ipynb "Python solution for 2020/19")|[**20**](https://adventofcode.com/2020/day/20) [<img height=12 src=".assets/py.svg">](Python/2020/20.ipynb "Python solution for 2020/20")|
|[**21**](https://adventofcode.com/2020/day/21) [<img height=12 src=".assets/py.svg">](Python/2020/21.ipynb "Python solution for 2020/21")|[**22**](https://adventofcode.com/2020/day/22) [<img height=12 src=".assets/py.svg">](Python/2020/22.ipynb "Python solution for 2020/22")|[**23**](https://adventofcode.com/2020/day/23) [<img height=12 src=".assets/py.svg">](Python/2020/23.ipynb "Python solution for 2020/23")|[**24**](https://adventofcode.com/2020/day/24) [<img height=12 src=".assets/py.svg">](Python/2020/24.ipynb "Python solution for 2020/24")|[**25**](https://adventofcode.com/2020/day/25) [<img height=12 src=".assets/py.svg">](Python/2020/25.ipynb "Python solution for 2020/25")|26|27|

41
Rust/2020/06.rs Normal file
View file

@ -0,0 +1,41 @@
#![feature(test)]
use rustc_hash::FxHashSet;
type Input = Vec<Vec<Vec<u8>>>;
fn setup(input: &str) -> Input {
input
.split("\n\n")
.map(|group| group.lines().map(|line| line.bytes().collect()).collect())
.collect()
}
fn part1(input: &Input) -> usize {
input
.iter()
.map(|group| group.iter().flatten().collect::<FxHashSet<_>>().len())
.sum()
}
fn part2(input: &Input) -> usize {
input
.iter()
.map(|group| {
let l = group.len();
group
.iter()
.fold([0; 256], |mut acc, xs| {
for &x in xs {
acc[x as usize] += 1;
}
acc
})
.into_iter()
.filter(|&x| x == l)
.count()
})
.sum()
}
aoc::main!(2020, 6, ex: 1);

View file

@ -51,6 +51,9 @@ path = "2020/04.rs"
[[bin]]
name = "2020_05"
path = "2020/05.rs"
[[bin]]
name = "2020_06"
path = "2020/06.rs"
# 2021
[[bin]]

15
examples/2020/6/1 Normal file
View file

@ -0,0 +1,15 @@
abc
a
b
c
ab
ac
a
a
a
a
b

1
examples/2020/6/1.1 Normal file
View file

@ -0,0 +1 @@
11

1
examples/2020/6/1.2 Normal file
View file

@ -0,0 +1 @@
6