solve_1.go 806 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package main
  2. import (
  3. "bufio"
  4. "fmt"
  5. "math"
  6. "os"
  7. "strconv"
  8. "strings"
  9. )
  10. func main() {
  11. fmt.Println("Advent of Code 2025 - Day 9 - Part 1")
  12. f,_:= os.Open("9/input")
  13. defer f.Close()
  14. scanner:=bufio.NewScanner(f)
  15. var red_walls [][]int
  16. for scanner.Scan(){
  17. line:= scanner.Text()
  18. line_sp := strings.Split(line, ",")
  19. x,_:= strconv.Atoi(line_sp[0])
  20. y,_:= strconv.Atoi(line_sp[1])
  21. red_walls = append(red_walls, []int{x,y})
  22. }
  23. res := 0
  24. for i:= range red_walls {
  25. w1:= red_walls[i]
  26. for j:= i+1; j < len(red_walls); j++{
  27. w2:= red_walls[j]
  28. area := calculate_area(w1,w2)
  29. if area > res {
  30. res = area
  31. }
  32. }
  33. }
  34. fmt.Println(res)
  35. }
  36. func calculate_area(w1,w2 []int) int{
  37. dx, dy := int(math.Abs(float64(w1[0]-w2[0]))), int(math.Abs(float64(w1[1]-w2[1])))
  38. return (dx+1) * (dy+1)
  39. }