Skip to content

Instantly share code, notes, and snippets.

@ghaiklor
Last active January 5, 2016 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghaiklor/107355c3df044683704a to your computer and use it in GitHub Desktop.
Save ghaiklor/107355c3df044683704a to your computer and use it in GitHub Desktop.
Advent of Code (Day 10 Part 2)
const INPUT = '1113122113';
const FIND_REPETITIONS_REGEX = /(\d)\1*/g;
const lookAndSay = input => input.match(FIND_REPETITIONS_REGEX).reduce((acc, char) => acc + `${char.length}${char[0]}`, '');
let result = INPUT;
for (let i = 0; i < 50; i++) {
result = lookAndSay(result);
}
console.log(result.length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment