49 lines
737 B
Go
49 lines
737 B
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"bytes"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func main() {
|
|
nums := []int{}
|
|
f, err := ioutil.ReadFile("input")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
reader := bufio.NewReader(bytes.NewReader(f))
|
|
for {
|
|
line, err := reader.ReadString('\n')
|
|
if err != nil {
|
|
break
|
|
}
|
|
line = strings.TrimSpace(line)
|
|
if len(line) == 0 {
|
|
continue
|
|
}
|
|
i, err := strconv.Atoi(line)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
nums = append(nums, i)
|
|
}
|
|
|
|
max := len(nums)
|
|
|
|
for p1 := 0; p1 < max; p1++ {
|
|
for p2 := 0; p2 < max; p2++ {
|
|
for p3 := 0; p3 < max; p3++ {
|
|
sum := nums[p1] + nums[p2] + nums[p3]
|
|
if sum == 2020 {
|
|
fmt.Printf("%d", nums[p1]*nums[p2]*nums[p3])
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|