This commit is contained in:
z1glr
2025-12-08 20:38:20 +01:00
parent 0cf3fb738c
commit 8da2c12663
3 changed files with 55 additions and 47 deletions

View File

@@ -4,7 +4,6 @@ import (
"fmt"
"math"
"os"
"strconv"
"strings"
)
@@ -13,22 +12,18 @@ func countJoltage(i int, rows *[][]int) int {
for _, rowNumbers := range *rows {
index := 0
thisJoltage := 0
for digitPlace := range i {
index = int(math.Max(float64(index), float64(digitPlace)))
for candidate := index; candidate <= len(rowNumbers)-i+digitPlace; candidate++ {
if rowNumbers[candidate] > rowNumbers[index] {
index = candidate
}
}
thisJoltage += rowNumbers[index] * int(math.Pow10(i-digitPlace-1))
totalJoltage += rowNumbers[index] * int(math.Pow10(i-digitPlace-1))
index++
}
totalJoltage += thisJoltage
}
return totalJoltage
@@ -66,11 +61,3 @@ func loadData(test bool) string {
return strings.TrimSpace(string(cont))
}
}
func parseInt(s string) int {
if ii, err := strconv.Atoi(s); err != nil {
panic(err)
} else {
return ii
}
}