Last active
December 21, 2019 21:35
-
-
Save emukupa/08d88c4d26b5d934e4f9cd7ab8def66d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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