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]) }