2024 day 8 Complete!
This commit is contained in:
parent
6af73b70f2
commit
30a2f6df7b
50
2024/day08/input
Normal file
50
2024/day08/input
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
............s...............1.....................
|
||||||
|
......................E......3.....S..............
|
||||||
|
.......................3.....S....................
|
||||||
|
...e........T.t.......S.1...........I.............
|
||||||
|
..................B..................I.....O......
|
||||||
|
g.......z........i39......B..I....................
|
||||||
|
.......s....S.......3......................i..I...
|
||||||
|
....e.............2..........B....................
|
||||||
|
.......tC...z.......g......1......................
|
||||||
|
.E......s....R....................................
|
||||||
|
..G...t..........2................................
|
||||||
|
.........K...C.......2............................
|
||||||
|
....T..e...........5...C..........................
|
||||||
|
...T................................O...o.........
|
||||||
|
...............................g..............o...
|
||||||
|
.........z...................g......i............o
|
||||||
|
...9.E............H...........Y.......O...........
|
||||||
|
..........R..H...............7.O..................
|
||||||
|
...........H.............v......7........B........
|
||||||
|
..9.Q.......................W......1........Y.....
|
||||||
|
.........................z.7.................Y....
|
||||||
|
.....Q................................v...........
|
||||||
|
....K.......E.....R...............2..........o....
|
||||||
|
.n............H......v...........................Y
|
||||||
|
.G.y..........................Q...................
|
||||||
|
......G....A5.....................h...............
|
||||||
|
..........D...5.w...9.............................
|
||||||
|
......n....5...L..................................
|
||||||
|
............................v.....................
|
||||||
|
............L...0t..........7.....................
|
||||||
|
..n....k............y....................W........
|
||||||
|
..k..........0.........................W..........
|
||||||
|
...n.......R..L..a........................W.......
|
||||||
|
.........................................h........
|
||||||
|
..0..L........c...b...............................
|
||||||
|
.....................8.y..........................
|
||||||
|
.......w.................6.............h.......N..
|
||||||
|
..........y..4....................................
|
||||||
|
...0....8...k.....Z........r......................
|
||||||
|
..............a...8Z.........G......4.............
|
||||||
|
........4..b.q.....................K..............
|
||||||
|
.q...........kZ.K......b..D.........d.............
|
||||||
|
.8.....................D................r.........
|
||||||
|
.....w.........a...............d........A.........
|
||||||
|
................................d.A.hV............
|
||||||
|
................c..........D.....V....r...........
|
||||||
|
.......Z......6.....l........................A.d..
|
||||||
|
...................l..6..c....b......r...........N
|
||||||
|
......a....4........q..l..V..c................N...
|
||||||
|
l.....w...........q..6............V...............
|
59
2024/day08/main.go
Normal file
59
2024/day08/main.go
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
h "git.bullercodeworks.com/brian/adventofcode/helpers"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
inp := h.StdinToStringSlice()
|
||||||
|
part1(inp)
|
||||||
|
fmt.Println()
|
||||||
|
part2(inp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func part1(inp []string) {
|
||||||
|
c := h.StringSliceToCoordByteMap(inp)
|
||||||
|
anC := h.StringSliceToCoordByteMap(inp)
|
||||||
|
nodes := c.FindAllNot('.')
|
||||||
|
for k, bt := range nodes {
|
||||||
|
fNodes := c.FindAll(bt)
|
||||||
|
for _, nd := range fNodes {
|
||||||
|
if k.Equals(nd) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
diff := k.Sub(nd)
|
||||||
|
an := k.Add(diff)
|
||||||
|
if anC.ContainsCoord(an) {
|
||||||
|
anC.Put(k.Add(diff), '#')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println("# Part 1")
|
||||||
|
fmt.Println("Antinodes:", anC.Count('#'))
|
||||||
|
}
|
||||||
|
|
||||||
|
func part2(inp []string) {
|
||||||
|
c := h.StringSliceToCoordByteMap(inp)
|
||||||
|
anC := h.StringSliceToCoordByteMap(inp)
|
||||||
|
nodes := c.FindAllNot('.')
|
||||||
|
for k, bt := range nodes {
|
||||||
|
fNodes := c.FindAll(bt)
|
||||||
|
for _, nd := range fNodes {
|
||||||
|
anC.Put(nd, '#')
|
||||||
|
anC.Put(k, '#')
|
||||||
|
if k.Equals(nd) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
diff := k.Sub(nd)
|
||||||
|
an := k.Add(diff)
|
||||||
|
for anC.ContainsCoord(an) {
|
||||||
|
anC.Put(an, '#')
|
||||||
|
an = an.Add(diff)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println("# Part 2")
|
||||||
|
fmt.Println("Antinodes:", anC.Count('#'))
|
||||||
|
}
|
12
2024/day08/testinput
Normal file
12
2024/day08/testinput
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
............
|
||||||
|
........0...
|
||||||
|
.....0......
|
||||||
|
.......0....
|
||||||
|
....0.......
|
||||||
|
......A.....
|
||||||
|
............
|
||||||
|
............
|
||||||
|
........A...
|
||||||
|
.........A..
|
||||||
|
............
|
||||||
|
............
|
10
2024/day08/testinput2
Normal file
10
2024/day08/testinput2
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
T.........
|
||||||
|
...T......
|
||||||
|
.T........
|
||||||
|
..........
|
||||||
|
..........
|
||||||
|
..........
|
||||||
|
..........
|
||||||
|
..........
|
||||||
|
..........
|
||||||
|
..........
|
@ -42,6 +42,13 @@ func (c *Coordinate) MoveNW() {
|
|||||||
c.Y--
|
c.Y--
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c Coordinate) Sub(o Coordinate) Coordinate {
|
||||||
|
return Coordinate{
|
||||||
|
X: c.X - o.X,
|
||||||
|
Y: c.Y - o.Y,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c Coordinate) Add(o Coordinate) Coordinate {
|
func (c Coordinate) Add(o Coordinate) Coordinate {
|
||||||
return Coordinate{
|
return Coordinate{
|
||||||
X: c.X + o.X,
|
X: c.X + o.X,
|
||||||
|
Loading…
Reference in New Issue
Block a user