mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-04-19 11:13:48 +01:00
Compare commits
No commits in common. "6e06bd5b16581f9794315d889c54c3ad9c5c8d19" and "c3fa7d0ff8cbcfea07f7b797f6ecb75064594f28" have entirely different histories.
6e06bd5b16
...
c3fa7d0ff8
@ -25,10 +25,5 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
one, two, err := problems.Solve(data)
|
problems.Solve(data)
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("solution one: %d\nsolution two: %d\n", one, two)
|
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,13 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
"regexp"
|
||||||
|
|
||||||
"github.com/onyx-and-iris/aoc2024/day-01/internal/util"
|
"github.com/onyx-and-iris/aoc2024/day-01/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var reNums = regexp.MustCompile(`[0-9]+`)
|
||||||
|
|
||||||
func Solve(data []byte) (int, error) {
|
func Solve(data []byte) (int, error) {
|
||||||
r := bytes.NewReader(data)
|
r := bytes.NewReader(data)
|
||||||
left, right, err := parseLines(r)
|
left, right, err := parseLines(r)
|
||||||
@ -29,7 +31,7 @@ func parseLines(r io.Reader) ([]int, []int, error) {
|
|||||||
|
|
||||||
scanner := bufio.NewScanner(r)
|
scanner := bufio.NewScanner(r)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
nums := strings.Fields(scanner.Text())
|
nums := reNums.FindAllString(scanner.Text(), -1)
|
||||||
|
|
||||||
left = util.InsertSorted(left, util.MustConv(nums[0]))
|
left = util.InsertSorted(left, util.MustConv(nums[0]))
|
||||||
right = util.InsertSorted(right, util.MustConv(nums[1]))
|
right = util.InsertSorted(right, util.MustConv(nums[1]))
|
||||||
|
@ -4,12 +4,14 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/onyx-and-iris/aoc2024/day-01/internal/util"
|
"github.com/onyx-and-iris/aoc2024/day-01/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var reNums = regexp.MustCompile(`[0-9]+`)
|
||||||
|
|
||||||
func Solve(data []byte) (int, error) {
|
func Solve(data []byte) (int, error) {
|
||||||
r := bytes.NewReader(data)
|
r := bytes.NewReader(data)
|
||||||
left, right, err := parseLines(r)
|
left, right, err := parseLines(r)
|
||||||
@ -41,7 +43,7 @@ func parseLines(r io.Reader) (map[int]int, []int, error) {
|
|||||||
|
|
||||||
scanner := bufio.NewScanner(r)
|
scanner := bufio.NewScanner(r)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
nums := strings.Fields(scanner.Text())
|
nums := reNums.FindAllString(scanner.Text(), -1)
|
||||||
|
|
||||||
left[util.MustConv(nums[0])]++
|
left[util.MustConv(nums[0])]++
|
||||||
right = util.InsertSorted(right, util.MustConv(nums[1]))
|
right = util.InsertSorted(right, util.MustConv(nums[1]))
|
||||||
|
@ -1,20 +1,23 @@
|
|||||||
package dayone
|
package day01
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/onyx-and-iris/aoc2024/day-01/internal/one"
|
"github.com/onyx-and-iris/aoc2024/day-01/internal/one"
|
||||||
"github.com/onyx-and-iris/aoc2024/day-01/internal/two"
|
"github.com/onyx-and-iris/aoc2024/day-01/internal/two"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Solve(data []byte) (int, int, error) {
|
func Solve(data []byte) {
|
||||||
answerOne, err := one.Solve(data)
|
val, err := one.Solve(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, err
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
fmt.Printf("solution one: %d\n", val)
|
||||||
|
|
||||||
answerTwo, err := two.Solve(data)
|
val, err = two.Solve(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, err
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
fmt.Printf("solution two: %d\n", val)
|
||||||
return answerOne, answerTwo, nil
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package dayone
|
package day01
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
goos: linux
|
|
||||||
goarch: amd64
|
|
||||||
pkg: github.com/onyx-and-iris/aoc2024/day-02
|
|
||||||
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
|
|
||||||
BenchmarkMain-12 1000000000 0.001121 ns/op
|
|
||||||
BenchmarkMain-12 1000000000 0.0009054 ns/op
|
|
||||||
BenchmarkMain-12 1000000000 0.0009948 ns/op
|
|
||||||
BenchmarkMain-12 1000000000 0.0008774 ns/op
|
|
||||||
BenchmarkMain-12 1000000000 0.0009065 ns/op
|
|
||||||
BenchmarkMain-12 1000000000 0.0008702 ns/op
|
|
||||||
BenchmarkMain-12 1000000000 0.0008654 ns/op
|
|
||||||
BenchmarkMain-12 1000000000 0.0008806 ns/op
|
|
||||||
BenchmarkMain-12 1000000000 0.0009256 ns/op
|
|
||||||
BenchmarkMain-12 1000000000 0.0009088 ns/op
|
|
||||||
ok github.com/onyx-and-iris/aoc2024/day-02 0.085s
|
|
@ -1,34 +0,0 @@
|
|||||||
/********************************************************************************
|
|
||||||
Advent of Code 2024 - day-02
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"embed"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
problems "github.com/onyx-and-iris/aoc2024/day-02"
|
|
||||||
)
|
|
||||||
|
|
||||||
//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)
|
|
||||||
}
|
|
||||||
|
|
||||||
one, two, err := problems.Solve(data)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("solution one: %d\nsolution two: %d\n", one, two)
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
module github.com/onyx-and-iris/aoc2024/day-02
|
|
||||||
|
|
||||||
go 1.23.3
|
|
||||||
|
|
||||||
require github.com/stretchr/testify v1.10.0
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
|
||||||
)
|
|
@ -1,10 +0,0 @@
|
|||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
|
||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
@ -1,6 +0,0 @@
|
|||||||
goos: linux
|
|
||||||
goarch: amd64
|
|
||||||
pkg: github.com/onyx-and-iris/aoc2024/day-02/internal/one
|
|
||||||
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
|
|
||||||
BenchmarkMain-12 1000000000 0.0003352 ns/op
|
|
||||||
ok github.com/onyx-and-iris/aoc2024/day-02/internal/one 0.009s
|
|
@ -1,16 +0,0 @@
|
|||||||
package one
|
|
||||||
|
|
||||||
import "math"
|
|
||||||
|
|
||||||
func checkWithComparator(nums []int, comparator comparator) bool {
|
|
||||||
for i := 1; i < len(nums); i++ {
|
|
||||||
if comparator(nums, i) || !isSafe(nums[i-1], nums[i]) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func isSafe(m, n int) bool {
|
|
||||||
return int(math.Abs(float64(m-n))) <= 3
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
package one
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestCheckIncreased(t *testing.T) {
|
|
||||||
tt := map[string]struct {
|
|
||||||
input []int
|
|
||||||
want bool
|
|
||||||
}{
|
|
||||||
"nominal": {
|
|
||||||
input: []int{1, 3, 6, 7, 9},
|
|
||||||
want: true,
|
|
||||||
},
|
|
||||||
"unsafe": {
|
|
||||||
input: []int{1, 3, 2, 4, 8},
|
|
||||||
want: false,
|
|
||||||
},
|
|
||||||
"two numbers the same": {
|
|
||||||
input: []int{1, 3, 3, 4, 8},
|
|
||||||
want: false,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
cmp := func(nums []int, i int) bool {
|
|
||||||
return nums[i-1] >= nums[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
for name, tc := range tt {
|
|
||||||
t.Run(name, func(t *testing.T) {
|
|
||||||
got := checkWithComparator(tc.input, cmp)
|
|
||||||
assert.Equal(t, tc.want, got)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCheckDecreased(t *testing.T) {
|
|
||||||
tt := map[string]struct {
|
|
||||||
input []int
|
|
||||||
want bool
|
|
||||||
}{
|
|
||||||
"nominal": {
|
|
||||||
input: []int{7, 6, 4, 2, 1},
|
|
||||||
want: true,
|
|
||||||
},
|
|
||||||
"unsafe": {
|
|
||||||
input: []int{9, 7, 6, 2, 1},
|
|
||||||
want: false,
|
|
||||||
},
|
|
||||||
"two numbers the same": {
|
|
||||||
input: []int{8, 6, 4, 4, 1},
|
|
||||||
want: false,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
cmp := func(nums []int, i int) bool {
|
|
||||||
return nums[i-1] <= nums[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
for name, tc := range tt {
|
|
||||||
t.Run(name, func(t *testing.T) {
|
|
||||||
got := checkWithComparator(tc.input, cmp)
|
|
||||||
assert.Equal(t, tc.want, got)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
package one
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/onyx-and-iris/aoc2024/day-02/internal/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
type comparator func([]int, int) bool
|
|
||||||
|
|
||||||
func Solve(data []byte) (int, error) {
|
|
||||||
r := bytes.NewReader(data)
|
|
||||||
sum := parseLines(r)
|
|
||||||
|
|
||||||
return sum, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseLines(r io.Reader) int {
|
|
||||||
var sum int
|
|
||||||
|
|
||||||
scanner := bufio.NewScanner(r)
|
|
||||||
for scanner.Scan() {
|
|
||||||
nums := util.IntsFromString(scanner.Text())
|
|
||||||
if check(checkWithComparator, nums, func(nums []int, i int) bool {
|
|
||||||
return nums[i-1] >= nums[i]
|
|
||||||
}) || check(checkWithComparator, nums, func(nums []int, i int) bool {
|
|
||||||
return nums[i-1] <= nums[i]
|
|
||||||
}) {
|
|
||||||
sum++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sum
|
|
||||||
}
|
|
||||||
|
|
||||||
func check(fn func([]int, comparator) bool, nums []int, comparator comparator) bool {
|
|
||||||
return fn(nums, comparator)
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
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)
|
|
||||||
Solve(data)
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
goos: linux
|
|
||||||
goarch: amd64
|
|
||||||
pkg: github.com/onyx-and-iris/aoc2024/day-02/internal/two
|
|
||||||
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
|
|
||||||
BenchmarkMain-12 1000000000 0.0005847 ns/op
|
|
||||||
ok github.com/onyx-and-iris/aoc2024/day-02/internal/two 0.011s
|
|
@ -1,32 +0,0 @@
|
|||||||
package two
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math"
|
|
||||||
"slices"
|
|
||||||
)
|
|
||||||
|
|
||||||
func checkWithComparator(nums []int, comparator comparator, count int) bool {
|
|
||||||
if count > 1 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 1; i < len(nums); i++ {
|
|
||||||
if comparator(nums, i) || !isSafe(nums[i-1], nums[i]) {
|
|
||||||
count++
|
|
||||||
removeFirst, removeSecond := nextLevels(nums, i)
|
|
||||||
return checkWithComparator(removeFirst, comparator, count) ||
|
|
||||||
checkWithComparator(removeSecond, comparator, count)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func isSafe(m, n int) bool {
|
|
||||||
return int(math.Abs(float64(m-n))) <= 3
|
|
||||||
}
|
|
||||||
|
|
||||||
func nextLevels(nums []int, i int) ([]int, []int) {
|
|
||||||
first, second := slices.Clone(nums), slices.Clone(nums)
|
|
||||||
return append(first[:i-1], first[i:]...), append(second[:i], second[i+1:]...)
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
package two
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestIncreasedWithDampener(t *testing.T) {
|
|
||||||
tt := map[string]struct {
|
|
||||||
input []int
|
|
||||||
want bool
|
|
||||||
}{
|
|
||||||
"one violation: two numbers the same": {
|
|
||||||
input: []int{72, 74, 74, 77, 78},
|
|
||||||
want: true,
|
|
||||||
},
|
|
||||||
"one violation: not in order": {
|
|
||||||
input: []int{72, 74, 75, 77, 63},
|
|
||||||
want: true,
|
|
||||||
},
|
|
||||||
|
|
||||||
"two violations: three numbers the same": {
|
|
||||||
input: []int{74, 74, 74, 77, 78},
|
|
||||||
want: false,
|
|
||||||
},
|
|
||||||
"two violations: two numbers the same and not in order": {
|
|
||||||
input: []int{72, 74, 74, 72, 78},
|
|
||||||
want: false,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
cmp := func(nums []int, i int) bool {
|
|
||||||
return nums[i-1] >= nums[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
for name, tc := range tt {
|
|
||||||
t.Run(name, func(t *testing.T) {
|
|
||||||
got := checkWithComparator(tc.input, cmp, 0)
|
|
||||||
assert.Equal(t, tc.want, got)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDecreasedWithDampener(t *testing.T) {
|
|
||||||
tt := map[string]struct {
|
|
||||||
input []int
|
|
||||||
want bool
|
|
||||||
}{}
|
|
||||||
|
|
||||||
cmp := func(nums []int, i int) bool {
|
|
||||||
return nums[i-1] <= nums[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
for name, tc := range tt {
|
|
||||||
t.Run(name, func(t *testing.T) {
|
|
||||||
got := checkWithComparator(tc.input, cmp, 0)
|
|
||||||
assert.Equal(t, tc.want, got)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
package two
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/onyx-and-iris/aoc2024/day-02/internal/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
type comparator func([]int, int) bool
|
|
||||||
|
|
||||||
func Solve(data []byte) (int, error) {
|
|
||||||
r := bytes.NewReader(data)
|
|
||||||
sum := parseLines(r)
|
|
||||||
|
|
||||||
return sum, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseLines(r io.Reader) int {
|
|
||||||
var sum int
|
|
||||||
|
|
||||||
scanner := bufio.NewScanner(r)
|
|
||||||
for scanner.Scan() {
|
|
||||||
nums := util.IntsFromString(scanner.Text())
|
|
||||||
if check(checkWithComparator, nums, func(nums []int, i int) bool {
|
|
||||||
return nums[i-1] >= nums[i]
|
|
||||||
}) || check(checkWithComparator, nums, func(nums []int, i int) bool {
|
|
||||||
return nums[i-1] <= nums[i]
|
|
||||||
}) {
|
|
||||||
sum++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sum
|
|
||||||
}
|
|
||||||
|
|
||||||
func check(fn func([]int, comparator, int) bool, nums []int, comparator comparator) bool {
|
|
||||||
var count int
|
|
||||||
return fn(nums, comparator, count)
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
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)
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package util
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func MustConv(s string) int {
|
|
||||||
n, err := strconv.Atoi(s)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
func IntsFromString(s string) []int {
|
|
||||||
nums := []int{}
|
|
||||||
for _, r := range strings.Fields(s) {
|
|
||||||
nums = append(nums, MustConv(r))
|
|
||||||
}
|
|
||||||
return nums
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
program = day-02
|
|
||||||
|
|
||||||
GO = go
|
|
||||||
SRC_DIR := src
|
|
||||||
BIN_DIR := bin
|
|
||||||
|
|
||||||
EXE := $(BIN_DIR)/$(program)
|
|
||||||
|
|
||||||
.DEFAULT_GOAL := build
|
|
||||||
|
|
||||||
.PHONY: fmt vet build bench clean
|
|
||||||
fmt:
|
|
||||||
$(GO) fmt ./...
|
|
||||||
|
|
||||||
vet: fmt
|
|
||||||
$(GO) vet ./...
|
|
||||||
|
|
||||||
build: vet | $(BIN_DIR)
|
|
||||||
$(GO) build -o $(EXE) ./$(SRC_DIR)
|
|
||||||
|
|
||||||
bench:
|
|
||||||
$(GO) test ./internal/one/ -bench=. > internal/one/benchmark
|
|
||||||
$(GO) test ./internal/two/ -bench=. > internal/two/benchmark
|
|
||||||
$(GO) test . -count=10 -bench=. > benchmark
|
|
||||||
|
|
||||||
$(BIN_DIR):
|
|
||||||
@mkdir -p $@
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@rm -rv $(BIN_DIR)
|
|
@ -1,20 +0,0 @@
|
|||||||
package daytwo
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/onyx-and-iris/aoc2024/day-02/internal/one"
|
|
||||||
"github.com/onyx-and-iris/aoc2024/day-02/internal/two"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Solve(data []byte) (int, int, error) {
|
|
||||||
answerOne, err := one.Solve(data)
|
|
||||||
if err != nil {
|
|
||||||
return 0, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
answerTwo, err := two.Solve(data)
|
|
||||||
if err != nil {
|
|
||||||
return 0, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return answerOne, answerTwo, nil
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package daytwo
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user