11use std:: collections:: HashMap ;
22
3- use crate :: { Excercise , Solvable } ;
3+ use crate :: { Exercise , Solvable } ;
44
55type Position = ( i32 , i32 ) ;
66
@@ -49,7 +49,7 @@ impl Santa {
4949}
5050
5151struct ThirdDay {
52- exercise : Excercise ,
52+ exercise : Exercise ,
5353}
5454
5555fn get_visited_multiple_times ( first : Santa , second : Santa ) -> usize {
@@ -64,30 +64,30 @@ fn get_visited_multiple_times(first: Santa, second: Santa) -> usize {
6464}
6565
6666impl Solvable for ThirdDay {
67- fn solve_first ( & self , is_prod : bool ) -> i32 {
67+ fn solve_first ( & self , is_prod : bool ) -> i64 {
6868 if is_prod {
69- self . first ( self . exercise . content . to_owned ( ) )
69+ self . first ( & self . exercise . content )
7070 } else {
71- self . first ( self . exercise . example . to_owned ( ) )
71+ self . first ( & self . exercise . example )
7272 }
7373 }
7474
75- fn solve_second ( & self , is_prod : bool ) -> i32 {
75+ fn solve_second ( & self , is_prod : bool ) -> i64 {
7676 if is_prod {
77- self . second ( self . exercise . content . to_owned ( ) )
77+ self . second ( & self . exercise . content )
7878 } else {
79- self . second ( self . exercise . example . to_owned ( ) )
79+ self . second ( & self . exercise . example )
8080 }
8181 }
82- fn first ( & self , content : String ) -> i32 {
82+ fn first ( & self , content : & str ) -> i64 {
8383 let mut santa = Santa :: new ( ) ;
8484 for direction in content. chars ( ) {
8585 santa. move_to ( direction) ;
8686 }
87- santa. get_visited_multiple ( ) as i32
87+ santa. get_visited_multiple ( ) as i64
8888 }
8989
90- fn second ( & self , content : String ) -> i32 {
90+ fn second ( & self , content : & str ) -> i64 {
9191 let mut santa = Santa :: new ( ) ;
9292 let mut robo_santa = Santa :: new ( ) ;
9393 for direction in content. chars ( ) . enumerate ( ) {
@@ -97,20 +97,20 @@ impl Solvable for ThirdDay {
9797 robo_santa. move_to ( direction. 1 ) ;
9898 }
9999 }
100- get_visited_multiple_times ( santa, robo_santa) as i32
100+ get_visited_multiple_times ( santa, robo_santa) as i64
101101 }
102102}
103103
104104#[ cfg( test) ]
105105mod tests {
106106 use super :: * ;
107- const EXAMPLE : & str = include_str ! ( "3_test.txt" ) ;
108- const PROD : & str = include_str ! ( "3_prod.txt" ) ;
107+ const EXAMPLE : & str = include_str ! ( "inputs/ 3_test.txt" ) ;
108+ const PROD : & str = include_str ! ( "inputs/ 3_prod.txt" ) ;
109109
110110 #[ test]
111111 fn first_test ( ) {
112- let first_excersise = ThirdDay {
113- exercise : Excercise {
112+ let first_exercise = ThirdDay {
113+ exercise : Exercise {
114114 content : String :: from ( PROD ) ,
115115 example : String :: from ( EXAMPLE ) ,
116116 } ,
@@ -119,15 +119,15 @@ mod tests {
119119 let expected_example = 4 ;
120120 let expected_prod = 2572 ;
121121
122- let result_example = first_excersise . solve_first ( false ) ;
123- let result_prod = first_excersise . solve_first ( true ) ;
122+ let result_example = first_exercise . solve_first ( false ) ;
123+ let result_prod = first_exercise . solve_first ( true ) ;
124124 assert_eq ! ( expected_example, result_example) ;
125125 assert_eq ! ( expected_prod, result_prod) ;
126126
127127 let expected_example = 3 ;
128128 let expected_prod = 2631 ;
129- let result_example = first_excersise . solve_second ( false ) ;
130- let result_prod = first_excersise . solve_second ( true ) ;
129+ let result_example = first_exercise . solve_second ( false ) ;
130+ let result_prod = first_exercise . solve_second ( true ) ;
131131 assert_eq ! ( expected_example, result_example) ;
132132 assert_eq ! ( expected_prod, result_prod) ;
133133 }
0 commit comments