Skip to content

Commit

Permalink
2024 day 6 update
Browse files Browse the repository at this point in the history
  • Loading branch information
dbut2 committed Dec 6, 2024
1 parent 6b79740 commit ddaa8d0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
1 change: 0 additions & 1 deletion .github/workflows/quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- main
pull_request:

jobs:
build-current:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/readme-stars.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: README Stars
on:
push:
branches:
- main
schedule:
- cron: 0 */4 * 12 *
workflow_dispatch:
Expand Down
4 changes: 2 additions & 2 deletions 2024/06/01.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
)

func solve(input space.Grid[byte]) int {
cell, _ := input.Find(func(cell space.Cell, b byte) bool { return b == '^' })
cell, _ := input.Find(func(_ space.Cell, b byte) bool { return b == '^' })
dir := space.Up

seen := sets.Set[space.Cell]{}
seen := make(sets.Set[space.Cell], len(input)*len(input[0]))
for {
seen.Add(cell)

Expand Down
13 changes: 6 additions & 7 deletions 2024/06/02.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import (
"github.com/dbut2/advent-of-code/pkg/space"
)

type pos struct {
cell space.Cell
dir space.Direction
}

func solve(input space.Grid[byte]) int {
count := 0

Expand All @@ -23,10 +18,14 @@ func solve(input space.Grid[byte]) int {
}
input.Set(c, '#')

cell, _ := input.Find(func(cell space.Cell, b byte) bool { return b == '^' })
cell, _ := input.Find(func(_ space.Cell, b byte) bool { return b == '^' })
dir := space.Up

seen := sets.Set[pos]{}
type pos struct {
cell space.Cell
dir space.Direction
}
seen := make(sets.Set[pos], len(input)*len(input[0]))
for {
p := pos{cell: cell, dir: dir}
if seen.Contains(p) {
Expand Down
12 changes: 11 additions & 1 deletion pkg/harness/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Harness[T any, U comparable] struct {
preProcessor PreProcessor[T]
solve func(T) U
inputs embed.FS
silent bool
}

// HarnessOpt modifies the Harness when initialising.
Expand All @@ -29,6 +30,12 @@ func WithPreProcessor[T any, U comparable](preProcessor PreProcessor[T]) Harness
}
}

func WithSilence[T any, U comparable]() HarnessOpt[T, U] {
return func(h *Harness[T, U]) {
h.silent = true
}
}

// New returns a new Harness. At minimum a solve function and some inputs are
// required.
func New[T any, U comparable](solve func(T) U, inputs embed.FS, opts ...HarnessOpt[T, U]) *Harness[T, U] {
Expand Down Expand Up @@ -122,7 +129,10 @@ func (h *Harness[T, U]) run(s string) U {

// Run will execute the harness with the main input.
func (h *Harness[T, U]) Run() {
fmt.Println(h.run(h.getInput()))
out := h.run(h.getInput())
if !h.silent {
fmt.Println(out)
}
}

func (h *Harness[T, U]) readInput(s string) string {
Expand Down
7 changes: 3 additions & 4 deletions template/01.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"embed"

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

func solve(input []string) int {
for i, line := range input {
_, _ = i, line

}

}

func main() {
Expand Down

0 comments on commit ddaa8d0

Please sign in to comment.