This commit is contained in:
PedroEdiaz
2025-12-01 16:55:48 -06:00
parent 62bdc3c593
commit 915065d2e6
4 changed files with 93 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
**.txt

75
2025/01/main.go Normal file
View File

@@ -0,0 +1,75 @@
package main
import (
"bufio"
"fmt"
"os"
"regexp"
"strconv"
)
func main() {
sum := 50
res1 := 0
res2 := 0
file, err := os.Open("./input.txt")
//file, err := os.Open("./test.txt")
if err != nil {
return
}
defer file.Close()
re := regexp.MustCompile("(L|R)(\\w+)")
scanner := bufio.NewScanner(file)
for scanner.Scan() {
// Since re : "(L|R)(\w+)", we can parse it as the following i
i := 0
{
m := re.FindStringSubmatch(scanner.Text())
i, _ = strconv.Atoi(m[2])
if m[1] == "L" {
i *= -1
}
}
// Handle sum +=i as mod(100) and work w/res2
{
// Avoid counting rebundant match
if sum == 0 && i < 0 {
res2 -= 1
}
sum += i
for sum < 0 {
sum += 100
res2 += 1
}
for sum > 100 {
sum -= 100
res2 += 1
}
if sum == 100 {
sum -= 100
}
}
// work w/res1
if sum == 0 {
res1 += 1
}
}
if err := scanner.Err(); err != nil {
return
}
fmt.Println(res1, res1+res2)
}

10
2025/01/test.txt Normal file
View File

@@ -0,0 +1,10 @@
L68
L30
R48
L5
R60
L55
L1
L99
R14
L82

7
2025/Makefile Normal file
View File

@@ -0,0 +1,7 @@
INPUT = \
01/input.txt
.SUFFIXES: .txt
$(INPUT):
curl "https://adventofcode.com/2025/day/`echo $@|sed -r 's,^0*(\w+/input).txt$$,\1,'`" -H 'Cookie: session=$(SESSION)' > $@