44 lines
774 B
Go
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)
|
|
}
|