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

40 lines
945 B
Go
Raw Normal View History

2020-12-01 22:06:44 +00:00
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
2020-12-01 22:19:04 +00:00
// 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?
2020-12-01 22:06:44 +00:00
func main() {
2020-12-01 22:26:47 +00:00
file, _ := os.Open("../input.txt")
2020-12-01 22:06:44 +00:00
defer file.Close()
numbers := []int{}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
2020-12-01 22:26:47 +00:00
n, _ := strconv.Atoi(scanner.Text())
2020-12-01 22:06:44 +00:00
numbers = append(numbers, n)
}
for _, i := range numbers {
for _, j := range numbers {
for _, k := range numbers {
if i+j+k == 2020 {
fmt.Println(i * j * k)
return
}
}
}
}
}