|
|
@ -24,5 +24,26 @@ func (d Day3) Part1(r io.Reader) string { |
|
|
|
} |
|
|
|
|
|
|
|
func (d Day3) Part2(r io.Reader) string { |
|
|
|
return "" |
|
|
|
var bd strings.Builder |
|
|
|
var sum int |
|
|
|
io.Copy(&bd, r) |
|
|
|
|
|
|
|
re := regexp.MustCompile(`mul\((\d{1,3}),(\d{1,3})\)|do\(\)|don\'t\(\)`) |
|
|
|
|
|
|
|
matches := re.FindAllStringSubmatch(bd.String(), -1) |
|
|
|
|
|
|
|
var skip bool |
|
|
|
for _, match := range matches { |
|
|
|
switch match[0] { |
|
|
|
case "do()": |
|
|
|
skip = false |
|
|
|
case "don't()": |
|
|
|
skip = true |
|
|
|
default: |
|
|
|
if !skip { |
|
|
|
sum += atoi(match[1]) * atoi(match[2]) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return printi(sum) |
|
|
|
} |
|
|
|