-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart2.go
48 lines (43 loc) · 993 Bytes
/
part2.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package day08
import "github.com/patrick22414/Advent-of-Code-2024/readinput"
func Part2() int {
// map of frequency to locations
antennas := make(map[byte][]Vec)
i, n := 0, -1
for line := range readinput.ReadInput("./input.txt") {
if n == -1 {
n = len(line) // max y of input
}
for j := 0; j < len(line); j++ {
f := line[j]
if f != '.' {
antennas[f] = append(antennas[f], Vec{i, j})
}
}
i++
}
m := i // max x of input
isWithinBounds := func(v Vec) bool {
return v.x >= 0 && v.x < m &&
v.y >= 0 && v.y < n
}
// total := 0
uniques := make(map[Vec]struct{})
for _, v := range antennas {
for i, a1 := range v {
for _, a2 := range v[i+1:] {
// fmt.Println(a1, a2)
d := a2.sub(a1)
for a := a1; isWithinBounds(a); a = a.sub(d) {
uniques[a] = struct{}{}
}
for a := a2; isWithinBounds(a); a = a.add(d) {
uniques[a] = struct{}{}
}
}
}
}
// fmt.Println(antennas)
// fmt.Println(uniques)
return len(uniques)
}