tangled
alpha
login
or
join now
nove.dev
/
aoc-2024
0
fork
atom
retroactive, to derust my rust
0
fork
atom
overview
issues
pulls
pipelines
cleanup
nove.dev
3 months ago
1102c196
44f5223e
+3
-32
2 changed files
expand all
collapse all
unified
split
src
day10.rs
spatial.rs
+3
-9
src/day10.rs
···
1
1
-
use itertools::Itertools;
2
2
-
3
1
use crate::spatial::{
4
4
-
Point, adjacent_cardinal, adjacent_cardinal_points, all_coords, flood, paths_to_each_point,
5
5
-
print_grid,
2
2
+
Point, adjacent_cardinal_points, all_coords, flood, paths_to_each_point,
6
3
};
7
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
35
-
})
36
36
-
.collect_vec();
37
37
-
dbg!(&ratings);
38
38
-
ratings.iter().sum::<usize>().to_string()
31
31
+
});
32
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
11
-
impl ToString for Point {
12
12
-
fn to_string(&self) -> String {
13
13
-
format!("({}, {})", self.row, self.col)
14
14
-
}
15
15
-
}
16
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
90
-
println!("cursor is at ({}, {})", cursor.row, cursor.col);
91
84
for point in &digraph[cursor.row][cursor.col] {
92
92
-
println!("dealing with adjacent point ({}, {})", point.row, point.col);
93
85
frontier.insert(*point);
94
94
-
println!(
95
95
-
"frontier now has {} points: {}",
96
96
-
frontier.len(),
97
97
-
frontier.iter().map(|pt| pt.to_string()).join(", ")
98
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
107
-
dbg!(paths_to_each_point.len());
108
94
paths_to_each_point
109
95
}
110
110
-
111
111
-
pub fn print_grid<T: ToString>(paths: Vec<Vec<T>>) -> Vec<Vec<T>> {
112
112
-
let s = paths
113
113
-
.iter()
114
114
-
.map(|row| row.iter().map(|count| count.to_string()).join(""))
115
115
-
.join("\n");
116
116
-
println!("{s}\n");
117
117
-
paths
118
118
-
}