add comments
add comments to day02 and day03
This commit is contained in:
parent
d67d377bd4
commit
faaff8013f
2 changed files with 5 additions and 1 deletions
|
@ -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:]...)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue