day 06
This commit is contained in:
15
03/main.go
15
03/main.go
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user