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 } ;
3
3
use tracing_subscriber:: field:: debug;
4
4
use util:: { Coord , Direction , ParseError } ;
5
5
@@ -142,7 +142,6 @@ impl Conundrum {
142
142
let final_paths: Vec < Path > = r1_paths
143
143
. iter ( )
144
144
. flat_map ( |r1_path| {
145
- // TODO add A at front of r1_path?
146
145
assert ! ( r1_path. chars( ) . nth( 0 ) . unwrap( ) == 'A' ) ;
147
146
r1_path
148
147
. as_bytes ( )
@@ -152,49 +151,62 @@ impl Conundrum {
152
151
153
152
let mut r2_paths: Vec < String > = self . robot_2 . path ( r1_substr[ 0 ] . into ( ) , r1_substr[ 1 ] . into ( ) , & self . robot_2 ) ;
154
153
debug ! ( "\t r1_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
156
156
. iter_mut ( )
157
157
. flat_map ( |r2_path| {
158
158
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( ) ] ;
160
162
161
- let r3_r2_path : Vec < Vec < Path > > = r2_path
163
+ r2_path
162
164
. as_bytes ( )
163
165
. windows ( 2 )
164
- . map ( |r2_substr| {
166
+ . for_each ( |r2_substr| {
165
167
let r2_substr_string: String = r1_substr. iter ( ) . map ( |r| * r as char ) . collect ( ) ;
166
168
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 \t r2_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 \t r3_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 \t r2_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
+ } )
176
177
} )
177
178
. collect ( ) ;
178
- debug ! ( "\t \t r3_paths={:?}" , r3_paths) ;
179
- r3_paths
180
179
181
- } )
182
- . collect ( ) ;
183
- //debug!("\t\tr3_r2_path={:?}", r3_r2_path);
184
- r3_r2_path. iter ( )
185
- . for_each ( |p| debug ! ( "\t \t r3_r2_path p={:?}" , p) ) ;
186
- r3_r2_path. into_iter ( ) . flatten ( )
180
+ debug ! ( "\t \t \t r3_paths_curr={:?} want last group of these" , r3_paths_curr) ;
187
181
182
+ } ) ;
183
+
184
+
185
+ debug ! ( "\t \t r3_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 > > ( )
188
191
} )
189
192
. collect ( ) ;
190
- r2_full_paths
193
+ debug ! ( "\t r2_full_paths=" ) ;
194
+ r2_all_paths. iter ( )
195
+ . for_each ( |p| {
196
+ debug ! ( "\t \t r2_all_path p={:?}" , p) ;
197
+ } ) ;
198
+ r2_all_paths
191
199
} )
192
200
} )
193
- . collect ( )
194
- ;
201
+ . collect ( ) ;
195
202
196
203
//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);
197
204
205
+ debug ! ( "final_paths=" ) ;
206
+ final_paths. iter ( )
207
+ . for_each ( |p| {
208
+ debug ! ( "\t {:?}" , p) ;
209
+ } ) ;
198
210
final_paths. len ( )
199
211
}
200
212
0 commit comments