diff --git a/src/components/PresentsPuzzle.tsx b/src/components/PresentsPuzzle.tsx index fe945da..b465e21 100644 --- a/src/components/PresentsPuzzle.tsx +++ b/src/components/PresentsPuzzle.tsx @@ -273,7 +273,26 @@ const PresentsPuzzle = ({ }; const stepToEnd = () => { - updateStep(99); + const { presents, aliceOrder: aOrder, bobOrder: bOrder } = initializeSimulation(); + + let aliceCount = 0; + let bobCount = 0; + let winningStep = 99; // default to last step if no winner found + + // Find the step where someone first wins + for (let i = 0; i < 100; i++) { + if (presents.has(aOrder[i])) aliceCount++; + if (presents.has(bOrder[i])) bobCount++; + + // Check if someone won on this step + if (aliceCount === 26 || bobCount === 26) { + winningStep = i; + break; + } + } + + // Update to that step + updateStep(winningStep); }; const stepToStart = () => {