Skip to content

Instantly share code, notes, and snippets.

@jmc734
Last active August 29, 2015 14:05
Show Gist options
  • Save jmc734/852aa8d05c44e5bbd4d2 to your computer and use it in GitHub Desktop.
Save jmc734/852aa8d05c44e5bbd4d2 to your computer and use it in GitHub Desktop.
Look-and-Say Sequence Generator
var list = [1];
var N = 10;
for(var i = 0; i < N; i++){
list = list.reduce(function(prev, cur, index, array){
var last = prev.splice(prev.length - 2);
if(cur === last[1]){
last[0]++;
} else {
last.push(1, cur);
}
return prev.concat(last);
}, [0,list[0]]);
console.log(list);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment