2015: day05: part 1

This commit is contained in:
Antoine Martin 2019-12-03 16:25:23 +01:00
parent a5911369e5
commit b023546c8c
4 changed files with 1066 additions and 1 deletions

1000
aoc2015/input/day05.txt Normal file

File diff suppressed because it is too large Load diff

63
aoc2015/src/day05.rs Normal file
View file

@ -0,0 +1,63 @@
use aoc::Result;
const INPUT: &str = include_str!("../input/day05.txt");
pub fn run() -> Result<()> {
println!("part 1: {}", part1(INPUT));
Ok(())
}
fn part1(input: &str) -> usize {
input
.lines()
.map(|line| line.trim_end())
.filter(|line| {
let mut vowel_count = 0;
for c in line.chars() {
if "aeiou".find(c).is_some() {
vowel_count += 1;
}
}
vowel_count >= 3
})
.filter(|line| {
let mut prev = None;
for c in line.chars() {
if let Some(p) = prev {
if p == c {
return true;
}
}
prev = Some(c);
}
false
})
.filter(|line| line.find("ab").is_none())
.filter(|line| line.find("cd").is_none())
.filter(|line| line.find("pq").is_none())
.filter(|line| line.find("xy").is_none())
.count()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn part1_provided() {
assert_eq!(part1("ugknbfddgicrmopn"), 1);
assert_eq!(part1("aaa"), 1);
assert_eq!(part1("jchzalrnumimnmhp"), 0);
assert_eq!(part1("haegwjzuvuyypxyu"), 0);
assert_eq!(part1("dvszwmarrgswjxmb"), 0);
}
#[test]
fn part1_real() {
assert_eq!(part1(INPUT), 258);
}
}

View file

@ -2,3 +2,4 @@ pub mod day01;
pub mod day02; pub mod day02;
pub mod day03; pub mod day03;
pub mod day04; pub mod day04;
pub mod day05;

View file

@ -4,9 +4,10 @@ use aoc2015::day01;
use aoc2015::day02; use aoc2015::day02;
use aoc2015::day03; use aoc2015::day03;
use aoc2015::day04; use aoc2015::day04;
use aoc2015::day05;
fn main() -> Result<()> { fn main() -> Result<()> {
let days: &[fn() -> Result<()>] = &[day01::run, day02::run, day03::run, day04::run]; let days: &[fn() -> Result<()>] = &[day01::run, day02::run, day03::run, day04::run, day05::run];
aoc::run(days) aoc::run(days)
} }