File tree Expand file tree Collapse file tree 1 file changed +25
-2
lines changed
Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ impl DayImpl<Data> for Day<CURRENT_DAY> {
1111 }
1212
1313 fn expected_results ( ) -> ( Answer , Answer ) {
14- ( Answer :: Number ( 1227775554 ) , Answer :: Number ( 0 ) )
14+ ( Answer :: Number ( 1227775554 ) , Answer :: Number ( 4174379265 ) )
1515 }
1616
1717 fn init ( input : & str ) -> ( Self , Data ) {
@@ -59,6 +59,29 @@ impl DayImpl<Data> for Day<CURRENT_DAY> {
5959 }
6060
6161 fn two ( & self , data : & mut Data ) -> Answer {
62- Answer :: Number ( data. len ( ) as u64 )
62+ let mut count: u64 = 0 ;
63+
64+ for & mut ( start, end) in data. iter_mut ( ) {
65+ for id in start..=end {
66+ let id_str: String = id. to_string ( ) ;
67+ let id_length = id_str. len ( ) ;
68+
69+ for chunk_size in 1 ..=id_length/2 {
70+ if id_length % chunk_size != 0 { continue ; }
71+
72+ let chunk = & id_str[ 0 ..chunk_size] ;
73+ let repeats = id_length / chunk_size;
74+
75+ if repeats < 2 { continue ; }
76+
77+ if chunk. repeat ( repeats) == id_str {
78+ count += id;
79+ break ;
80+ }
81+ }
82+ }
83+ }
84+
85+ Answer :: Number ( count)
6386 }
6487}
You can’t perform that action at this time.
0 commit comments