File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ function run(n) {
3131
3232 // keep making recipes until we have 10 recipes after the input
3333 let expectedRecipes = n + 10 ;
34- while ( data . recipes . length < expectedRecipes || data . part2 < 0 ) {
34+ while ( ! data . score || data . part2 < 0 ) {
3535 let toAdd = ( data . recipes [ data . elf1 ] + data . recipes [ data . elf2 ] )
3636 . toString ( )
3737 . split ( "" )
@@ -40,6 +40,11 @@ function run(n) {
4040 data . elf1 = ( data . elf1 + 1 + data . recipes [ data . elf1 ] ) % data . recipes . length ;
4141 data . elf2 = ( data . elf2 + 1 + data . recipes [ data . elf2 ] ) % data . recipes . length ;
4242
43+ // check if we already reach the desired number of recipes to get the score
44+ if ( ! data . score && data . recipes . length >= expectedRecipes ) {
45+ data . score = data . recipes . slice ( n , n + 10 ) . join ( "" ) ;
46+ }
47+
4348 // check if we found our input in the recipes list for the first time
4449 // optimization: we just need to look it up at the end of the recipes list, no need to indexOf of the full list each time!
4550 if ( data . part2 < 0 ) {
@@ -54,7 +59,6 @@ function run(n) {
5459 //printStatus(data);
5560 }
5661
57- data . score = data . recipes . slice ( n , n + 10 ) . join ( "" ) ;
5862 return data ;
5963}
6064
You can’t perform that action at this time.
0 commit comments