@@ -14,22 +14,24 @@ pub struct Day07;
1414impl Solution for Day07 {
1515 fn part_one ( & self , input : & str ) -> String {
1616 let grid: Grid < char > = Grid :: from ( input) ;
17- let max_height = grid. columns_range ( ) . end ( ) + 1 ;
17+ let column_range = grid. columns_range ( ) ;
1818 let start = grid. get_first_position ( & START ) . unwrap ( ) ;
1919
2020 let splitters: HashSet < Point > = grid. get_all_positions ( & SPLITTER ) . into_iter ( ) . collect ( ) ;
2121
22- let mut result_beams : Vec < Beam > = Vec :: new ( ) ;
22+ let mut finished_beams : Vec < Beam > = Vec :: new ( ) ;
2323 let mut current_beams: VecDeque < Beam > = VecDeque :: from ( vec ! [ start. into( ) ] ) ;
24+ let mut splits = 0 ;
2425
2526 while let Some ( current_beam) = current_beams. pop_front ( ) {
2627 let down = current_beam. down ( ) ;
2728
2829 if splitters. contains ( & down. current ( ) ) {
29- result_beams. push ( current_beam) ;
30+ finished_beams. push ( current_beam) ;
31+ splits += 1 ;
3032
3133 for split in down. split ( ) {
32- if result_beams
34+ if finished_beams
3335 . iter ( )
3436 . chain ( current_beams. iter ( ) )
3537 . any ( |beam| beam. collides ( & split) )
@@ -43,14 +45,17 @@ impl Solution for Day07 {
4345 continue ;
4446 }
4547
46- if down. current ( ) . y > max_height {
48+ if !column_range. contains ( down. current ( ) . y ) {
49+ finished_beams. push ( down) ;
4750 continue ;
4851 }
4952
5053 current_beams. push_front ( down) ;
5154 }
5255
53- result_beams. len ( ) . to_string ( )
56+ // print(&grid, &finished_beams);
57+
58+ splits. to_string ( )
5459 }
5560
5661 fn part_two ( & self , _input : & str ) -> String {
0 commit comments