Skip to content

Commit

Permalink
Create GospersHack.js
Browse files Browse the repository at this point in the history
  • Loading branch information
everthis authored Jul 2, 2024
1 parent 4c4513b commit df41089
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/GospersHack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function GospersHack(k, n)
{
let set = (1 << k) - 1;
let limit = (1 << n);
while (set < limit)
{
DoStuff(set);

// Gosper's hack:
let c = set & - set;
let r = set + c;
set = Math.floor(((r ^ set) >> 2) / c) | r;
}
}

0 comments on commit df41089

Please sign in to comment.