aoc2015/day10/day10.go
2020-12-26 10:26:29 +01:00

44 lines
771 B
Go

package day10
import (
tools "shtools"
)
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 tools.Puzzle) interface{} {
look := puzzle.GetInput2DArrayInt()[0]
for i := 0; i < 40; i++ {
look = lookAndSay(look)
}
return len(look)
}
func Part2(puzzle tools.Puzzle) interface{} {
look := puzzle.GetInput2DArrayInt()[0]
for i := 0; i < 50; i++ {
look = lookAndSay(look)
}
return len(look)
}