Skip to content

Instantly share code, notes, and snippets.

@chalkpe
Created November 12, 2017 08:12
Show Gist options
  • Select an option

  • Save chalkpe/83fa8d38f3830007a4097ec7449315cd to your computer and use it in GitHub Desktop.

Select an option

Save chalkpe/83fa8d38f3830007a4097ec7449315cd to your computer and use it in GitHub Desktop.
자바스크립트로 구현한 개미 수열 https://en.wikipedia.org/wiki/Look-and-say_sequence
function* ant (seed = '1') {
while (true) yield (seed = seed.replace(/(\d)\1*/g, (m, s) => s + m.length))
}
const seq = ant()
Array.from(Array(11), seq.next, seq).map(a => a.value)
// ["11",
// "12",
// "1121",
// "122111",
// "112213",
// "12221131",
// "1123123111",
// "12213111213113",
// "11221131132111311231",
// "12221231123121133112213111",
// "1123112131122131112112321222113113"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment