diff --git a/.gitignore b/.gitignore index a967731..e6b40cd 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ *.dll *.so *.dylib +bin/ # Test binary, built with `go test -c` *.test diff --git a/day-01/internal/one/benchmark b/day-01/internal/one/benchmark new file mode 100644 index 0000000..8c90b82 --- /dev/null +++ b/day-01/internal/one/benchmark @@ -0,0 +1,6 @@ +goos: linux +goarch: amd64 +pkg: github.com/onyx-and-iris/aoc2024/day-01/internal/one +cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz +BenchmarkMain-12 1000000000 0.0006628 ns/op +ok github.com/onyx-and-iris/aoc2024/day-01/internal/one 0.009s diff --git a/day-01/main_internal_test.go b/day-01/internal/one/solve_internal_test.go similarity index 55% rename from day-01/main_internal_test.go rename to day-01/internal/one/solve_internal_test.go index ae4aa6b..f9cc9af 100644 --- a/day-01/main_internal_test.go +++ b/day-01/internal/one/solve_internal_test.go @@ -1,11 +1,15 @@ -package main +package one import ( + _ "embed" "os" "testing" ) +//go:embed testdata/input.txt +var data []byte + func BenchmarkMain(b *testing.B) { os.Stdout, _ = os.Open(os.DevNull) - main() + Solve(data) } diff --git a/day-01/internal/two/benchmark b/day-01/internal/two/benchmark new file mode 100644 index 0000000..0eb0983 --- /dev/null +++ b/day-01/internal/two/benchmark @@ -0,0 +1,6 @@ +goos: linux +goarch: amd64 +pkg: github.com/onyx-and-iris/aoc2024/day-01/internal/two +cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz +BenchmarkMain-12 1000000000 0.001179 ns/op +ok github.com/onyx-and-iris/aoc2024/day-01/internal/two 0.011s diff --git a/day-01/internal/two/solve_internal_test.go b/day-01/internal/two/solve_internal_test.go new file mode 100644 index 0000000..e3efa34 --- /dev/null +++ b/day-01/internal/two/solve_internal_test.go @@ -0,0 +1,15 @@ +package two + +import ( + _ "embed" + "os" + "testing" +) + +//go:embed testdata/input.txt +var data []byte + +func BenchmarkMain(b *testing.B) { + os.Stdout, _ = os.Open(os.DevNull) + Solve(data) +} diff --git a/day-01/main.go b/day-01/main.go deleted file mode 100644 index 3b5ba78..0000000 --- a/day-01/main.go +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************** - Advent of Code 2024 - day-01 -********************************************************************************/ - -package main - -import ( - "embed" - "flag" - "fmt" - "log" - - "github.com/onyx-and-iris/aoc2024/day-01/internal/one" - "github.com/onyx-and-iris/aoc2024/day-01/internal/two" -) - -//go:embed testdata -var files embed.FS - -func main() { - filename := flag.String("f", "input.txt", "input file") - flag.Parse() - - data, err := files.ReadFile(fmt.Sprintf("testdata/%s", *filename)) - if err != nil { - log.Fatal(err) - } - - val, err := one.Solve(data) - if err != nil { - log.Fatal(err) - } - fmt.Printf("solution one: %d\n", val) - - val, err = two.Solve(data) - if err != nil { - log.Fatal(err) - } - fmt.Printf("solution two: %d\n", val) -} diff --git a/day-01/solve.go b/day-01/solve.go new file mode 100644 index 0000000..39d0613 --- /dev/null +++ b/day-01/solve.go @@ -0,0 +1,23 @@ +package day01 + +import ( + "fmt" + "log" + + "github.com/onyx-and-iris/aoc2024/day-01/internal/one" + "github.com/onyx-and-iris/aoc2024/day-01/internal/two" +) + +func Solve(data []byte) { + val, err := one.Solve(data) + if err != nil { + log.Fatal(err) + } + fmt.Printf("solution one: %d\n", val) + + val, err = two.Solve(data) + if err != nil { + log.Fatal(err) + } + fmt.Printf("solution two: %d\n", val) +} diff --git a/day-01/solve_internal_test.go b/day-01/solve_internal_test.go new file mode 100644 index 0000000..151cb6f --- /dev/null +++ b/day-01/solve_internal_test.go @@ -0,0 +1,15 @@ +package day01 + +import ( + _ "embed" + "os" + "testing" +) + +//go:embed testdata/input.txt +var data []byte + +func BenchmarkMain(b *testing.B) { + os.Stdout, _ = os.Open(os.DevNull) + Solve(data) +}