Skip to content

Commit c8de44b

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

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

.run/run_aoc.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="run_aoc" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
33
<option name="buildProfileId" value="dev" />
4-
<option name="command" value="run --package aoclp_solutions --bin aoclp_solutions -- --year 2025 --day 10 --part 2" />
4+
<option name="command" value="run --package aoclp_solutions --bin aoclp_solutions -- --year 2025 --day 12" />
55
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
66
<envs />
77
<option name="emulateTerminal" value="true" />

aoclp_solutions/src/y2025/day_12.rs

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
use std::ops::Range;
21
use std::str::FromStr;
32
use std::sync::OnceLock;
43
use itertools::Itertools;
54
use aoclp::anyhow::Context;
65
use aoclp::regex::Regex;
6+
use aoclp::solvers_impl::input::safe_get_input;
77

88
pub fn part_1() -> usize {
9+
let input = input();
10+
println!("Presents: {}, regions: {}", input.0.len(), input.1.len());
11+
912
0
1013
}
1114

@@ -73,18 +76,58 @@ impl FromStr for Region {
7376
}
7477
}
7578

79+
fn input() -> (Vec<Present>, Vec<Region>) {
80+
parse_input(safe_get_input(2025, 12).lines())
81+
}
82+
7683
fn parse_input<I, S>(input: I) -> (Vec<Present>, Vec<Region>)
7784
where
7885
I: IntoIterator<Item = S>,
86+
<I as IntoIterator>::IntoIter: Clone,
7987
S: AsRef<str>,
8088
{
81-
let mut it = input.into_iter();
89+
static INDEX_REGEX: OnceLock<Regex> = OnceLock::new();
90+
let index_re =
91+
INDEX_REGEX.get_or_init(|| {
92+
Regex::new(r"^(?<idx>\d+):\s*$").unwrap()
93+
});
8294

95+
let mut it = input.into_iter().peekable();
8396
let mut presents = Vec::new();
84-
for i in 0.. {
85-
let index = it.next();
86-
if
97+
let mut i = 0;
98+
loop {
99+
// if let Some(line) = it.peek() && line.as_ref().trim_ascii().is_empty() {
100+
//
101+
// }
102+
103+
let index_s = it.next().expect("end of data before regions!");
104+
let index_s = index_s.as_ref();
105+
if index_s.trim_ascii().is_empty() {
106+
continue;
107+
}
108+
109+
match index_re.captures(index_s) {
110+
None => break,
111+
Some(index_cap) => {
112+
let index = &index_cap["idx"];
113+
let index: usize = index.parse().unwrap();
114+
if index != i {
115+
panic!("expected present #{i}, found present #{index}");
116+
}
117+
118+
let present: Present = it.clone().take(3).into();
119+
presents.push(present);
120+
121+
it = it.dropping(3);
122+
i += 1;
123+
},
124+
}
87125
}
88126

89-
todo!()
127+
let regions = it
128+
.skip_while(|l| l.as_ref().trim_ascii().is_empty())
129+
.map(|l| l.as_ref().parse().unwrap())
130+
.collect();
131+
132+
(presents, regions)
90133
}

0 commit comments

Comments
 (0)