-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday08_2.go
61 lines (53 loc) · 1.56 KB
/
day08_2.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
49
50
51
52
53
54
55
56
57
58
59
60
61
package day08
import (
"strings"
"github.com/blfuentes/AdventOfCode_2024_Go/utilities"
)
func FindAntinodes2(antennas []Antenna, maxRows, maxCols int, antinodes *map[Coord]bool) {
pairOfAntennas := utilities.Combinations(antennas, 2)
for _, pair := range pairOfAntennas {
radius := 1
oneOutOfRange := false
twoOutOfRange := false
initialA, initialB := pair[0].Position, pair[1].Position
(*antinodes)[initialA] = true
(*antinodes)[initialB] = true
for !oneOutOfRange || !twoOutOfRange {
mirrorA, mirrorB := Mirror(initialA, initialB, radius)
if utilities.IsInBoundaries(mirrorA.Row, mirrorA.Col, maxRows, maxCols) {
(*antinodes)[mirrorA] = true
} else {
oneOutOfRange = true
}
if utilities.IsInBoundaries(mirrorB.Row, mirrorB.Col, maxRows, maxCols) {
(*antinodes)[mirrorB] = true
} else {
twoOutOfRange = true
}
radius++
}
}
}
func Executepart2() int {
var result int = 0
var fileName string = "./day08/day08.txt"
if fileContent, err := utilities.ReadFileAsLines(fileName); err == nil {
antennas := make(map[string][]Antenna)
maxRows := len(fileContent)
maxCols := len(fileContent[0])
for row := 0; row < maxRows; row++ {
for col := 0; col < maxCols; col++ {
value := strings.Split(fileContent[row], "")[col]
if value != "." {
antennas[value] = append(antennas[value], Antenna{value, Coord{row, col}})
}
}
}
antinodes := make(map[Coord]bool)
for _, subantennas := range antennas {
FindAntinodes2(subantennas, maxRows, maxCols, &antinodes)
}
result += len(antinodes)
}
return result
}