Skip to content

Commit dac3116

Browse files
committed
2025 11.2
1 parent 15706fe commit dac3116

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed

data

Submodule data updated from a2b075e to 4c247cf

src/aoc/y2025/day11.rs

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ const fn to_id(input: &str) -> Key {
2626
((a as u32) << 16) + ((b as u32) << 8) + (c as u32)
2727
}
2828

29-
const START: Key = to_id("you");
29+
const YOU: Key = to_id("you");
30+
const SERVER: Key = to_id("svr");
31+
const FFT: Key = to_id("fft");
32+
const DAC: Key = to_id("dac");
3033
const END: Key = to_id("out");
3134

3235
fn parse_line(input: String) -> crate::AoCResult<(Key, Vec<Key>)> {
@@ -53,7 +56,56 @@ cached_key! {
5356

5457
pub fn part_1(data: crate::DataIn) -> crate::AoCResult<String> {
5558
let store: Store = data.map(parse_line).try_collect()?;
56-
let ret = find_paths(START, &store);
59+
let ret = find_paths(YOU, &store);
60+
Ok(ret.to_string())
61+
}
62+
63+
#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq, Default)]
64+
struct PathState {
65+
found_fft: bool,
66+
found_dac: bool,
67+
}
68+
69+
impl PathState {
70+
fn get_score(&self) -> usize {
71+
if self.found_dac && self.found_fft {
72+
1
73+
} else {
74+
0
75+
}
76+
}
77+
}
78+
79+
cached_key! {
80+
FIND_PATHS_2: UnboundCache<(Key, PathState), usize> = UnboundCache::with_capacity(600);
81+
Key = { (id, path_state) };
82+
fn find_paths_2(id: Key, path_state: PathState, store: &Store) -> usize = {
83+
let mut path_state = path_state;
84+
if id == FFT {
85+
path_state.found_fft = true;
86+
} else if id == DAC{
87+
path_state.found_dac = true;
88+
}
89+
let my_outputs = &store[&id];
90+
log::debug!("Hello I'm {id} and my friends are {my_outputs:?}");
91+
92+
my_outputs
93+
.iter()
94+
.copied()
95+
.map(|out_id| {
96+
if out_id == END {
97+
path_state.get_score()
98+
} else {
99+
find_paths_2(out_id, path_state, store)
100+
}
101+
})
102+
.sum::<usize>()
103+
}
104+
}
105+
106+
pub fn part_2(data: crate::DataIn) -> crate::AoCResult<String> {
107+
let store: Store = data.map(parse_line).try_collect()?;
108+
let ret = find_paths_2(SERVER, Default::default(), &store);
57109
Ok(ret.to_string())
58110
}
59111

@@ -62,7 +114,16 @@ inventory::submit!(crate::AoCDay {
62114
day: "11",
63115
part_1: crate::AoCPart {
64116
main: part_1,
65-
example: part_1
117+
example: |data| {
118+
let (data, _) = crate::partition_input(data);
119+
part_1(data)
120+
}
66121
},
67-
part_2: None
122+
part_2: Some(crate::AoCPart {
123+
main: part_2,
124+
example: |data| {
125+
let (_, data) = crate::partition_input(data);
126+
part_2(data)
127+
}
128+
})
68129
});

0 commit comments

Comments
 (0)