Skip to content

Commit

Permalink
Day 25 solved!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
CcydtN committed Dec 25, 2024
1 parent 87b63ad commit 4f75c15
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
39 changes: 39 additions & 0 deletions data/examples/25.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#####
.####
.####
.####
.#.#.
.#...
.....

#####
##.##
.#.##
...##
...#.
...#.
.....

.....
#....
#....
#...#
#.#.#
#.###
#####

.....
.....
#.#..
###..
###.#
###.#
#####

.....
.....
.....
#....
#.#..
#.#.#
#####
36 changes: 34 additions & 2 deletions src/bin/25.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
use itertools::iproduct;

advent_of_code::solution!(25);

fn parse(input: &str) -> Option<(Vec<[i64; 5]>, Vec<[i64; 5]>)> {
let mut keys = vec![];
let mut locks = vec![];
let mut buffer = [0; 5];
for grid in input.split("\n\n") {
for row in grid.split_whitespace() {
for (i, cell) in row.trim().chars().enumerate() {
buffer[i] += if cell == '#' { 1 } else { -1 };
}
}
// as top row is filled
// if grid.chars().take(5).all(|c| c == '#') {
if grid.chars().next() == Some('#') {
locks.push(buffer);
} else {
keys.push(buffer);
}
buffer.fill(0);
}
Some((keys, locks))
}

pub fn part_one(input: &str) -> Option<u64> {
None
let (keys, locks) = dbg!(parse(input))?;

let mut count = 0;
for (key, lock) in iproduct!(keys, locks) {
if key.iter().zip(lock).all(|(a, b)| a + b <= 0) {
count += 1;
}
}
Some(count)
}

pub fn part_two(input: &str) -> Option<u64> {
Expand All @@ -15,7 +47,7 @@ mod tests {
#[test]
fn test_part_one() {
let result = part_one(&advent_of_code::template::read_file("examples", DAY));
assert_eq!(result, None);
assert_eq!(result, Some(3));
}

#[test]
Expand Down

0 comments on commit 4f75c15

Please sign in to comment.