day_10: part 1 done
This commit is contained in:
@@ -12,7 +12,7 @@ https://adventofcode.com/2024
|
|||||||
| 07 | Bridge Repair | :pushpin: | :pushpin: | Equation parsing |
|
| 07 | Bridge Repair | :pushpin: | :pushpin: | Equation parsing |
|
||||||
| 08 | Resonant Collinearity | :pushpin: | | Matrix exploration |
|
| 08 | Resonant Collinearity | :pushpin: | | Matrix exploration |
|
||||||
| 09 | Disk fragmenter | :pushpin: | | Array indexing |
|
| 09 | Disk fragmenter | :pushpin: | | Array indexing |
|
||||||
| 10 | Hoof It | | | |
|
| 10 | Hoof It | :pushpin: | | Path finding |
|
||||||
| 11 | | | | |
|
| 11 | | | | |
|
||||||
| 12 | | | | |
|
| 12 | | | | |
|
||||||
| 13 | | | | |
|
| 13 | | | | |
|
||||||
|
|||||||
@@ -1,8 +1,44 @@
|
|||||||
89010123
|
12109832101432101234107652158943210178765892
|
||||||
78121874
|
03078456210145696701218943067654396549456701
|
||||||
87430965
|
54562364345436789874327832107810387630345210
|
||||||
96549874
|
65401875696925210765498017656901234521254321
|
||||||
45678903
|
78078956787814321544567328943217890012189450
|
||||||
32019012
|
69101045698701055432123410812206921983098765
|
||||||
01329801
|
43232132509652566785010569701105435674549056
|
||||||
10456732
|
58943001419143478994321678983210304105678143
|
||||||
|
67653214328012988765690787894321213289437212
|
||||||
|
45654301037001089650787096765010034576524301
|
||||||
|
56789890156121072341256101896654123678915498
|
||||||
|
43276765243234561212345234987783210569206789
|
||||||
|
54109854312789870109012345676898765454106543
|
||||||
|
45610123203650105438721056765609674323287012
|
||||||
|
54781010154543216521635489832014589210398013
|
||||||
|
67898543269854107610544376541023008101296323
|
||||||
|
54987656576765678923455210458782112010387456
|
||||||
|
23122189983454989012966904349698103465456567
|
||||||
|
12033078012763210101877813234521098578956798
|
||||||
|
03944565430887654012109320121034787632347897
|
||||||
|
87856556021991047121238458945695698961036016
|
||||||
|
96587432110872338930347567232780087654105125
|
||||||
|
01498983321265427945656089101091109803234934
|
||||||
|
32327465456766016859890176232892256712107843
|
||||||
|
21012334569854105766763245001743343893256765
|
||||||
|
30503129678945234897854632122654872894349854
|
||||||
|
45614068798234012656906543213458961783210703
|
||||||
|
21765878907178723765417891008965450654125612
|
||||||
|
30854965416069654894328982567872342103054503
|
||||||
|
48903010325450560761237813450561003276543678
|
||||||
|
56012321210341981230106504341540214789432189
|
||||||
|
67329630121212870341012415432634345695321012
|
||||||
|
78478742198903965494543326998723456786540765
|
||||||
|
89569653087654654987696547889010567847830874
|
||||||
|
21052104676501723898587032378765676956921923
|
||||||
|
32343015685432810767698121459034982349650010
|
||||||
|
10478723794354903456567030760121061078744567
|
||||||
|
21569654891263212347450177898267877101233498
|
||||||
|
32108765430678903038321789783454978715012399
|
||||||
|
47899834320545676129012876012543269856101087
|
||||||
|
56938723011230983543903965987650156747801256
|
||||||
|
40127619654321012652874854107890349832954343
|
||||||
|
30034508763018723761765543236501212721096501
|
||||||
|
21065619012349654890101234565432301430787432
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ pub fn hoof_it(input: &str) -> usize {
|
|||||||
|
|
||||||
let mut sum_of_scores: usize = 0;
|
let mut sum_of_scores: usize = 0;
|
||||||
|
|
||||||
println!("The score list is: {:?}", vector_of_scores);
|
|
||||||
// TODO: improve, this is dirty
|
// TODO: improve, this is dirty
|
||||||
for score in vector_of_scores {
|
for score in vector_of_scores {
|
||||||
sum_of_scores += score;
|
sum_of_scores += score;
|
||||||
@@ -24,7 +23,8 @@ pub fn explore_map(map: TrailMap) -> Vec<TrailScore> {
|
|||||||
for y_index in 0..map.len() {
|
for y_index in 0..map.len() {
|
||||||
for x_index in 0..map[y_index].len() {
|
for x_index in 0..map[y_index].len() {
|
||||||
if map[y_index][x_index] == 0 {
|
if map[y_index][x_index] == 0 {
|
||||||
trail_score_list.push(explore_position(x_index, y_index, &map));
|
let mut reached_ends: Vec<(usize, usize)> = vec![];
|
||||||
|
trail_score_list.push(explore_position(x_index, y_index, &map, &mut reached_ends));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,15 +32,23 @@ pub fn explore_map(map: TrailMap) -> Vec<TrailScore> {
|
|||||||
trail_score_list
|
trail_score_list
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn explore_position(x: TrailPosition, y: TrailPosition, map: &TrailMap) -> usize {
|
pub fn explore_position(
|
||||||
|
x: TrailPosition,
|
||||||
|
y: TrailPosition,
|
||||||
|
map: &TrailMap,
|
||||||
|
reached_ends: &mut Vec<(usize, usize)>,
|
||||||
|
) -> usize {
|
||||||
if map[y][x] == 9 {
|
if map[y][x] == 9 {
|
||||||
|
reached_ends.push((x, y));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut score_sum: usize = 0;
|
let mut score_sum: usize = 0;
|
||||||
for next_position in get_pos_surroundings(x, y, map) {
|
for next_position in get_pos_surroundings(x, y, map) {
|
||||||
if map[next_position.1][next_position.0] == map[y][x] + 1 {
|
if map[next_position.1][next_position.0] == map[y][x] + 1
|
||||||
score_sum += explore_position(next_position.0, next_position.1, map);
|
&& !reached_ends.contains(&(next_position.0, next_position.1))
|
||||||
|
{
|
||||||
|
score_sum += explore_position(next_position.0, next_position.1, map, reached_ends);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,24 +65,24 @@ pub fn get_pos_surroundings(
|
|||||||
if x > 0 {
|
if x > 0 {
|
||||||
trail_pos_vec.push((x - 1, y));
|
trail_pos_vec.push((x - 1, y));
|
||||||
|
|
||||||
if y > 0 {
|
// if y > 0 {
|
||||||
trail_pos_vec.push((x - 1, y - 1));
|
// trail_pos_vec.push((x - 1, y - 1));
|
||||||
}
|
// }
|
||||||
if y < map.len() - 1 {
|
// if y < map.len() - 1 {
|
||||||
trail_pos_vec.push((x - 1, y + 1));
|
// trail_pos_vec.push((x - 1, y + 1));
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
if x < map[0].len() - 1 {
|
if x < map[0].len() - 1 {
|
||||||
trail_pos_vec.push((x + 1, y));
|
trail_pos_vec.push((x + 1, y));
|
||||||
|
|
||||||
if y > 0 {
|
// if y > 0 {
|
||||||
trail_pos_vec.push((x + 1, y - 1));
|
// trail_pos_vec.push((x + 1, y - 1));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if y < map.len() - 1 {
|
// if y < map.len() - 1 {
|
||||||
trail_pos_vec.push((x + 1, y + 1));
|
// trail_pos_vec.push((x + 1, y + 1));
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
if y > 0 {
|
if y > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user