Day 1 part 2

This commit is contained in:
Araozu 2024-02-24 21:13:14 -05:00
parent c9e8ca3669
commit 7a356e8734
2 changed files with 26 additions and 1 deletions

View File

@ -3,5 +3,5 @@ package main
import "advent-20/solutions"
func main() {
solutions.Day01Part01()
solutions.Day01Part02()
}

View File

@ -27,3 +27,28 @@ func Day01Part01() {
}
}
}
func Day01Part02() {
input := ReadInput("01", false)
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 {
fmt.Println(values[i] * values[j] * values[k])
return
}
}
}
}
}