# aoc-2020-day-1-part-1.go -rw-r--r-- 814 bytes View raw
                                                                                
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
48
49
50
51
52
package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"strconv"
	"strings"
)

func getInput() []string {
	file := os.Args[1]
	if file != "" {
		contents, err := ioutil.ReadFile(file)

		if err != nil {
			fmt.Println("error reading file", err)
		}

		return strings.Split(string(contents), "\n")
	} else {
		return []string{"1721", "979", "366", "299", "675", "1456"}
	}
}

func main() {
	input := getInput()
	inputInt := []int{}

	for _, val := range input {
		if val != "" {
			intString, err := strconv.Atoi(val)

			if err != nil {
				fmt.Println("error converting string to val", err)
			}

			inputInt = append(inputInt, intString)
		}
	}

	for i, val := range inputInt {
		rest := append(inputInt[:i], inputInt[i+1:]...)

		for _, y := range rest {
			if y+val == 2020 {
				fmt.Println(y * val)
			}
		}
	}
}