summaryrefslogtreecommitdiff
path: root/2024/go/src/day3/main.go
diff options
context:
space:
mode:
authoromagdy <omar.professional8777@gmail.com>2024-12-04 18:19:33 +0200
committeromagdy <omar.professional8777@gmail.com>2024-12-04 18:19:33 +0200
commit8bf0fd29f7cd29c2933774b02694d8f172626ea1 (patch)
tree2f644167fa055032ca6c34c16bf94b1f4437c927 /2024/go/src/day3/main.go
parentf5accf64b27eacbe09345c13995ef228f2d0db6c (diff)
downloadaoc-8bf0fd29f7cd29c2933774b02694d8f172626ea1.tar.xz
aoc-8bf0fd29f7cd29c2933774b02694d8f172626ea1.zip
Day 4 done.
Diffstat (limited to '2024/go/src/day3/main.go')
-rw-r--r--2024/go/src/day3/main.go50
1 files changed, 24 insertions, 26 deletions
diff --git a/2024/go/src/day3/main.go b/2024/go/src/day3/main.go
index 09e487b..661d7aa 100644
--- a/2024/go/src/day3/main.go
+++ b/2024/go/src/day3/main.go
@@ -23,17 +23,17 @@ func solve_part_one(data string) int {
// FindStringSubmatch returns the full match and all capture groups
matches := regex.FindAllStringSubmatch(data, -1)
- ans := 0
+ ans := 0
- // Iterate over all matches
+ // Iterate over all matches
for _, match := range matches {
// fmt.Printf("Match %d:\n", i+1)
// fmt.Println(" Full match:", match[0]) // Entire match
- left, _ := strconv.Atoi(match[1])
- right , _ := strconv.Atoi(match[2])
- ans += left * right
+ left, _ := strconv.Atoi(match[1])
+ right, _ := strconv.Atoi(match[2])
+ ans += left * right
}
- return ans
+ return ans
}
func solve_part_two(data string) int {
@@ -43,32 +43,30 @@ func solve_part_two(data string) int {
// FindStringSubmatch returns the full match and all capture groups
matches := regex.FindAllStringSubmatch(data, -1)
- ans := 0
- enabled := true
+ ans := 0
+ enabled := true
- // Iterate over all matches
+ // Iterate over all matches
for _, match := range matches {
- left, _ := strconv.Atoi(match[1])
- right , _ := strconv.Atoi(match[2])
- if match[0] == "don't()" {
- enabled = false
- } else if match[0] == "do()" {
- enabled = true
- }
- if enabled {
- ans += left * right
- }
+ left, _ := strconv.Atoi(match[1])
+ right, _ := strconv.Atoi(match[2])
+ if match[0] == "don't()" {
+ enabled = false
+ } else if match[0] == "do()" {
+ enabled = true
+ }
+ if enabled {
+ ans += left * right
+ }
}
- return ans
+ return ans
}
-
-
func main() {
- test := FileRead("../input/day_3.test")
- test_2 := FileRead("../input/day_3_2.test")
- prod := FileRead("../input/day_3.prod")
- // Define the regex pattern with capture groups
+ test := FileRead("../input/day3.test")
+ test_2 := FileRead("../input/day3_2.test")
+ prod := FileRead("../input/day3.prod")
+ // Define the regex pattern with capture groups
fmt.Println("Part_1 test: ", solve_part_one(test))
fmt.Println("Part_1 prod: ", solve_part_one(prod))