You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
664 B
42 lines
664 B
package day10
|
|
|
|
import (
|
|
"log"
|
|
)
|
|
|
|
func Solve2() {
|
|
log.Printf("2020-12-10.02: Answer: %d\n", calc(rows))
|
|
}
|
|
|
|
func calc(data []int) int {
|
|
// Some cached answers, these works since we check if they
|
|
// increment by one when we split up the data below, so if the
|
|
// chain is a certain length, we know it works.
|
|
switch len(data) {
|
|
case 0, 1, 2:
|
|
return 1
|
|
case 3:
|
|
return 2
|
|
case 4:
|
|
return 4
|
|
case 5:
|
|
return 7
|
|
}
|
|
|
|
// Locate a good place to break the chain in the middle
|
|
i := 0
|
|
for i = 0; i < len(data)-1; i++ {
|
|
if data[i+1] == data[i]+1 {
|
|
continue
|
|
}
|
|
|
|
break
|
|
}
|
|
|
|
if len(data[:i]) >= 0 {
|
|
return calc(data[:i+1]) * calc(data[i+1:])
|
|
}
|
|
|
|
return 0
|
|
}
|