From f41814cfc288f3b08e5fb91295e878cc4da5053f Mon Sep 17 00:00:00 2001 From: Neil Hanlon Date: Fri, 6 Dec 2024 13:59:37 -0500 Subject: [PATCH] attempt 2 day 2 part 2 - works --- 02/main.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) 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":