File tree Expand file tree Collapse file tree 1 file changed +10
-12
lines changed Expand file tree Collapse file tree 1 file changed +10
-12
lines changed Original file line number Diff line number Diff line change @@ -11,18 +11,17 @@ pub struct Rules {
1111pub fn input_generator ( input : & str ) -> Rules {
1212 let mut ordering = HashMap :: new ( ) ;
1313 let mut updates = vec ! [ ] ;
14+ let ( one, two) = input. split_once ( "\n \n " ) . unwrap ( ) ;
1415
15- for l in input. lines ( ) {
16- if l. contains ( "|" ) {
17- let sides = l. split_once ( "|" ) . unwrap ( ) ;
18- ordering
19- . entry ( sides. 1 . parse ( ) . unwrap ( ) )
20- . or_insert_with ( Vec :: new)
21- . push ( sides. 0 . parse ( ) . unwrap ( ) ) ;
22- }
23- if l. contains ( "," ) {
24- updates. push ( l. split ( "," ) . map ( |s| s. parse ( ) . unwrap ( ) ) . collect ( ) ) ;
25- }
16+ for l in one. lines ( ) {
17+ let sides = l. split_once ( "|" ) . unwrap ( ) ;
18+ ordering
19+ . entry ( sides. 1 . parse ( ) . unwrap ( ) )
20+ . or_insert_with ( Vec :: new)
21+ . push ( sides. 0 . parse ( ) . unwrap ( ) ) ;
22+ }
23+ for l in two. lines ( ) {
24+ updates. push ( l. split ( "," ) . map ( |s| s. parse ( ) . unwrap ( ) ) . collect ( ) ) ;
2625 }
2726 Rules { ordering, updates }
2827}
@@ -65,7 +64,6 @@ pub fn part2(input: &Rules) -> usize {
6564 for invalid in invalids {
6665 let mut inv = invalid. clone ( ) ;
6766 inv. sort_by ( |a, b| {
68- dbg ! ( a, b) ;
6967 if let Some ( must_be_before) = input. ordering . get ( b) {
7068 if must_be_before. contains ( a) {
7169 return Ordering :: Less ;
You can’t perform that action at this time.
0 commit comments