Day 10, first half.

This commit is contained in:
Anna Rose 2020-12-11 10:19:50 +00:00
parent 4e10039bfb
commit fe5ee7bc16

48
2020/day10.go Normal file
View File

@ -0,0 +1,48 @@
package main
import (
"fmt"
"log"
"os"
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
)
func getMax(values map[int]bool) int {
max := 0
for value, _ := range values {
if value > max {
max = value
}
}
return max
}
func main() {
// step := os.Args[1]
values := fileutils.InputParserIntMap(os.Args[2])
diffMap := make(map[int]int)
device := getMax(values) + 3
values[device] = true
diff := 0
for i := 0; i < device; i++ {
// increment diff, make sure we haven't broken the chain
// Note that we're actually logically checking the joltage at i+1
// but that serves us well here
diff++
if diff > 3 {
log.Panicf("Diff too big, bailing.")
}
// if we have a device at this joltage, register and reset count
if values[i+1] {
diffMap[diff]++
diff = 0
}
}
fmt.Println(diffMap[1] * diffMap[3])
}