Created
July 19, 2018 10:22
-
-
Save e-mihaylin/4f3cced0ee3b667a6fbc80d56b86b32a 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 hamming = n => { | |
| const seq = [1]; | |
| let i2 = 0, i3 = 0, i5 = 0; | |
| for (let i = 1; i < n; i++) { | |
| let x = Math.min(2 * seq[i2], 3 * seq[i3], 5 * seq[i5]); | |
| seq.push(x); | |
| if (2 * seq[i2] <= x) i2++; | |
| if (3 * seq[i3] <= x) i3++; | |
| if (5 * seq[i5] <= x) i5++; | |
| } | |
| return seq[n - 1]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment