attempt 2 day 2 part 2 - works

This commit is contained in:
Neil Hanlon 2024-12-06 13:59:37 -05:00
parent 8bc9fc8517
commit f41814cfc2
Signed by: neil
GPG Key ID: 705BC21EC3C70F34

View File

@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"slices"
"strconv"
"strings"
)
@ -70,10 +71,24 @@ func (report *Report) IsValid() bool {
}
if !report.valid && report.flag > 0 && !report.dampened {
fmt.Printf("DAMPING:%v\n", report.levels)
report.levels = remove(report.levels, report.flag)
fmt.Printf("DAMPING:%v\n", report.levels)
return report.IsValid()
// First, try and just remove the flagged problem
orig := make([]int, len(report.levels))
for idx := range report.levels {
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
}
@ -102,6 +117,9 @@ func (report *Report) ValidDirection() bool {
if prev := idx - 1; prev < 0 {
continue
}
if val == 0 {
break
}
last := report.levels[idx-1]
switch report.direction {
case "ASC":