mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-04-11 07:23:46 +01:00
Compare commits
3 Commits
588561be7c
...
c3fa7d0ff8
Author | SHA1 | Date | |
---|---|---|---|
c3fa7d0ff8 | |||
84312b157c | |||
d05828154e |
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,6 +7,7 @@
|
|||||||
*.dll
|
*.dll
|
||||||
*.so
|
*.so
|
||||||
*.dylib
|
*.dylib
|
||||||
|
bin/
|
||||||
|
|
||||||
# Test binary, built with `go test -c`
|
# Test binary, built with `go test -c`
|
||||||
*.test
|
*.test
|
||||||
|
@ -10,8 +10,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/onyx-and-iris/aoc2024/day-01/internal/one"
|
problems "github.com/onyx-and-iris/aoc2024/day-01"
|
||||||
"github.com/onyx-and-iris/aoc2024/day-01/internal/two"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed testdata
|
//go:embed testdata
|
||||||
@ -26,15 +25,5 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
val, err := one.Solve(data)
|
problems.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)
|
|
||||||
}
|
}
|
6
day-01/internal/one/benchmark
Normal file
6
day-01/internal/one/benchmark
Normal file
@ -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
|
@ -1,11 +1,15 @@
|
|||||||
package main
|
package one
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
_ "embed"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed testdata/input.txt
|
||||||
|
var data []byte
|
||||||
|
|
||||||
func BenchmarkMain(b *testing.B) {
|
func BenchmarkMain(b *testing.B) {
|
||||||
os.Stdout, _ = os.Open(os.DevNull)
|
os.Stdout, _ = os.Open(os.DevNull)
|
||||||
main()
|
Solve(data)
|
||||||
}
|
}
|
6
day-01/internal/two/benchmark
Normal file
6
day-01/internal/two/benchmark
Normal file
@ -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
|
15
day-01/internal/two/solve_internal_test.go
Normal file
15
day-01/internal/two/solve_internal_test.go
Normal file
@ -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)
|
||||||
|
}
|
@ -16,10 +16,12 @@ vet: fmt
|
|||||||
$(GO) vet ./...
|
$(GO) vet ./...
|
||||||
|
|
||||||
build: vet | $(BIN_DIR)
|
build: vet | $(BIN_DIR)
|
||||||
$(GO) build -o $(EXE) .
|
$(GO) build -o $(EXE) ./cmd/cli/
|
||||||
|
|
||||||
bench:
|
bench:
|
||||||
$(GO) test . -test.count=10 -bench=. > benchmark
|
$(GO) test ./internal/one/ -bench=. > internal/one/benchmark
|
||||||
|
$(GO) test ./internal/two/ -bench=. > internal/two/benchmark
|
||||||
|
$(GO) test . -count=10 -bench=. > benchmark
|
||||||
|
|
||||||
$(BIN_DIR):
|
$(BIN_DIR):
|
||||||
@mkdir -p $@
|
@mkdir -p $@
|
||||||
|
23
day-01/solve.go
Normal file
23
day-01/solve.go
Normal file
@ -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)
|
||||||
|
}
|
15
day-01/solve_internal_test.go
Normal file
15
day-01/solve_internal_test.go
Normal file
@ -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)
|
||||||
|
}
|
@ -7,7 +7,8 @@ if [ -d day-"$name" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p "$name"/testdata
|
mkdir -p "$name"/cmd/cli/testdata \
|
||||||
|
"$name"/testdata "$name"/internal/one/testdata "$name"/internal/two/testdata
|
||||||
touch "$name"/makefile
|
touch "$name"/makefile
|
||||||
|
|
||||||
cat <<EOT >> "$name"/makefile
|
cat <<EOT >> "$name"/makefile
|
||||||
@ -32,7 +33,9 @@ build: vet | \$(BIN_DIR)
|
|||||||
\$(GO) build -o \$(EXE) ./\$(SRC_DIR)
|
\$(GO) build -o \$(EXE) ./\$(SRC_DIR)
|
||||||
|
|
||||||
bench:
|
bench:
|
||||||
\$(GO) test . -test.count=10 -bench=. > benchmark
|
\$(GO) test ./internal/one/ -bench=. > internal/one/benchmark
|
||||||
|
\$(GO) test ./internal/two/ -bench=. > internal/two/benchmark
|
||||||
|
\$(GO) test . -count=10 -bench=. > benchmark
|
||||||
|
|
||||||
\$(BIN_DIR):
|
\$(BIN_DIR):
|
||||||
@mkdir -p \$@
|
@mkdir -p \$@
|
||||||
@ -41,7 +44,7 @@ clean:
|
|||||||
@rm -rv \$(BIN_DIR)
|
@rm -rv \$(BIN_DIR)
|
||||||
EOT
|
EOT
|
||||||
|
|
||||||
cat <<EOT >> "$name"/solution.go
|
cat <<EOT >> "$name"/cmd/cli/main.go
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
Advent of Code 2024 - $name
|
Advent of Code 2024 - $name
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user