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.
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
Nothing, this puzzle was quite simple.