Skip to content

Commit 9c94216

Browse files
committed
chore: WIP y2025::day_12
1 parent d980a18 commit 9c94216

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

aoclp_solutions/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ pub mod y2025;
1111
build_solvers! {
1212
{ 2017, [01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25] },
1313
{ 2024, [01, 02, 03, 04, 05, 06, 07, 08, 09, 10] },
14-
{ 2025, [01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11] }
14+
{ 2025, [01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12] }
1515
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
use std::ops::Range;
2+
use std::str::FromStr;
3+
use std::sync::OnceLock;
4+
use itertools::Itertools;
5+
use aoclp::anyhow::Context;
6+
use aoclp::regex::Regex;
7+
8+
pub fn part_1() -> usize {
9+
0
10+
}
11+
12+
pub fn part_2() -> usize {
13+
0
14+
}
15+
16+
#[derive(Debug, Copy, Clone)]
17+
struct Present {
18+
shape: [[bool; 3]; 3],
19+
}
20+
21+
impl<I, S> From<I> for Present
22+
where
23+
I: Iterator<Item = S>,
24+
S: AsRef<str>,
25+
{
26+
fn from(value: I) -> Self {
27+
let shape = value
28+
.map(|line| {
29+
line.as_ref()
30+
.chars()
31+
.map(|c| c == '#')
32+
.collect_array()
33+
.unwrap()
34+
})
35+
.collect_array()
36+
.unwrap();
37+
Self { shape }
38+
}
39+
}
40+
41+
#[derive(Debug, Clone)]
42+
struct Region {
43+
width: usize,
44+
height: usize,
45+
presents: Vec<usize>,
46+
}
47+
48+
impl FromStr for Region {
49+
type Err = aoclp::Error;
50+
51+
fn from_str(s: &str) -> Result<Self, Self::Err> {
52+
static REGEX: OnceLock<Regex> = OnceLock::new();
53+
let re =
54+
REGEX.get_or_init(|| {
55+
Regex::new(r"^(?<width>\d+)x(?<height>\d+):\s+(?<presents>(?:\d+\s*)+)$").unwrap()
56+
});
57+
58+
let captures = re
59+
.captures(s)
60+
.with_context(|| format!("invalid region spec: {s}"))?;
61+
let width = &captures["width"];
62+
let height = &captures["height"];
63+
let presents = &captures["presents"];
64+
65+
let width = width.parse()?;
66+
let height = height.parse()?;
67+
let presents: Vec<_> = presents
68+
.split_ascii_whitespace()
69+
.map(|p| p.parse::<usize>())
70+
.try_collect()?;
71+
72+
Ok(Self { width, height, presents })
73+
}
74+
}
75+
76+
fn parse_input<I, S>(input: I) -> (Vec<Present>, Vec<Region>)
77+
where
78+
I: IntoIterator<Item = S>,
79+
S: AsRef<str>,
80+
{
81+
let mut it = input.into_iter();
82+
83+
let mut presents = Vec::new();
84+
for i in 0.. {
85+
let index = it.next();
86+
if
87+
}
88+
89+
todo!()
90+
}

aoclp_solutions/src/y2025/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ pub mod day_08;
99
pub mod day_09;
1010
pub mod day_10;
1111
pub mod day_11;
12+
pub mod day_12;

0 commit comments

Comments
 (0)