adventofcode/2020/day01/main.go
2020-12-01 13:53:24 -06:00

42 lines
819 B
Go

package main
import (
"fmt"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := h.StdinToIntSlice()
fmt.Println("# Part 1")
part1(inp)
fmt.Println("# Part 2")
part2(inp)
}
func part1(input []int) {
for i := 0; i < len(input); i++ {
for j := i + 1; j < len(input); j++ {
if input[i]+input[j] == 2020 {
fmt.Printf("Entries %d and %d sum to 2020\n", i, j)
fmt.Printf("Answer: %d\n", input[i]*input[j])
return
}
}
}
}
func part2(input []int) {
for i := 0; i < len(input); i++ {
for j := i + 1; j < len(input); j++ {
for k := j + 1; k < len(input); k++ {
if input[i]+input[j]+input[k] == 2020 {
fmt.Printf("Entries %d, %d, and %d sum to 2020\n", i, j, k)
fmt.Printf("Answer: %d\n", input[i]*input[j]*input[k])
return
}
}
}
}
}