Compare commits

...

2 Commits

Author SHA1 Message Date
z1glr
e34c4084c6 Merge remote-tracking branch 'refs/remotes/origin/main' 2025-12-03 19:50:02 +01:00
z1glr
262d13478d day 02 - first thing completely from nvim 2025-12-02 21:08:26 +01:00
4 changed files with 81 additions and 0 deletions

3
02/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module git.z1glr.de/z1glr/advent-of-code-2025/02
go 1.25.4

2
02/input Normal file
View File

@@ -0,0 +1,2 @@
9595822750-9596086139,1957-2424,88663-137581,48152-65638,12354817-12385558,435647-489419,518494-609540,2459-3699,646671-688518,195-245,295420-352048,346-514,8686839668-8686892985,51798991-51835611,8766267-8977105,2-17,967351-995831,6184891-6331321,6161577722-6161678622,912862710-913019953,6550936-6625232,4767634976-4767662856,2122995-2257010,1194-1754,779-1160,22-38,4961-6948,39-53,102-120,169741-245433,92902394-92956787,531-721,64-101,15596-20965,774184-943987,8395-11781,30178-47948,94338815-94398813

74
02/main.go Normal file
View File

@@ -0,0 +1,74 @@
package main
import (
"fmt"
"os"
"strconv"
"strings"
)
func readFile(p string) string {
if cont, err := os.ReadFile(p); err != nil {
panic(err)
} else {
return strings.TrimSpace(string(cont))
}
}
func parseInt(s string) int {
if i, err := strconv.Atoi(s); err != nil {
panic(err)
} else {
return i
}
}
func main() {
// data := readFile("test")
data := readFile("input")
idSum := 0
for rr := range strings.SplitSeq(data, ",") {
parts := strings.Split(rr, "-")
from := parseInt(parts[0])
to := parseInt(parts[1])
idMap := map[string]bool{}
for number := from; number <= to; number++ {
candidate := strconv.Itoa(number)
numLen := len(candidate)
for testParts := 2; testParts <= numLen; testParts++ {
if numLen%testParts == 0 {
sliceLen := numLen / testParts
ref := candidate[:sliceLen]
isCode := true
for testPartIndex := 1; testPartIndex < testParts; testPartIndex++ {
if candidate[sliceLen*testPartIndex:sliceLen*(testPartIndex+1)] != ref {
isCode = false
break
}
}
if isCode && !idMap[candidate] {
idMap[candidate] = true
idSum += number
fmt.Println(number)
}
}
}
}
}
fmt.Println(idSum)
}

2
02/test Normal file
View File

@@ -0,0 +1,2 @@
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124