Javascript Solution. It all probably can be done easier, I don't know, it works. Don't kick me :).
(function(){functiongetNewRecipe(recipes,index1,index2){letsum=recipes[index1]+recipes[index2];returnsum.toString().split('').map(item=>+item);}functiongetNextPosition(elf,recipes){letsteps=recipes[elf.current]+1;letindex=elf.current;for(leti=0;i<steps;i++){index+=1;if(index>recipes.length-1){index=0;}}returnindex;}functionfindAnswer(limit){letrecipes=[3,7];letfirstElf={current:0};letsecondElf={current:1};letmeScore=limit.toString();letfirstAnswer;letsecondAnswer;for(leti=0;i<5800000*5;i++){{firstElf.current=getNextPosition(firstElf,recipes);secondElf.current=getNextPosition(secondElf,recipes);recipes.push(...getNewRecipe(recipes,firstElf.current,secondElf.current));}if(recipes.slice(recipes.length-meScore.length,recipes.length).join('')===meScore){i=Infinity;secondAnswer=recipes.length-meScore.length;}elseif(recipes.slice(recipes.length-meScore.length-1,recipes.length-1).join('')===meScore){i=Infinity;secondAnswer=recipes.length-meScore.length-1;}if(recipes.length>=limit+10&&firstAnswer===undefined){firstAnswer=recipes.slice(limit,limit+10).join('');}}console.log('FINISHED!',firstAnswer,secondAnswer);return{firstAnswer,secondAnswer};}constanswer=findAnswer(765071);// your puzzle input})();
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Javascript Solution. It all probably can be done easier, I don't know, it works. Don't kick me :).