retroactive, to derust my rust

cleanup

+3 -32
+3 -9
src/day10.rs
··· 1 - use itertools::Itertools; 2 - 3 1 use crate::spatial::{ 4 - Point, adjacent_cardinal, adjacent_cardinal_points, all_coords, flood, paths_to_each_point, 5 - print_grid, 2 + Point, adjacent_cardinal_points, all_coords, flood, paths_to_each_point, 6 3 }; 7 - use std::collections::{BTreeSet, HashMap}; 8 4 9 5 pub fn day10_part1(input: &str) -> String { 10 6 let topomap = parse(input); ··· 32 28 .filter(|pt| topomap[pt.row][pt.col] == 9) 33 29 .map(|pt| grid[pt.row][pt.col].len()) 34 30 .sum::<usize>() 35 - }) 36 - .collect_vec(); 37 - dbg!(&ratings); 38 - ratings.iter().sum::<usize>().to_string() 31 + }); 32 + ratings.sum::<usize>().to_string() 39 33 } 40 34 41 35 fn parse(input: &str) -> Vec<Vec<u8>> {
-23
src/spatial.rs
··· 8 8 pub col: usize, 9 9 } 10 10 11 - impl ToString for Point { 12 - fn to_string(&self) -> String { 13 - format!("({}, {})", self.row, self.col) 14 - } 15 - } 16 - 17 11 pub fn all_coords(width: usize, height: usize) -> impl Iterator<Item = Point> { 18 12 (0..height) 19 13 .cartesian_product(0..width) ··· 87 81 let mut frontier = BTreeSet::from_iter([start]); 88 82 89 83 while let Some(cursor) = frontier.pop_first() { 90 - println!("cursor is at ({}, {})", cursor.row, cursor.col); 91 84 for point in &digraph[cursor.row][cursor.col] { 92 - println!("dealing with adjacent point ({}, {})", point.row, point.col); 93 85 frontier.insert(*point); 94 - println!( 95 - "frontier now has {} points: {}", 96 - frontier.len(), 97 - frontier.iter().map(|pt| pt.to_string()).join(", ") 98 - ); 99 86 let paths_to_new_point = paths_to_each_point[cursor.row][cursor.col].clone(); 100 87 for mut path in paths_to_new_point { 101 88 path.push(*point); ··· 104 91 } 105 92 } 106 93 107 - dbg!(paths_to_each_point.len()); 108 94 paths_to_each_point 109 95 } 110 - 111 - pub fn print_grid<T: ToString>(paths: Vec<Vec<T>>) -> Vec<Vec<T>> { 112 - let s = paths 113 - .iter() 114 - .map(|row| row.iter().map(|count| count.to_string()).join("")) 115 - .join("\n"); 116 - println!("{s}\n"); 117 - paths 118 - }