2024 day 2 part 2 - remove unused code
This commit is contained in:
parent
c26376f49d
commit
2345680352
@ -6,7 +6,6 @@ import (
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
// "slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@ -68,7 +67,6 @@ func checkSafe(nums []int) bool {
|
||||
var current int
|
||||
var isIncreasing bool
|
||||
isSafe := true
|
||||
firstFailedIdx := -1
|
||||
|
||||
for idx, num := range nums {
|
||||
current = num
|
||||
@ -77,9 +75,6 @@ func checkSafe(nums []int) bool {
|
||||
continue
|
||||
}
|
||||
if prev == current {
|
||||
if firstFailedIdx == -1 {
|
||||
firstFailedIdx = idx
|
||||
}
|
||||
isSafe = false
|
||||
break
|
||||
}
|
||||
@ -89,21 +84,12 @@ func checkSafe(nums []int) bool {
|
||||
diff := int(math.Abs(float64(prev) - float64(current)))
|
||||
|
||||
if diff < 1 || diff > 3 {
|
||||
if firstFailedIdx == -1 {
|
||||
firstFailedIdx = idx
|
||||
}
|
||||
isSafe = false
|
||||
}
|
||||
if isIncreasing && (prev > current) {
|
||||
if firstFailedIdx == -1 {
|
||||
firstFailedIdx = idx
|
||||
}
|
||||
isSafe = false
|
||||
}
|
||||
if !isIncreasing && (prev < current) {
|
||||
if firstFailedIdx == -1 {
|
||||
firstFailedIdx = idx
|
||||
}
|
||||
isSafe = false
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user