day10
This commit is contained in:
parent
aa19c8c5b1
commit
b3d99b6975
@ -56,6 +56,25 @@ func (p *Puzzle) GetInputArrayInt() []int {
|
|||||||
return p.RawInputInt
|
return p.RawInputInt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Puzzle) GetInput2DArrayInt() [][]int {
|
||||||
|
var ret [][]int
|
||||||
|
for _, v := range p.GetInputArray() {
|
||||||
|
var thisIntLine []int
|
||||||
|
for _, c := range v {
|
||||||
|
value, err := strconv.Atoi(string(c))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Cannot convert string to int: (%c in %s)", c, v)
|
||||||
|
} else {
|
||||||
|
thisIntLine = append(thisIntLine, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = append(ret, thisIntLine)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
func (p Puzzle) Solve(partFunction func(p Puzzle) interface{}, day int, part int, timeit bool, timeitNumber int) {
|
func (p Puzzle) Solve(partFunction func(p Puzzle) interface{}, day int, part int, timeit bool, timeitNumber int) {
|
||||||
var result interface{}
|
var result interface{}
|
||||||
if !timeit {
|
if !timeit {
|
||||||
|
|||||||
43
day10/day10.go
Normal file
43
day10/day10.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
1
inputs/10_test
Normal file
1
inputs/10_test
Normal file
@ -0,0 +1 @@
|
|||||||
|
1
|
||||||
4
main.go
4
main.go
@ -11,6 +11,7 @@ import (
|
|||||||
"aoc2015/day07"
|
"aoc2015/day07"
|
||||||
"aoc2015/day08"
|
"aoc2015/day08"
|
||||||
"aoc2015/day09"
|
"aoc2015/day09"
|
||||||
|
"aoc2015/day10"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@ -54,6 +55,9 @@ func initDayFunctions() {
|
|||||||
dayFunctions[9] = make(map[int]func(puzzle aoclib.Puzzle) interface{}, 2)
|
dayFunctions[9] = make(map[int]func(puzzle aoclib.Puzzle) interface{}, 2)
|
||||||
dayFunctions[9][1] = day09.Part1
|
dayFunctions[9][1] = day09.Part1
|
||||||
dayFunctions[9][2] = day09.Part2
|
dayFunctions[9][2] = day09.Part2
|
||||||
|
dayFunctions[10] = make(map[int]func(puzzle aoclib.Puzzle) interface{}, 2)
|
||||||
|
dayFunctions[10][1] = day10.Part1
|
||||||
|
dayFunctions[10][2] = day10.Part2
|
||||||
}
|
}
|
||||||
|
|
||||||
func execute(thisDay int) {
|
func execute(thisDay int) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user