-
Notifications
You must be signed in to change notification settings - Fork 0
/
day1.go
48 lines (42 loc) · 1.03 KB
/
day1.go
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
package main
import (
"fmt"
"sort"
"strconv"
)
func day1Cleaner(dirtyInput []string) []int {
var puzzleInput []int
for _, i := range dirtyInput {
j, err := strconv.Atoi(i)
check(err)
puzzleInput = append(puzzleInput, j)
}
sort.Ints(puzzleInput)
return puzzleInput
}
// Day1Solution1 finds two numbers in the list that equal 2020 when summed
func Day1Solution1(dirtyInput []string, results chan string) {
puzzleInput := day1Cleaner(dirtyInput)
for _, x := range puzzleInput {
for _, y := range puzzleInput {
if x+y == 2020 {
results <- fmt.Sprintf("part1: %v * %v = %v; ", x, y, x*y)
return
}
}
}
}
// Day1Solution2 finds three numbers in the list that equal 2020 when summed
func Day1Solution2(dirtyInput []string, results chan string) {
puzzleInput := day1Cleaner(dirtyInput)
for _, x := range puzzleInput {
for _, y := range puzzleInput {
for _, z := range puzzleInput {
if x+y+z == 2020 {
results <- fmt.Sprintf("part2: %v * %v * %v = %v; ", x, y, z, x*y*z)
return
}
}
}
}
}