Skip to content

Commit

Permalink
2024 day 8
Browse files Browse the repository at this point in the history
  • Loading branch information
dbut2 committed Dec 8, 2024
1 parent 46fd876 commit 3c0a0f5
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
50 changes: 50 additions & 0 deletions 2024/08/01.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"embed"

"github.com/dbut2/advent-of-code/pkg/harness"
"github.com/dbut2/advent-of-code/pkg/sets"
"github.com/dbut2/advent-of-code/pkg/space"
)

func solve(input space.Grid[byte]) int {
locations := map[byte][]space.Cell{}
for cell, val := range input.Cells() {
if *val == '.' {
continue
}
locations[*val] = append(locations[*val], cell)
}

antinodes := sets.Set[space.Cell]{}
for _, list := range locations {
for i := range list {
for j := range list {
if i == j {
continue
}

next := list[i].Move(diff(list[i], list[j]))
if input.Inside(next) {
antinodes.Add(next)
}
}
}
}

return len(antinodes)
}

func diff(a, b space.Cell) space.Direction {
return space.Direction{a[0] - b[0], a[1] - b[1]}
}

func main() {
h := harness.New(solve, inputs)
h.Expect(1, 14)
h.Run()
}

//go:embed *.txt

Check failure on line 49 in 2024/08/01.go

View workflow job for this annotation

GitHub Actions / Build and Run

pattern *.txt: no matching files found

Check failure on line 49 in 2024/08/01.go

View workflow job for this annotation

GitHub Actions / Build and Run

pattern *.txt: no matching files found
var inputs embed.FS
53 changes: 53 additions & 0 deletions 2024/08/02.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package main

import (
"embed"

"github.com/dbut2/advent-of-code/pkg/harness"
"github.com/dbut2/advent-of-code/pkg/sets"
"github.com/dbut2/advent-of-code/pkg/space"
)

func solve(input space.Grid[byte]) int {
antinodes := sets.Set[space.Cell]{}
locations := map[byte][]space.Cell{}
for cell, val := range input.Cells() {
if *val == '.' {
continue
}
antinodes.Add(cell)
locations[*val] = append(locations[*val], cell)
}

for _, list := range locations {
for i := range list {
for j := range list {
if i == j {
continue
}

next := list[i].Move(diff(list[i], list[j]))
for input.Inside(next) {
antinodes.Add(next)
next = next.Move(diff(list[i], list[j]))
}
}
}
}

return len(antinodes)
}

func diff(a, b space.Cell) space.Direction {
return space.Direction{a[0] - b[0], a[1] - b[1]}
}

func main() {
h := harness.New(solve, inputs)
h.Expect(2, 9)
h.Expect(1, 34)
h.Run()
}

//go:embed *.txt

Check failure on line 52 in 2024/08/02.go

View workflow job for this annotation

GitHub Actions / Build and Run

pattern *.txt: no matching files found

Check failure on line 52 in 2024/08/02.go

View workflow job for this annotation

GitHub Actions / Build and Run

pattern *.txt: no matching files found
var inputs embed.FS

0 comments on commit 3c0a0f5

Please sign in to comment.