From faaff8013f612ef64502e47a00d970f840da8122 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Wed, 4 Dec 2024 15:33:55 +0100 Subject: [PATCH] add comments add comments to day02 and day03 --- 2024/02/main.go | 3 ++- 2024/03/main.go | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/2024/02/main.go b/2024/02/main.go index adcaa28..2076a95 100644 --- a/2024/02/main.go +++ b/2024/02/main.go @@ -43,7 +43,7 @@ func (r report) isSave() bool { return false } - for i := 0; i < len(r.levels)-1; i++ { + for i := 0; i < len(r.levels)-1; i++ { // iterate til second last level if !isValidLevelDifference(r.levels[i], r.levels[i+1]) { return false } @@ -94,6 +94,7 @@ func (r report) isSaveWithDamper() bool { func (r report) removeLevelByIndex(dropIndex int) report { var newlevels []int + // create new slice w/o passed index position newlevels = append(newlevels, r.levels[:dropIndex]...) newlevels = append(newlevels, r.levels[dropIndex+1:]...) diff --git a/2024/03/main.go b/2024/03/main.go index 9478c34..97da925 100644 --- a/2024/03/main.go +++ b/2024/03/main.go @@ -20,6 +20,7 @@ func main() { } func findAndExecuteInstructions(memory string) (res int) { + // find all `mul()` and save numbers as MatchGroup 1 + 2 re := regexp.MustCompile(`mul\((\d{1,3}),(\d{1,3})\)`) instructions := re.FindAllStringSubmatch(memory, -1) @@ -31,6 +32,8 @@ func findAndExecuteInstructions(memory string) (res int) { } func findAndExecuteEnabledInstructions(memory string) (res int) { + // find all `mul()` and save numbers as MatchGroup 1 + 2 + // save `do()` and `dont()` in MatchGroup 0 re := regexp.MustCompile(`mul\((\d{1,3}),(\d{1,3})\)|do\(\)|don't\(\)`) instructions := re.FindAllStringSubmatch(memory, -1)