diff --git a/.github/workflows/quality.yaml b/.github/workflows/quality.yaml index 3484bfb..62394d8 100644 --- a/.github/workflows/quality.yaml +++ b/.github/workflows/quality.yaml @@ -4,7 +4,6 @@ on: push: branches: - main - pull_request: jobs: build-current: diff --git a/.github/workflows/readme-stars.yaml b/.github/workflows/readme-stars.yaml index c6571d5..f9ad662 100644 --- a/.github/workflows/readme-stars.yaml +++ b/.github/workflows/readme-stars.yaml @@ -1,5 +1,8 @@ name: README Stars on: + push: + branches: + - main schedule: - cron: 0 */4 * 12 * workflow_dispatch: diff --git a/2024/06/01.go b/2024/06/01.go index f8bdf13..31bc8f3 100644 --- a/2024/06/01.go +++ b/2024/06/01.go @@ -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) diff --git a/2024/06/02.go b/2024/06/02.go index 83f0529..52be5dd 100644 --- a/2024/06/02.go +++ b/2024/06/02.go @@ -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 @@ -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) { diff --git a/pkg/harness/harness.go b/pkg/harness/harness.go index af22862..a3e827d 100644 --- a/pkg/harness/harness.go +++ b/pkg/harness/harness.go @@ -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. @@ -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] { @@ -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 { diff --git a/template/01.go b/template/01.go index 02f8005..7819629 100644 --- a/template/01.go +++ b/template/01.go @@ -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() {