|
|
@@ -0,0 +1,62 @@
|
|
|
+package main
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "os"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
+func is_kinvalid(id string, k int) bool{
|
|
|
+ size_idstr := len(id)
|
|
|
+ if (size_idstr % k) != 0 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ l:= size_idstr / k
|
|
|
+
|
|
|
+ for i:= 0; i+l < size_idstr ; i+=l {
|
|
|
+ if id[i : i+l] != id[i+l : i+2*l]{
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
+func is_invalid(id int) bool {
|
|
|
+ idstr := strconv.Itoa(id)
|
|
|
+ size_idstr := len(idstr)
|
|
|
+ for k:=2; k <= size_idstr; k++{
|
|
|
+ if is_kinvalid(idstr, k) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
+func count_invalids(lb, ub int) int{
|
|
|
+ res := 0
|
|
|
+ for i:=lb; i <= ub; i++ {
|
|
|
+ if is_invalid(i) {
|
|
|
+ res += i
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res
|
|
|
+}
|
|
|
+
|
|
|
+func main() {
|
|
|
+ fmt.Println("Advent of Code 2025 - Day 2 - Part 2")
|
|
|
+ f, _ := os.ReadFile("2/input")
|
|
|
+ l := strings.Split(string(f), ",")
|
|
|
+ var ranges []string
|
|
|
+ var lower_bound, upper_bound int
|
|
|
+ res:=0
|
|
|
+ for _,value := range l {
|
|
|
+ ranges = strings.Split(value,"-")
|
|
|
+ lower_bound, _ = strconv.Atoi(ranges[0])
|
|
|
+ upper_bound, _ = strconv.Atoi(ranges[1])
|
|
|
+ res += count_invalids(lower_bound, upper_bound)
|
|
|
+ }
|
|
|
+ fmt.Println(res)
|
|
|
+}
|