Compare commits

..

No commits in common. "2a340c2e04a8414b1e929e091bfc532b4c217de3" and "6585356f0e978be4f991b7226e8b7fccc36f3a6d" have entirely different histories.

3 changed files with 12 additions and 165 deletions

View File

@ -1,7 +1,7 @@
use std::collections::VecDeque; use std::collections::VecDeque;
use aoc_runner_derive::{aoc, aoc_generator}; use aoc_runner_derive::{aoc, aoc_generator};
use hashbrown::HashMap; use hashbrown::{HashMap, HashSet};
use nom::{ use nom::{
bytes::complete::tag, bytes::complete::tag,
character::complete::{anychar, newline, one_of, space1, u64}, character::complete::{anychar, newline, one_of, space1, u64},
@ -293,11 +293,11 @@ x02 OR y02 -> z02"
); );
} }
// #[test] #[test]
// fn part2_example() { fn part2_example() {
// assert_eq!( assert_eq!(
// part2(&parse(include_str!("../input/2024/day24.txt").trim_end())), part2(&parse(include_str!("../input/2024/day24.txt").trim_end())),
// "z00,z01,z02,z05" "z00,z01,z02,z05"
// ); );
// } }
} }

View File

@ -1,152 +0,0 @@
use aoc_runner_derive::{aoc, aoc_generator};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Cell {
Empty,
Filled,
}
type Code = [usize; 5];
type Input = (Vec<Code>, Vec<Code>);
#[aoc_generator(day25)]
fn parse(input: &str) -> Input {
let (keys, locks): (Vec<Option<Vec<Vec<Cell>>>>, Vec<Option<Vec<Vec<Cell>>>>) = input
.split("\n\n")
.map(|block| {
block
.lines()
.map(|line| {
line.chars()
.map(|c| match c {
'.' => Cell::Empty,
'#' => Cell::Filled,
_ => panic!("Invalid cell"),
})
.collect()
})
.collect()
})
.map(|block: Vec<Vec<Cell>>| {
if block[0][0] == Cell::Filled {
(None, Some(block))
} else {
(Some(block), None)
}
})
.unzip();
let keys = keys
.into_iter()
.flatten()
.map(|block| {
let mut buffer = [0; 5];
for (y, row) in block.iter().enumerate() {
for x in 0..5 {
if row[x] == Cell::Empty {
buffer[x] = y;
}
}
}
buffer
})
.collect();
let locks = locks
.into_iter()
.flatten()
.map(|block| {
let mut buffer = [0; 5];
for (y, row) in block.iter().enumerate() {
for x in 0..5 {
if row[x] == Cell::Filled {
buffer[x] = y;
}
}
}
buffer
})
.collect();
(keys, locks)
}
#[aoc(day25, part1)]
fn part1(input: &Input) -> usize {
let (keys, locks) = input;
let mut valid_combinations = 0;
for key in keys {
for lock in locks {
if (0..5).all(|i| key[i] >= lock[i]) {
valid_combinations += 1;
}
}
}
valid_combinations
}
// #[aoc(day25, part2)]
// fn part2(input: &Input) -> usize {
// todo!()
// }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn part1_example() {
assert_eq!(
part1(&parse(
"#####
.####
.####
.####
.#.#.
.#...
.....
#####
##.##
.#.##
...##
...#.
...#.
.....
.....
#....
#....
#...#
#.#.#
#.###
#####
.....
.....
#.#..
###..
###.#
###.#
#####
.....
.....
.....
#....
#.#..
#.#.#
#####"
)),
3
);
}
// #[test]
// fn part2_example() {
// assert_eq!(part2(&parse("<EXAMPLE>")), 0);
// }
}

View File

@ -1,3 +1,7 @@
mod day24;
mod day23;
mod day22;
mod day21;
mod day1; mod day1;
mod day10; mod day10;
mod day11; mod day11;
@ -11,11 +15,6 @@ mod day18;
mod day19; mod day19;
mod day2; mod day2;
mod day20; mod day20;
mod day21;
mod day22;
mod day23;
mod day24;
mod day25;
mod day3; mod day3;
mod day4; mod day4;
mod day5; mod day5;