Skip to content

Instantly share code, notes, and snippets.

@sayanriju
Created November 24, 2019 07:15
Show Gist options
  • Save sayanriju/f85c0c8563310d9d7818f64c707d6aae to your computer and use it in GitHub Desktop.
Save sayanriju/f85c0c8563310d9d7818f64c707d6aae to your computer and use it in GitHub Desktop.
Conway Sequence
function lookandsay(str) {
return str.replace(/(.)\1*/g, (seq, p1) => seq.length.toString() + p1)
}
function conway(n) {
if (n === 1) return "1"
return lookandsay(conway(n - 1))
}
Array(10).fill().map((_, idx) => console.log(conway(idx + 1)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment