|
|
@@ -7,34 +7,38 @@ import (
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
-func is_palindrome(id int) bool {
|
|
|
- fmt.Printf("analyzing %v\n", id)
|
|
|
- return true
|
|
|
+func is_valid(id int) bool {
|
|
|
+ idstr := strconv.Itoa(id)
|
|
|
+ size_idstr := len(idstr)
|
|
|
+ if (size_idstr % 2) != 0 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return idstr[:size_idstr/2] == idstr[size_idstr/2:]
|
|
|
}
|
|
|
|
|
|
-func count_palindroms(lb, ub int) int{
|
|
|
- fmt.Printf("counting palindroms %v until %v\n", lb, ub)
|
|
|
+func count_valids(lb, ub int) int{
|
|
|
+ res := 0
|
|
|
for i:=lb; i <= ub; i++ {
|
|
|
- is_palindrome(i)
|
|
|
+ if is_valid(i) {
|
|
|
+ res += i
|
|
|
+ }
|
|
|
}
|
|
|
- return 0
|
|
|
+ return res
|
|
|
}
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
fmt.Println("Advent of Code 2025 - Day 2 - Part 1")
|
|
|
- f, _ := os.ReadFile("2/test")
|
|
|
- fmt.Println(string(f))
|
|
|
+ f, _ := os.ReadFile("2/input")
|
|
|
l := strings.Split(string(f), ",")
|
|
|
var ranges []string
|
|
|
- var lower_bound int
|
|
|
- var upper_bound int
|
|
|
+ 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])
|
|
|
- count_palindroms(lower_bound, upper_bound)
|
|
|
- fmt.Println("****")
|
|
|
+ res += count_valids(lower_bound, upper_bound)
|
|
|
}
|
|
|
-
|
|
|
+ fmt.Println(res)
|
|
|
}
|