@@ -15,25 +15,25 @@ enum Direction {
1515impl Direction {
1616 /// Move one step in the given direction, if possible.
1717 fn step ( self , x : usize , y : usize , sx : usize , sy : usize ) -> Option < ( usize , usize ) > {
18- if self == Direction :: North && y > 0 {
18+ if self == Self :: North && y > 0 {
1919 Some ( ( x, y - 1 ) )
20- } else if self == Direction :: East && x < sx - 1 {
20+ } else if self == Self :: East && x < sx - 1 {
2121 Some ( ( x + 1 , y) )
22- } else if self == Direction :: South && y < sy - 1 {
22+ } else if self == Self :: South && y < sy - 1 {
2323 Some ( ( x, y + 1 ) )
24- } else if self == Direction :: West && x > 0 {
24+ } else if self == Self :: West && x > 0 {
2525 Some ( ( x - 1 , y) )
2626 } else {
2727 None
2828 }
2929 }
3030
3131 /// Indicate if two directions are opposite.
32- fn is_opposite ( self , other : Direction ) -> bool {
33- self == Direction :: North && other == Direction :: South
34- || self == Direction :: South && other == Direction :: North
35- || self == Direction :: East && other == Direction :: West
36- || self == Direction :: West && other == Direction :: East
32+ fn is_opposite ( self , other : Self ) -> bool {
33+ self == Self :: North && other == Self :: South
34+ || self == Self :: South && other == Self :: North
35+ || self == Self :: East && other == Self :: West
36+ || self == Self :: West && other == Self :: East
3737 }
3838}
3939
@@ -72,8 +72,8 @@ struct Puzzle {
7272}
7373
7474impl Puzzle {
75- fn new ( ) -> Puzzle {
76- Puzzle {
75+ const fn new ( ) -> Self {
76+ Self {
7777 grid : vec ! [ ] ,
7878 sx : 0 ,
7979 sy : 0 ,
@@ -188,6 +188,14 @@ impl Puzzle {
188188 }
189189}
190190
191+ fn main ( ) {
192+ let args = aoc:: parse_args ( ) ;
193+ let mut puzzle = Puzzle :: new ( ) ;
194+ puzzle. configure ( args. path . as_str ( ) ) ;
195+ println ! ( "{}" , puzzle. part1( ) ) ;
196+ println ! ( "{}" , puzzle. part2( ) ) ;
197+ }
198+
191199/// Test from puzzle input
192200#[ cfg( test) ]
193201mod test {
@@ -214,11 +222,3 @@ mod test {
214222 assert_eq ! ( puzzle. part2( ) , 71 ) ;
215223 }
216224}
217-
218- fn main ( ) {
219- let args = aoc:: parse_args ( ) ;
220- let mut puzzle = Puzzle :: new ( ) ;
221- puzzle. configure ( args. path . as_str ( ) ) ;
222- println ! ( "{}" , puzzle. part1( ) ) ;
223- println ! ( "{}" , puzzle. part2( ) ) ;
224- }
0 commit comments