File tree Expand file tree Collapse file tree 1 file changed +12
-9
lines changed
Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -62,15 +62,18 @@ pub fn part_2(data: crate::DataIn) -> crate::AoCResult<String> {
6262 let len = numstr. len ( ) ;
6363 let max_len = len / 2 ;
6464
65- // This takes 6 seconds but whatever 😭
66- ( 1 ..=max_len) . any ( |size| {
67- let substr = & numstr[ 0 ..size] ;
68- numstr
69- . chars ( )
70- . chunks ( size)
71- . into_iter ( )
72- . all ( |window| window. collect :: < String > ( ) == substr)
73- } )
65+ // This takes 4 seconds but whatever 😭
66+ ( 1 ..=max_len)
67+ // Filter out any number that can't make valid windows
68+ . filter ( |size| len % size == 0 )
69+ . any ( |size| {
70+ let substr = & numstr[ 0 ..size] ;
71+ numstr
72+ . chars ( )
73+ . chunks ( size)
74+ . into_iter ( )
75+ . all ( |window| window. collect :: < String > ( ) == substr)
76+ } )
7477 } )
7578 } )
7679 . inspect ( |serial| log:: debug!( "Found invalid serial number {serial}" ) )
You can’t perform that action at this time.
0 commit comments