Skip to content

Commit

Permalink
use bitwiseIterator to speed up the iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
jsgao0 committed Sep 5, 2023
1 parent c723339 commit 4fd6f13
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ function printProgress(progress) {
new Intl.NumberFormat().format(allCombinations.length * BigInt(costPerTicket))
}`);

const allCombinationsIterator = allCombinations.bitwiseIterator();
let totalBonus = 0n;
for(let i = 0n; i < allCombinations.length; i++) {
const comb = allCombinations.nth(i);
const comb = allCombinationsIterator.next().value;
const matchedNumbers = comb.filter(n => randomNumbers.includes(n)).length;
const matchedSpecialNumber = comb.includes(randomSpecialNumber) ? 1 : 0;
const prizeKey = `${matchedNumbers}:${matchedSpecialNumber}`;
Expand Down

0 comments on commit 4fd6f13

Please sign in to comment.