From fe5ee7bc16e82baf63c16620b7362731c175ce5b Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Fri, 11 Dec 2020 10:19:50 +0000 Subject: [PATCH] Day 10, first half. --- 2020/day10.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 2020/day10.go diff --git a/2020/day10.go b/2020/day10.go new file mode 100644 index 0000000..49ab39e --- /dev/null +++ b/2020/day10.go @@ -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]) +}