2024 day 8 Complete!
This commit is contained in:
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('#'))
|
||||
}
|
||||
Reference in New Issue
Block a user