Skip to content

Latest commit

 

History

History
49 lines (35 loc) · 1.74 KB

10.md

File metadata and controls

49 lines (35 loc) · 1.74 KB

Day 10

Part 1

Apply the look-and-say process 40 times on the input string. What is the length of the result?

const input = '1113222113'

const lookAndSay = (numericString) =>
  numericString
    .slice(1)
    .split('')
    .reduce(
      (numbers, n) => {
        const previous = numbers[numbers.length - 1]

        const next = previous[0] === n ? numbers.pop() + n : n
        numbers.push(next)

        return numbers
      },
      [numericString[0]]
    )
    .map((n) => n.length + n[0])
    .join('')

const part1 = Array.from({ length: 40 }).reduce(lookAndSay, input).length
console.log('Part 1:', part1)

Flems link in Part 2.

Part 2

Apply the process 50 times. What is the length of the new result?

const part2 = Array.from({ length: 50 }).reduce(lookAndSay, input).length
console.log('Part 2:', part2)

Try out the final code on flems.io

What did I learn?

Nothing, this puzzle was quite simple.