adventofcode/2024/day08/main.go

60 lines
1.1 KiB
Go

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('#'))
}