Skip to content

Instantly share code, notes, and snippets.

@avestura
Created May 5, 2023 20:16
Show Gist options
  • Save avestura/7365545cbd221891661a58108079ec39 to your computer and use it in GitHub Desktop.
Save avestura/7365545cbd221891661a58108079ec39 to your computer and use it in GitHub Desktop.
const getDragon2 = n => {
const getDragonRecurse = (n, complement) => {
if(n === 1) {
return complement ? [0] : [1]
}
const right = getDragonRecurse(n - 1, complement);
const left = getDragonRecurse(n - 1, !complement);
return complement ? [...right, 0, ...left] : [...left, 1, ...right]
}
return getDragonRecurse(n, false).join('')
}
const n = 4;
console.log(getDragon2(n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment