Day 2 part 1

This commit is contained in:
bdnugget committed 2024-12-19 00:38:36 +01:00
1 parent 1e3f83b7d9
commit 09738f36d7
2 files changed
+33 -5

No files matched your search

+27 -5
View File
@@ -1,17 +1,39 @@
package day02
import (
"fmt"
_ "fmt"
"slices"
"strings"
"github.com/bdnugget/AoC_2024/utils"
)
func Part01() int {
reports := utils.InputLines("./day02/input")
reportLines := utils.InputLines("./day02/input")
var reports [][]int
for _, report := range reportLines {
levels := strings.Fields(report)
var row []int
for i, level := range levels {
levelInt := utils.MustAtoi(level)
if i == 0 {
row = append(row, levelInt)
} else if i > 0 && utils.AbsInt(levelInt-row[i-1]) >= 1 && utils.AbsInt(levelInt-row[i-1]) <= 3 {
row = append(row, levelInt)
} else {
row = nil
break
}
}
if row == nil {
continue
}
if slices.IsSorted(row) || slices.IsSortedFunc(row, func(a, b int) int { return b - a }) {
reports = append(reports, row)
}
fmt.Println(reports[1])
return 420
}
return len(reports)
}
func Part02() int {
+6
View File
@@ -0,0 +1,6 @@
7 6 4 2 1
1 2 7 8 9
9 7 6 2 1
1 3 2 4 5
8 6 4 4 1
1 3 6 7 9