1
Fork 0
This repository has been archived on 2020-12-13. You can view files and clone it, but cannot push or open issues or pull requests.
AdventOfCode2020/1/2/main.go

50 lines
1.1 KiB
Go

package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
)
// The Elves in accounting are thankful for your help; one of them even offers you a starfish coin they had left over from a past vacation. They offer you a second one if you can find three numbers in your expense report that meet the same criteria.
// Using the above example again, the three entries that sum to 2020 are 979, 366, and 675. Multiplying them together produces the answer, 241861950.
// In your expense report, what is the product of the three entries that sum to 2020?
func main() {
file, err := os.Open("../input.txt")
if err != nil {
log.Fatal(err)
}
defer file.Close()
numbers := []int{}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
n, err := strconv.Atoi(scanner.Text())
if err != nil {
log.Fatal(err)
}
numbers = append(numbers, n)
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
for _, i := range numbers {
for _, j := range numbers {
for _, k := range numbers {
if i+j+k == 2020 {
fmt.Println(i * j * k)
return
}
}
}
}
}