Skip to content

Commit 7b924c6

Browse files
committed
2024.08 WIP
1 parent ac1cab5 commit 7b924c6

File tree

3 files changed

+144
-0
lines changed

3 files changed

+144
-0
lines changed

2024/8-antenna/example.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
............
2+
........0...
3+
.....0......
4+
.......0....
5+
....0.......
6+
......A.....
7+
............
8+
............
9+
........A...
10+
.........A..
11+
............
12+
............

2024/8-antenna/input.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
.............C.7..................G..0...y........
2+
..................7................C..............
3+
....................................0......W....y.
4+
.......................................D..W.......
5+
..........u.......................................
6+
..................................4.......D0...j..
7+
.....................................D............
8+
................O.....C................G..........
9+
............F.....................C...............
10+
......u..........F.................4.......y......
11+
..........X..........5....4...........1...........
12+
..........F...........5X...................3......
13+
.............F.............................j.3....
14+
.................u..............X.................
15+
............................7.....................
16+
..................................................
17+
..........................5.....j2.........4......
18+
....d.....................y...................j1..
19+
..................................................
20+
............................Y.e...................
21+
.................d...X...............J...........e
22+
.............d....................................
23+
..............................Y..............1....
24+
.........................................Y........
25+
......................W......8..f...J.........3...
26+
.......w.............J............................
27+
...................................U.....f......e.
28+
.................................Of....e....t...1.
29+
.......g..........d......s........................
30+
................G................f................
31+
.....................................O............
32+
...g........................T.....U...............
33+
......................s..........T.............G..
34+
................................s.......8.........
35+
.....9........g...........o...U............E......
36+
............g............................t....o...
37+
...........................................6....E.
38+
.....................s......x........6....E.......
39+
..........w.9................x............t.......
40+
...........9........w...........J.....6o..........
41+
.............................................o....
42+
..........S................U......................
43+
.......S..2..........c........T.O....t............
44+
.....2...S.....c...................T..............
45+
..................x.......................8.......
46+
....9.............................................
47+
...wS.....................................6.......
48+
................2........................8........
49+
..................................................
50+
.................x....c........................E..

2024/8-antenna/main.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package main
2+
3+
import (
4+
"advent-of-code/util"
5+
"bufio"
6+
"fmt"
7+
"math"
8+
"slices"
9+
)
10+
11+
const nothing = '.'
12+
13+
func main() {
14+
file := util.FileFromArgs()
15+
scan := bufio.NewScanner(file)
16+
17+
antennas := map[byte][]position{}
18+
19+
var grid [][]byte
20+
var row []byte
21+
for scan.Scan() {
22+
row = scan.Bytes()
23+
for i := range row {
24+
if row[i] != nothing {
25+
if _, ok := antennas[row[i]]; !ok {
26+
antennas[row[i]] = []position{}
27+
}
28+
29+
antennas[row[i]] = append(antennas[row[i]], position{i, len(grid)})
30+
}
31+
}
32+
33+
grid = append(grid, row)
34+
}
35+
36+
var antinodes, points []position
37+
for k := range antennas {
38+
for i := range antennas[k] {
39+
for j := range antennas[k] {
40+
if i == j {
41+
continue
42+
}
43+
44+
points = calculateAntinodes(antennas[k][i], antennas[k][j])
45+
for p := range points {
46+
if slices.IndexFunc(antinodes, func(pp position) bool { return points[p].eq(pp) }) == -1 {
47+
antinodes = append(antinodes, points[p])
48+
}
49+
}
50+
51+
}
52+
}
53+
}
54+
55+
fmt.Println(len(antinodes))
56+
}
57+
58+
type position struct {
59+
X, Y int
60+
}
61+
62+
func (p position) eq(q position) bool {
63+
return p.X == q.X && p.Y == q.Y
64+
}
65+
66+
// calculateAntinodes will calculate all antinodes between two antennas
67+
func calculateAntinodes(c1, c2 position) []position {
68+
var positions []position
69+
70+
// sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
71+
d := math.Sqrt(float64((c1.X-c2.X)*(c1.X-c2.X) + (c1.Y-c2.Y)*(c1.Y-c2.Y)))
72+
73+
for r := range 20 {
74+
if d > float64(r+2*r) {
75+
continue // Circles don't touch
76+
}
77+
78+
// TODO: calculate touch points
79+
}
80+
81+
return positions
82+
}

0 commit comments

Comments
 (0)