Adding edges
This commit is contained in:
parent
47c0f0bf76
commit
22ada9b454
1 changed files with 19 additions and 1 deletions
20
src/prob8.rs
20
src/prob8.rs
|
@ -1,5 +1,5 @@
|
||||||
use petgraph::prelude::*;
|
|
||||||
use petgraph::matrix_graph::MatrixGraph;
|
use petgraph::matrix_graph::MatrixGraph;
|
||||||
|
use petgraph::prelude::*;
|
||||||
|
|
||||||
pub fn solve_part1(content: &str) -> color_eyre::Result<u32> {
|
pub fn solve_part1(content: &str) -> color_eyre::Result<u32> {
|
||||||
let (n_line, numbers) = {
|
let (n_line, numbers) = {
|
||||||
|
@ -26,6 +26,24 @@ pub fn solve_part1(content: &str) -> color_eyre::Result<u32> {
|
||||||
for i in 0..m_element {
|
for i in 0..m_element {
|
||||||
let idx = j * m_element + i;
|
let idx = j * m_element + i;
|
||||||
idx_slice[idx] = graph.add_node(num_slice[idx]);
|
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],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue