attempt 2 day 2 part 2 - works
This commit is contained in:
parent
8bc9fc8517
commit
f41814cfc2
26
02/main.go
26
02/main.go
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -70,10 +71,24 @@ func (report *Report) IsValid() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !report.valid && report.flag > 0 && !report.dampened {
|
if !report.valid && report.flag > 0 && !report.dampened {
|
||||||
fmt.Printf("DAMPING:%v\n", report.levels)
|
// First, try and just remove the flagged problem
|
||||||
report.levels = remove(report.levels, report.flag)
|
orig := make([]int, len(report.levels))
|
||||||
fmt.Printf("DAMPING:%v\n", report.levels)
|
for idx := range report.levels {
|
||||||
return report.IsValid()
|
copy(orig, report.levels)
|
||||||
|
orig := slices.Delete(orig, idx, idx+1)
|
||||||
|
|
||||||
|
dampened := Report{
|
||||||
|
number: report.number,
|
||||||
|
valid: report.valid,
|
||||||
|
direction: report.direction,
|
||||||
|
flag: report.flag,
|
||||||
|
dampened: report.dampened,
|
||||||
|
levels: orig,
|
||||||
|
}
|
||||||
|
if report.valid = dampened.IsValid(); report.valid {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return report.valid
|
return report.valid
|
||||||
}
|
}
|
||||||
@ -102,6 +117,9 @@ func (report *Report) ValidDirection() bool {
|
|||||||
if prev := idx - 1; prev < 0 {
|
if prev := idx - 1; prev < 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if val == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
last := report.levels[idx-1]
|
last := report.levels[idx-1]
|
||||||
switch report.direction {
|
switch report.direction {
|
||||||
case "ASC":
|
case "ASC":
|
||||||
|
Loading…
Reference in New Issue
Block a user