Abderrahmane Faiz 2 долоо хоног өмнө
parent
commit
38b8d25de3
2 өөрчлөгдсөн 19 нэмэгдсэн , 15 устгасан
  1. 18 14
      2/solve_1.go
  2. 1 1
      README.md

+ 18 - 14
2/solve_1.go

@@ -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)
 }

+ 1 - 1
README.md

@@ -21,7 +21,7 @@ Each day's folder is named after the day number (`1` to `12`). Inside each folde
 | Day | Part 1 | Part 2 |
 |-----|--------|--------|
 | 1   | ✅     | ✅     |
-| 2   |      | ⬜     |
+| 2   |      | ⬜     |
 | 3   | ⬜     | ⬜     |
 | 4   | ⬜     | ⬜     |
 | 5   | ⬜     | ⬜     |