1
0
Fork 0

Adding edges

This commit is contained in:
Pcornat 2023-10-05 23:29:30 +02:00
commit 22ada9b454
Signed by: Pcornat
GPG key ID: 2F3932FF46D9ECA0

View file

@ -1,5 +1,5 @@
use petgraph::prelude::*;
use petgraph::matrix_graph::MatrixGraph;
use petgraph::prelude::*;
pub fn solve_part1(content: &str) -> color_eyre::Result<u32> {
let (n_line, numbers) = {
@ -26,6 +26,24 @@ pub fn solve_part1(content: &str) -> color_eyre::Result<u32> {
for i in 0..m_element {
let idx = j * m_element + i;
idx_slice[idx] = graph.add_node(num_slice[idx]);
if (i as i64 - 1) >= 0 {
let previous_same_row = idx - 1;
graph.add_edge(idx_slice[idx], idx_slice[previous_same_row], num_slice[idx]);
graph.add_edge(
idx_slice[previous_same_row],
idx_slice[idx],
num_slice[previous_same_row],
);
}
if (j as i64 - 1) >= 0 {
let previous_same_col = idx - m_element;
graph.add_edge(idx_slice[idx], idx_slice[previous_same_col], num_slice[idx]);
graph.add_edge(
idx_slice[previous_same_col],
idx_slice[idx],
num_slice[previous_same_col],
);
}
}
}