|
@@ -57,7 +57,6 @@ func part1(muls [][]int) int {
|
|
func part2(lines []string) int {
|
|
func part2(lines []string) int {
|
|
var result int
|
|
var result int
|
|
multiply := true
|
|
multiply := true
|
|
- re := regexp.MustCompile(`mul\(\d+,\d+\)`)
|
|
|
|
|
|
|
|
for _, line := range lines {
|
|
for _, line := range lines {
|
|
var startIndex, endIndex int
|
|
var startIndex, endIndex int
|
|
@@ -78,16 +77,7 @@ func part2(lines []string) int {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|
|
- matches := re.FindAllString(line[startIndex:endIndex], -1)
|
|
|
|
- for _, match := range matches {
|
|
|
|
- mul := make([]int, 2)
|
|
|
|
- n, err := fmt.Sscanf(match, "mul(%d,%d)", &mul[0], &mul[1])
|
|
|
|
- if n != 2 || err != nil {
|
|
|
|
- log.Fatalf("Bad input: %s", err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- result += mul[0] * mul[1]
|
|
|
|
- }
|
|
|
|
|
|
+ result += getResults(line[startIndex:endIndex])
|
|
|
|
|
|
line = line[endIndex:]
|
|
line = line[endIndex:]
|
|
startIndex = 0
|
|
startIndex = 0
|