-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
47 lines (39 loc) · 642 Bytes
/
main.go
File metadata and controls
47 lines (39 loc) · 642 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"encoding/csv"
"fmt"
"io"
"os"
"path"
"strconv"
)
func parse(r io.Reader) {
csvReader := csv.NewReader(r)
rows, err := csvReader.ReadAll()
if err != nil {
panic(err)
}
var items []int
for _, item := range rows {
item, err := strconv.Atoi(item[0])
if err != nil {
panic(err)
}
items = append(items, item)
}
for i, item1 := range items {
for j, item2 := range items {
if i != j && item1+item2 == 2020 {
fmt.Println(item1 * item2)
return
}
}
}
}
func main() {
input, err := os.Open(path.Join("2020", "1", "input.txt"))
if err != nil {
panic(err)
}
parse(input)
}