36 lines
614 B
Go
36 lines
614 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
|
||
|
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
step := os.Args[1]
|
||
|
values := fileutils.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
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|