1
0
Fork 0

add comments

add comments to day02 and day03
This commit is contained in:
Sebastian Mark 2024-12-04 15:33:55 +01:00
parent d67d377bd4
commit faaff8013f
2 changed files with 5 additions and 1 deletions

View file

@ -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:]...)

View file

@ -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)