34 lines
562 B
Go
34 lines
562 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"regexp"
|
|
"strconv"
|
|
)
|
|
|
|
func main_p1() {
|
|
content, err := os.ReadFile("./input.txt")
|
|
file_content := string(content)
|
|
|
|
result := 0
|
|
|
|
if err != nil {
|
|
log.Fatalf("failed to open file: %s\n", err)
|
|
}
|
|
|
|
r := regexp.MustCompile(`mul\((\d+),(\d+)\)`)
|
|
matches := r.FindAllStringSubmatch(file_content, -1)
|
|
|
|
for _, m := range matches {
|
|
i1, err := strconv.Atoi(m[1])
|
|
if err != nil { panic(err) }
|
|
i2, err := strconv.Atoi(m[2])
|
|
if err != nil { panic(err) }
|
|
result += (i1 * i2)
|
|
}
|
|
|
|
fmt.Println("Result: ", result)
|
|
}
|