2020 day 1 Complete
This commit is contained in:
41
2020/day01/main.go
Normal file
41
2020/day01/main.go
Normal file
@@ -0,0 +1,41 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user