11use std:: collections:: { HashSet , VecDeque } ;
2- use utils:: point :: Point2D ;
2+ use utils:: geometry :: Vec2 ;
33use utils:: prelude:: * ;
44
55/// Finding the shortest path.
@@ -12,18 +12,18 @@ pub struct Day13 {
1212impl Day13 {
1313 pub fn new ( input : & str , input_type : InputType ) -> Result < Self , InputError > {
1414 let favorite_number = parser:: u32 ( ) . parse_complete ( input) ?;
15- let target: Point2D < u32 > = if input_type == InputType :: Real {
16- Point2D :: new ( 31 , 39 )
15+ let target: Vec2 < u32 > = if input_type == InputType :: Real {
16+ Vec2 :: new ( 31 , 39 )
1717 } else {
18- Point2D :: new ( 7 , 4 )
18+ Vec2 :: new ( 7 , 4 )
1919 } ;
2020
2121 // Use a hashset to store visited nodes to avoid having a fixed grid size, as theoretically
2222 // the shortest route to the target may first go a long way down/right.
2323 let mut visited = HashSet :: new ( ) ;
24- visited. insert ( Point2D :: new ( 1 , 1 ) ) ;
24+ visited. insert ( Vec2 :: new ( 1 , 1 ) ) ;
2525 let mut queue = VecDeque :: new ( ) ;
26- queue. push_back ( ( Point2D :: new ( 1 , 1 ) , 0 ) ) ;
26+ queue. push_back ( ( Vec2 :: new ( 1 , 1 ) , 0 ) ) ;
2727
2828 let ( mut part1, mut part2) = ( 0 , 0 ) ;
2929 while let Some ( ( p, steps) ) = queue. pop_front ( ) {
@@ -37,11 +37,11 @@ impl Day13 {
3737 break ;
3838 }
3939
40- for next @ Point2D { x, y } in [
41- Point2D :: new ( p. x . saturating_sub ( 1 ) , p. y ) ,
42- Point2D :: new ( p. x . saturating_add ( 1 ) , p. y ) ,
43- Point2D :: new ( p. x , p. y . saturating_sub ( 1 ) ) ,
44- Point2D :: new ( p. x , p. y . saturating_add ( 1 ) ) ,
40+ for next @ Vec2 { x, y } in [
41+ Vec2 :: new ( p. x . saturating_sub ( 1 ) , p. y ) ,
42+ Vec2 :: new ( p. x . saturating_add ( 1 ) , p. y ) ,
43+ Vec2 :: new ( p. x , p. y . saturating_sub ( 1 ) ) ,
44+ Vec2 :: new ( p. x , p. y . saturating_add ( 1 ) ) ,
4545 ] {
4646 let n = ( x * x) + ( 3 * x) + ( 2 * x * y) + y + ( y * y) + favorite_number;
4747 if n. count_ones ( ) . is_multiple_of ( 2 ) && !visited. contains ( & next) {
0 commit comments