Compare commits

..

No commits in common. "872f7e629d7eac3039d1238facca926449864765" and "c9e8ca36696e9a58a27cd29491f34a91963f7f06" have entirely different histories.

2 changed files with 7 additions and 37 deletions

View File

@ -1,11 +1,7 @@
package main package main
import ( import "advent-20/solutions"
"advent-20/solutions"
"fmt"
)
func main() { func main() {
fmt.Println("Day 01 part 1:\t", solutions.Day01Part01(false)) solutions.Day01Part01()
fmt.Println("Day 01 part 2:\t", solutions.Day01Part02(false))
} }

View File

@ -1,12 +1,13 @@
package solutions package solutions
import ( import (
"fmt"
"strconv" "strconv"
"strings" "strings"
) )
func Day01Part01(isTest bool) int { func Day01Part01() {
input := ReadInput("01", isTest) input := ReadInput("01", true)
values := strings.Split(input, "\n") values := strings.Split(input, "\n")
remainders := make(map[int]bool) remainders := make(map[int]bool)
@ -19,37 +20,10 @@ func Day01Part01(isTest bool) int {
currentRemainder := 2020 - value currentRemainder := 2020 - value
if _, err := remainders[currentRemainder]; err { if _, err := remainders[currentRemainder]; err {
return value * currentRemainder fmt.Println(value * currentRemainder)
break
} else { } else {
remainders[value] = true remainders[value] = true
} }
} }
return -1
}
func Day01Part02(isTest bool) int {
input := ReadInput("01", isTest)
strValues := strings.Split(input, "\n")
values := make([]int, len(strValues))
for i, valueStr := range strValues {
value, err := strconv.Atoi(valueStr)
if err != nil {
panic("Error converting to int")
}
values[i] = value
}
arrLen := len(values)
for i := 0; i < arrLen; i += 1 {
for j := i + 1; j < arrLen; j += 1 {
for k := j + 1; k < arrLen; k += 1 {
if values[i]+values[j]+values[k] == 2020 {
return (values[i] * values[j] * values[k])
}
}
}
}
return -1
} }