[Rust/2015/05] Add solution

This commit is contained in:
Felix Bargfeldt 2024-09-23 23:47:24 +02:00
parent 24eea1ba64
commit 48dbd9877c
Signed by: Defelo
GPG key ID: 2A05272471204DD3
4 changed files with 50 additions and 3 deletions

View file

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

44
Rust/2015/05.rs Normal file
View file

@ -0,0 +1,44 @@
#![feature(test)]
use itertools::Itertools;
type Input = Vec<String>;
fn setup(input: &str) -> Input {
input.trim().lines().map(Into::into).collect()
}
fn part1(input: &Input) -> usize {
input
.iter()
.filter(|s| {
let r1 = s
.chars()
.filter(|c| "aeiou".contains(c.to_ascii_lowercase()))
.count()
>= 3;
let r2 = s.chars().tuple_windows().any(|(a, b)| a == b);
let r3 = ["ab", "cd", "pq", "xy"].into_iter().all(|x| !s.contains(x));
r1 && r2 && r3
})
.count()
}
fn part2(input: &Input) -> usize {
input
.iter()
.filter(|s| {
let r1 =
(0..s.len() - 1).any(|i| (i + 2..s.len() - 1).any(|j| s[i..i + 2] == s[j..j + 2]));
let r2 = s.chars().tuple_windows().any(|(a, _, b)| a == b);
r1 && r2
})
.count()
}
aoc::main!(2015, 5);

View file

@ -3,7 +3,7 @@ aoc::year! {
"02.rs",
"03.rs",
"04.rs",
// "05.rs",
"05.rs",
// "06.rs",
// "07.rs",
// "08.rs",

View file

@ -56,6 +56,9 @@ path = "2015/03.rs"
[[bin]]
name = "2015_04"
path = "2015/04.rs"
[[bin]]
name = "2015_05"
path = "2015/05.rs"
# 2020
[[bin]]