diff --git a/02/main.go b/02/main.go index 19f334b..a19a17f 100644 --- a/02/main.go +++ b/02/main.go @@ -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":