Skip to content

Instantly share code, notes, and snippets.

@emukupa
Last active December 21, 2019 21:35
Show Gist options
  • Save emukupa/08d88c4d26b5d934e4f9cd7ab8def66d to your computer and use it in GitHub Desktop.
Save emukupa/08d88c4d26b5d934e4f9cd7ab8def66d to your computer and use it in GitHub Desktop.
const mersenneSequenceNumber = x => 2 * x + 1; // f(x) = 2x + 1
function mersenneSequence(upTo = 10) {
const list = [0]; // init with the first number
// make the rest using the previous number in the list
for (let i = 0; i < upTo; i++) {
list.push(mersenneSequenceNumber(list[i]));
}
return list;
}
console.log(mersenneSequence()); // you can pass in a number, if not 10 is used
/*
[
0, 1, 3, 7,
15, 31, 63, 127,
255, 511, 1023
]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment