Abderrahmane Faiz 2 недель назад
Родитель
Сommit
391dc25d78
2 измененных файлов с 45 добавлено и 1 удалено
  1. 44 0
      9/solve_1.go
  2. 1 1
      README.md

+ 44 - 0
9/solve_1.go

@@ -0,0 +1,44 @@
+package main
+
+import (
+	"bufio"
+	"fmt"
+	"math"
+	"os"
+	"strconv"
+	"strings"
+)
+
+func main() {
+	fmt.Println("Advent of Code 2025 - Day 9 - Part 1")
+	f,_:= os.Open("9/input")
+	defer f.Close()
+	scanner:=bufio.NewScanner(f)
+
+	var red_walls [][]int
+	for scanner.Scan(){
+		line:= scanner.Text()
+		line_sp := strings.Split(line, ",")
+		x,_:= strconv.Atoi(line_sp[0])
+		y,_:= strconv.Atoi(line_sp[1])
+		red_walls = append(red_walls, []int{x,y})
+	}
+
+	res := 0
+	for i:= range red_walls {
+		w1:= red_walls[i]
+		for j:= i+1; j < len(red_walls); j++{
+			w2:= red_walls[j]
+			area := calculate_area(w1,w2)
+			if area > res {
+				res = area
+			}
+			}
+	}
+	fmt.Println(res)
+}
+
+func calculate_area(w1,w2 []int) int{
+	dx, dy := int(math.Abs(float64(w1[0]-w2[0]))), int(math.Abs(float64(w1[1]-w2[1])))
+	return (dx+1) * (dy+1)
+}

+ 1 - 1
README.md

@@ -28,7 +28,7 @@ Each day's folder is named after the day number (`1` to `12`). Inside each folde
 | 6   | ✅     | ✅     |
 | 7   | ✅     | ✅     |
 | 8   | ✅     | ✅     |
-| 9   |      | ⬜     |
+| 9   |      | ⬜     |
 | 10  | ⬜     | ⬜     |
 | 11  | ⬜     | ⬜     |
 | 12  | ⬜     | ⬜     |