-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / Build and Run
|
||
var inputs embed.FS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / Build and Run
|
||
var inputs embed.FS |