Skip to content

Commit 8a24057

Browse files
committed
WIP day-21
1 parent 0fdf4a7 commit 8a24057

File tree

1 file changed

+39
-27
lines changed
  • AdventOfCode/2024/day-21/src

1 file changed

+39
-27
lines changed

AdventOfCode/2024/day-21/src/lib.rs

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::{fmt::Display, str::{Chars, FromStr}};
2-
use tracing::{debug, info};
1+
use std::{fmt::{format, Display}, str::{Chars, FromStr}};
2+
use tracing::{debug, field::debug, info, warn};
33
use tracing_subscriber::field::debug;
44
use util::{Coord, Direction, ParseError};
55

@@ -142,7 +142,6 @@ impl Conundrum {
142142
let final_paths: Vec<Path> = r1_paths
143143
.iter()
144144
.flat_map(|r1_path| {
145-
// TODO add A at front of r1_path?
146145
assert!(r1_path.chars().nth(0).unwrap() == 'A');
147146
r1_path
148147
.as_bytes()
@@ -152,49 +151,62 @@ impl Conundrum {
152151

153152
let mut r2_paths: Vec<String> = self.robot_2.path(r1_substr[0].into(), r1_substr[1].into(), &self.robot_2);
154153
debug!("\tr1_path={:?}, r1_substr={:?}, r2_paths={:?}", r1_path.clone(), r1_substr_string, r2_paths);
155-
let r2_full_paths: Vec<Path> = r2_paths
154+
155+
let r2_all_paths: Vec<Path> = r2_paths
156156
.iter_mut()
157157
.flat_map(|r2_path| {
158158
r2_path.insert(0, 'A');
159-
//assert!(r2_path.chars().nth(0).unwrap() == 'A');
159+
assert!(r2_path.chars().nth(0).unwrap() == 'A');
160+
161+
let mut r3_paths_curr: Vec<String> = vec!["".to_string()];
160162

161-
let r3_r2_path: Vec<Vec<Path>> = r2_path
163+
r2_path
162164
.as_bytes()
163165
.windows(2)
164-
.map(|r2_substr| {
166+
.for_each(|r2_substr| {
165167
let r2_substr_string: String = r1_substr.iter().map(|r| *r as char).collect();
166168

167-
let mut r3_presses: Vec<String> = self.robot_3.path(r2_substr[0].into(), r2_substr[1].into(), &self.robot_3);
168-
debug!("\t\tr2_substr={:?}, r3_paths={:?}", r2_substr_string, r3_presses);
169-
170-
let r3_paths: Vec<Path> = r3_presses
171-
.iter_mut()
172-
.map(|r3_path| {
173-
let p = Path { numpad: numpad_goal.clone(), r1: r1_path.clone(), r2: r2_path.clone(), r3: r3_path.to_string() };
174-
debug!("\t\t\tr3_path p={:?}", p);
175-
p
169+
let r3_new_presses: Vec<String> = self.robot_3.path(r2_substr[0].into(), r2_substr[1].into(), &self.robot_3);
170+
debug!("\t\t\tr2_substr_string={:?}, r3_paths_curr={:?}, r3_new_presses={:?}", r2_substr_string, r3_paths_curr, r3_new_presses);
171+
r3_paths_curr = r3_new_presses.iter()
172+
.flat_map(|r3_new_press| {
173+
r3_paths_curr.iter()
174+
.map(|r3_path_curr| {
175+
format!("{}{}", r3_path_curr, r3_new_press.clone())
176+
})
176177
})
177178
.collect();
178-
debug!("\t\tr3_paths={:?}", r3_paths);
179-
r3_paths
180179

181-
})
182-
.collect();
183-
//debug!("\t\tr3_r2_path={:?}", r3_r2_path);
184-
r3_r2_path.iter()
185-
.for_each(|p| debug!("\t\tr3_r2_path p={:?}", p));
186-
r3_r2_path.into_iter().flatten()
180+
debug!("\t\t\tr3_paths_curr={:?} want last group of these", r3_paths_curr);
187181

182+
});
183+
184+
185+
debug!("\t\tr3_paths_curr={:?}", r3_paths_curr);
186+
r3_paths_curr.iter()
187+
.map(|r3_path_curr| {
188+
Path { numpad: numpad_goal.clone(), r1: r1_path.clone(), r2: r2_path.clone(), r3: r3_path_curr.to_string() }
189+
})
190+
.collect::<Vec<Path>>()
188191
})
189192
.collect();
190-
r2_full_paths
193+
debug!("\tr2_full_paths=");
194+
r2_all_paths.iter()
195+
.for_each(|p| {
196+
debug!("\t\tr2_all_path p={:?}", p);
197+
});
198+
r2_all_paths
191199
})
192200
})
193-
.collect()
194-
;
201+
.collect();
195202

196203
//println!("[distance_r3] {} to {}, r3_path={}, r3_path.len()={}, r2_full_path={}, r1_path={}", from_npad_btn, to_npad_button, r3_path, r3_path.len(), r2_full_path, r1_path);
197204

205+
debug!("final_paths=");
206+
final_paths.iter()
207+
.for_each(|p| {
208+
debug!("\t{:?}", p);
209+
});
198210
final_paths.len()
199211
}
200212

0 commit comments

Comments
 (0)