finish 82
This commit is contained in:
@@ -4,12 +4,12 @@ use std::path::Path;
|
||||
|
||||
type Coordinate = (usize, usize);
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Matrix {
|
||||
data: Vec<Vec<Node>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Node {
|
||||
value: usize,
|
||||
distance: Option<usize>,
|
||||
@@ -76,7 +76,7 @@ impl MatrixTrait<usize> for Matrix {
|
||||
|
||||
impl Matrix {
|
||||
pub fn load(f: &Path) -> Self {
|
||||
let mut data: Vec<Vec<_>> = fs::read_to_string(f)
|
||||
let data: Vec<Vec<_>> = fs::read_to_string(f)
|
||||
.unwrap()
|
||||
.split_whitespace()
|
||||
.map(|line| {
|
||||
@@ -87,8 +87,11 @@ impl Matrix {
|
||||
.collect()
|
||||
})
|
||||
.collect();
|
||||
let mut start = &mut data[0][0];
|
||||
start.distance = Some(start.value);
|
||||
Self { data }
|
||||
}
|
||||
|
||||
pub fn set_start(&mut self, (x, y): Coordinate) {
|
||||
let node = &mut self.data[y][x];
|
||||
node.distance = Some(node.value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,13 @@ const FILENAME: &str = "p082_test.txt";
|
||||
const FILENAME: &str = "p082_matrix.txt";
|
||||
|
||||
fn main() {
|
||||
let mut matrix = Matrix::load(Path::new(FILENAME));
|
||||
let matrix_raw = Matrix::load(Path::new(FILENAME));
|
||||
let mut results = vec![];
|
||||
|
||||
for start in [0].into_iter().cycle().zip(0..LENGTH) {
|
||||
let mut matrix = matrix_raw.clone();
|
||||
matrix.set_start(start);
|
||||
|
||||
let mut dijkstra = Dijkstra::new(&mut matrix, AllowedMovements::DownRightUp, start);
|
||||
dijkstra.solve();
|
||||
let result = (0..LENGTH)
|
||||
|
||||
Reference in New Issue
Block a user