Skip to content

Instantly share code, notes, and snippets.

@e-mihaylin
Created July 19, 2018 10:22
Show Gist options
  • Select an option

  • Save e-mihaylin/4f3cced0ee3b667a6fbc80d56b86b32a to your computer and use it in GitHub Desktop.

Select an option

Save e-mihaylin/4f3cced0ee3b667a6fbc80d56b86b32a to your computer and use it in GitHub Desktop.
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