adventofcode/2020/day01.go

36 lines
604 B
Go
Raw Normal View History

package main
import (
"fmt"
"os"
2020-12-14 23:27:46 +00:00
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
)
func main() {
step := os.Args[1]
2020-12-14 23:27:46 +00:00
values := util.InputParserIntMap(os.Args[2])
switch step {
case "1":
for x, _ := range values {
if _, ok := values[2020-x]; ok {
answer := x * (2020 - x)
fmt.Println("The answer is:", answer)
return
}
}
case "2":
for x, _ := range values {
target := 2020 - x
for y, _ := range values {
if _, ok := values[target-y]; ok {
answer := x * y * (target - y)
fmt.Println("The answer is:", answer)
return
}
}
}
}
}