Created
May 5, 2023 20:16
-
-
Save avestura/7365545cbd221891661a58108079ec39 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 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