aoc2015/day10/day10.go
Stefan Harmuth b3d99b6975 day10
2020-12-26 06:54:51 +01:00

44 lines
774 B
Go

package day10
import (
"aoc2015/aoclib"
)
func lookAndSay(look []int) (say []int) {
for index := 0; index < len(look); {
firstChar := look[index]
nextIndex := index + 1
if nextIndex == len(look) {
say = append(say, nextIndex-index, firstChar)
} else {
for len(look) > nextIndex && look[nextIndex] == firstChar {
nextIndex++
}
say = append(say, nextIndex-index, firstChar)
}
index = nextIndex
}
return say
}
func Part1(puzzle aoclib.Puzzle) interface{} {
look := puzzle.GetInput2DArrayInt()[0]
for i := 0; i < 40; i++ {
look = lookAndSay(look)
}
return len(look)
}
func Part2(puzzle aoclib.Puzzle) interface{} {
look := puzzle.GetInput2DArrayInt()[0]
for i := 0; i < 50; i++ {
look = lookAndSay(look)
}
return len(look)
}