Compare commits
2 Commits
8dfe3e1f07
...
e34c4084c6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e34c4084c6 | ||
|
|
262d13478d |
3
02/go.mod
Normal file
3
02/go.mod
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module git.z1glr.de/z1glr/advent-of-code-2025/02
|
||||||
|
|
||||||
|
go 1.25.4
|
||||||
2
02/input
Normal file
2
02/input
Normal 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
74
02/main.go
Normal 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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user