Created
November 24, 2019 07:15
-
-
Save sayanriju/f85c0c8563310d9d7818f64c707d6aae to your computer and use it in GitHub Desktop.
Conway Sequence
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
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