Skip to content

Instantly share code, notes, and snippets.

@ghaiklor
Last active August 29, 2017 20:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghaiklor/8549a92b6ca6975602aa to your computer and use it in GitHub Desktop.
Save ghaiklor/8549a92b6ca6975602aa to your computer and use it in GitHub Desktop.
Advent of Code (Day 10 Part 1)
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 < 40; 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