mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-04-19 19:23:47 +01:00
Compare commits
No commits in common. "287a1682934668db9f2a1143d2ae7c9dd78d8b0a" and "3ccdd9fdf6d5ea3369dc07c4d4c49c9426242038" have entirely different histories.
287a168293
...
3ccdd9fdf6
@ -10,18 +10,18 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const numEmptyHeaps int = 9
|
const numEmptyBlocks int = 9
|
||||||
|
|
||||||
type disk struct {
|
type disk struct {
|
||||||
data []int
|
data []int
|
||||||
fileblocks []*block
|
fileblocks []*block
|
||||||
emptyHeaps [numEmptyHeaps]minHeap
|
emptyblocks [numEmptyBlocks]minHeap
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDisk(raw []int) *disk {
|
func newDisk(raw []int) *disk {
|
||||||
fileblocks := make([]*block, 0)
|
fileblocks := make([]*block, 0)
|
||||||
emptyblockHeaps := make([]minHeap, numEmptyHeaps)
|
emptyblockHeaps := make([]minHeap, numEmptyBlocks)
|
||||||
for i := range numEmptyHeaps {
|
for i := range numEmptyBlocks {
|
||||||
heap.Init(&emptyblockHeaps[i])
|
heap.Init(&emptyblockHeaps[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ func newDisk(raw []int) *disk {
|
|||||||
|
|
||||||
log.Debugf("\n%v\n%v", fileblocks, emptyblockHeaps)
|
log.Debugf("\n%v\n%v", fileblocks, emptyblockHeaps)
|
||||||
|
|
||||||
return &disk{data: raw, fileblocks: fileblocks, emptyHeaps: [numEmptyHeaps]minHeap(emptyblockHeaps)}
|
return &disk{data: raw, fileblocks: fileblocks, emptyblocks: [numEmptyBlocks]minHeap(emptyblockHeaps)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *disk) defragment() {
|
func (d *disk) defragment() {
|
||||||
@ -71,12 +71,12 @@ func (d *disk) defragment() {
|
|||||||
emptyblock.length -= d.fileblocks[i].length
|
emptyblock.length -= d.fileblocks[i].length
|
||||||
if emptyblock.length > 0 {
|
if emptyblock.length > 0 {
|
||||||
log.Debugf("emptyblock resized %d", emptyblock.length)
|
log.Debugf("emptyblock resized %d", emptyblock.length)
|
||||||
heap.Push(&d.emptyHeaps[emptyblock.length-1], emptyblock)
|
heap.Push(&d.emptyblocks[emptyblock.length-1], emptyblock)
|
||||||
}
|
}
|
||||||
|
|
||||||
// now create a new empty block and push it to the appropriate heap
|
// now create a new empty block and push it to the appropriate heap
|
||||||
heap.Push(
|
heap.Push(
|
||||||
&d.emptyHeaps[oldLength-1],
|
&d.emptyblocks[oldLength-1],
|
||||||
newBlock(kindOfEmpty, math.MaxInt, oldStart, oldLength, empty),
|
newBlock(kindOfEmpty, math.MaxInt, oldStart, oldLength, empty),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -85,12 +85,12 @@ func (d *disk) defragment() {
|
|||||||
func (d *disk) getNextEmptyBlock(currentFile *block) (*block, error) {
|
func (d *disk) getNextEmptyBlock(currentFile *block) (*block, error) {
|
||||||
// collect all minblocks the same size as the current file or greater
|
// collect all minblocks the same size as the current file or greater
|
||||||
minBlocks := []*block{}
|
minBlocks := []*block{}
|
||||||
for j := currentFile.length; j <= numEmptyHeaps; j++ {
|
for j := currentFile.length; j <= numEmptyBlocks; j++ {
|
||||||
if d.emptyHeaps[j-1].Len() == 0 {
|
if d.emptyblocks[j-1].Len() == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
currentblock := heap.Pop(&d.emptyHeaps[j-1]).(*block)
|
currentblock := heap.Pop(&d.emptyblocks[j-1]).(*block)
|
||||||
minBlocks = append(minBlocks, currentblock)
|
minBlocks = append(minBlocks, currentblock)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,12 +104,12 @@ func (d *disk) getNextEmptyBlock(currentFile *block) (*block, error) {
|
|||||||
})
|
})
|
||||||
// push back the ones we won't be using
|
// push back the ones we won't be using
|
||||||
for _, block := range minBlocks[1:] {
|
for _, block := range minBlocks[1:] {
|
||||||
heap.Push(&d.emptyHeaps[block.length-1], block)
|
heap.Push(&d.emptyblocks[block.length-1], block)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the lowest id minblock is positioned after the current file, push it back and return an error
|
// if the lowest id minblock is positioned after the current file, push it back and return an error
|
||||||
if minBlocks[0].start >= currentFile.start {
|
if minBlocks[0].start >= currentFile.start {
|
||||||
heap.Push(&d.emptyHeaps[minBlocks[0].length-1], minBlocks[0])
|
heap.Push(&d.emptyblocks[minBlocks[0].length-1], minBlocks[0])
|
||||||
return nil, errors.New("no empty blocks found")
|
return nil, errors.New("no empty blocks found")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,9 +123,9 @@ func (d *disk) write() {
|
|||||||
|
|
||||||
allBlocks = append(allBlocks, d.fileblocks...)
|
allBlocks = append(allBlocks, d.fileblocks...)
|
||||||
|
|
||||||
for i := range numEmptyHeaps {
|
for i := range numEmptyBlocks {
|
||||||
for !d.emptyHeaps[i].IsEmpty() {
|
for !d.emptyblocks[i].IsEmpty() {
|
||||||
allBlocks = append(allBlocks, heap.Pop(&d.emptyHeaps[i]).(*block))
|
allBlocks = append(allBlocks, heap.Pop(&d.emptyblocks[i]).(*block))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
goos: linux
|
|
||||||
goarch: amd64
|
|
||||||
pkg: github.com/onyx-and-iris/aoc2024/day-22
|
|
||||||
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
|
|
||||||
BenchmarkSolve-12 1 2054969661 ns/op
|
|
||||||
BenchmarkSolve-12 1 1820308129 ns/op
|
|
||||||
BenchmarkSolve-12 1 1853098610 ns/op
|
|
||||||
BenchmarkSolve-12 1 1825725443 ns/op
|
|
||||||
BenchmarkSolve-12 1 1817395243 ns/op
|
|
||||||
BenchmarkSolve-12 1 1823292443 ns/op
|
|
||||||
BenchmarkSolve-12 1 1825067743 ns/op
|
|
||||||
BenchmarkSolve-12 1 1827243915 ns/op
|
|
||||||
BenchmarkSolve-12 1 1821714708 ns/op
|
|
||||||
BenchmarkSolve-12 1 1825390608 ns/op
|
|
||||||
ok github.com/onyx-and-iris/aoc2024/day-22 18.538s
|
|
@ -1,41 +0,0 @@
|
|||||||
/********************************************************************************
|
|
||||||
Advent of Code 2024 - day-22
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"embed"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"slices"
|
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
problems "github.com/onyx-and-iris/aoc2024/day-22"
|
|
||||||
)
|
|
||||||
|
|
||||||
//go:embed testdata
|
|
||||||
var files embed.FS
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
filename := flag.String("f", "input.txt", "input file")
|
|
||||||
loglevel := flag.Int("l", int(log.InfoLevel), "log level")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
if slices.Contains(log.AllLevels, log.Level(*loglevel)) {
|
|
||||||
log.SetLevel(log.Level(*loglevel))
|
|
||||||
}
|
|
||||||
|
|
||||||
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,7 +0,0 @@
|
|||||||
module github.com/onyx-and-iris/aoc2024/day-22
|
|
||||||
|
|
||||||
go 1.23.3
|
|
||||||
|
|
||||||
require github.com/sirupsen/logrus v1.9.3
|
|
||||||
|
|
||||||
require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
|
|
@ -1,15 +0,0 @@
|
|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
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/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
|
||||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
|
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
@ -1,6 +0,0 @@
|
|||||||
goos: linux
|
|
||||||
goarch: amd64
|
|
||||||
pkg: github.com/onyx-and-iris/aoc2024/day-22/internal/one
|
|
||||||
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
|
|
||||||
BenchmarkSolve-12 1000000000 0.03026 ns/op
|
|
||||||
ok github.com/onyx-and-iris/aoc2024/day-22/internal/one 0.219s
|
|
@ -1,29 +0,0 @@
|
|||||||
package one
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
|
|
||||||
"github.com/onyx-and-iris/aoc2024/day-22/internal/randomiser"
|
|
||||||
)
|
|
||||||
|
|
||||||
const numIterations = 2000
|
|
||||||
|
|
||||||
func Solve(buf []byte) (int, error) {
|
|
||||||
r := bytes.NewReader(buf)
|
|
||||||
secrets, err := parseLines(r)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var sum int
|
|
||||||
for _, secret := range secrets {
|
|
||||||
randomiser := randomiser.New(secret)
|
|
||||||
|
|
||||||
for range numIterations {
|
|
||||||
randomiser.Randomise()
|
|
||||||
}
|
|
||||||
sum += randomiser.Secret()
|
|
||||||
}
|
|
||||||
|
|
||||||
return sum, nil
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package one
|
|
||||||
|
|
||||||
import (
|
|
||||||
_ "embed"
|
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
//go:embed testdata/input.txt
|
|
||||||
var data []byte
|
|
||||||
|
|
||||||
func BenchmarkSolve(b *testing.B) {
|
|
||||||
os.Stdout, _ = os.Open(os.DevNull)
|
|
||||||
Solve(data)
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
package one
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"io"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func parseLines(r io.Reader) ([]int, error) {
|
|
||||||
secrets := []int{}
|
|
||||||
|
|
||||||
scanner := bufio.NewScanner(r)
|
|
||||||
for scanner.Scan() {
|
|
||||||
secrets = append(secrets, mustConv(strings.TrimSpace(scanner.Text())))
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := scanner.Err(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return secrets, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func mustConv(s string) int {
|
|
||||||
n, err := strconv.Atoi(s)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return n
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
package randomiser
|
|
||||||
|
|
||||||
type Randomiser struct {
|
|
||||||
secret int
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(secret int) *Randomiser {
|
|
||||||
return &Randomiser{secret: secret}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Randomiser) multiplyBy(n int) int {
|
|
||||||
return r.secret * n
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Randomiser) divideBy(n int) int {
|
|
||||||
return r.secret / n
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Randomiser) mix(a int) {
|
|
||||||
r.secret ^= a
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Randomiser) prune() {
|
|
||||||
r.secret %= 16777216
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Randomiser) Randomise() {
|
|
||||||
res := r.multiplyBy(64)
|
|
||||||
r.mix(res)
|
|
||||||
r.prune()
|
|
||||||
|
|
||||||
res = r.divideBy(32)
|
|
||||||
r.mix(res)
|
|
||||||
r.prune()
|
|
||||||
|
|
||||||
res = r.multiplyBy(2048)
|
|
||||||
r.mix(res)
|
|
||||||
r.prune()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Randomiser) Secret() int {
|
|
||||||
return r.secret
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package randomiser
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
|
|
||||||
func TestRandomiserMix(t *testing.T) {
|
|
||||||
r := New(42)
|
|
||||||
r.mix(15)
|
|
||||||
if r.secret != 37 {
|
|
||||||
t.Errorf("r.secret: got = %d want = 3", r.secret)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRandomiserPrune(t *testing.T) {
|
|
||||||
r := New(10e7)
|
|
||||||
r.prune()
|
|
||||||
if r.secret != 16113920 {
|
|
||||||
t.Errorf("r.secret: got = %d want = 16113920", r.secret)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
goos: linux
|
|
||||||
goarch: amd64
|
|
||||||
pkg: github.com/onyx-and-iris/aoc2024/day-22/internal/two
|
|
||||||
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
|
|
||||||
BenchmarkSolve-12 1 2064547562 ns/op
|
|
||||||
ok github.com/onyx-and-iris/aoc2024/day-22/internal/two 2.091s
|
|
@ -1,21 +0,0 @@
|
|||||||
package two
|
|
||||||
|
|
||||||
import "sync"
|
|
||||||
|
|
||||||
type sequenceCache struct {
|
|
||||||
mu sync.RWMutex
|
|
||||||
data map[sequence]int
|
|
||||||
}
|
|
||||||
|
|
||||||
func newSequenceCache() sequenceCache {
|
|
||||||
return sequenceCache{
|
|
||||||
data: make(map[sequence]int),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sc *sequenceCache) upsert(seq sequence, value int) {
|
|
||||||
sc.mu.Lock()
|
|
||||||
defer sc.mu.Unlock()
|
|
||||||
|
|
||||||
sc.data[seq] += value
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package two
|
|
||||||
|
|
||||||
type sequence [4]int
|
|
||||||
|
|
||||||
func (s *sequence) shift(next int) {
|
|
||||||
s[0], s[1], s[2], s[3] = s[1], s[2], s[3], next
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
package two
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"math"
|
|
||||||
|
|
||||||
"github.com/onyx-and-iris/aoc2024/day-22/internal/randomiser"
|
|
||||||
)
|
|
||||||
|
|
||||||
const numIterations = 2000
|
|
||||||
|
|
||||||
func Solve(buf []byte) (int, error) {
|
|
||||||
r := bytes.NewReader(buf)
|
|
||||||
secrets, err := parseLines(r)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
conc := len(secrets)
|
|
||||||
done := make(chan bool)
|
|
||||||
|
|
||||||
sequences := newSequenceCache()
|
|
||||||
for _, secret := range secrets {
|
|
||||||
go func() {
|
|
||||||
seen := make(map[sequence]struct{})
|
|
||||||
sequence := sequence{math.MaxInt, math.MaxInt, math.MaxInt, math.MaxInt}
|
|
||||||
|
|
||||||
randomiser := randomiser.New(secret)
|
|
||||||
for range numIterations {
|
|
||||||
prev := lastDigit(randomiser.Secret())
|
|
||||||
randomiser.Randomise()
|
|
||||||
|
|
||||||
sequence.shift(prev - lastDigit(randomiser.Secret()))
|
|
||||||
|
|
||||||
_, ok := seen[sequence]
|
|
||||||
if !ok {
|
|
||||||
seen[sequence] = struct{}{}
|
|
||||||
sequences.upsert(sequence, lastDigit(randomiser.Secret()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
done <- true
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
for range conc {
|
|
||||||
<-done
|
|
||||||
}
|
|
||||||
|
|
||||||
max := 0
|
|
||||||
for _, sum := range sequences.data {
|
|
||||||
if sum > max {
|
|
||||||
max = sum
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return max, nil
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package two
|
|
||||||
|
|
||||||
import (
|
|
||||||
_ "embed"
|
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
//go:embed testdata/input.txt
|
|
||||||
var data []byte
|
|
||||||
|
|
||||||
func BenchmarkSolve(b *testing.B) {
|
|
||||||
os.Stdout, _ = os.Open(os.DevNull)
|
|
||||||
Solve(data)
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
package two
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"io"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func parseLines(r io.Reader) ([]int, error) {
|
|
||||||
secrets := []int{}
|
|
||||||
|
|
||||||
scanner := bufio.NewScanner(r)
|
|
||||||
for scanner.Scan() {
|
|
||||||
secrets = append(secrets, mustConv(strings.TrimSpace(scanner.Text())))
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := scanner.Err(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return secrets, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func mustConv(s string) int {
|
|
||||||
n, err := strconv.Atoi(s)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
func lastDigit(n int) int {
|
|
||||||
return n % 10
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
program = day-22
|
|
||||||
|
|
||||||
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 daytwentytwo
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/onyx-and-iris/aoc2024/day-22/internal/one"
|
|
||||||
"github.com/onyx-and-iris/aoc2024/day-22/internal/two"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Solve(buf []byte) (int, int, error) {
|
|
||||||
answerOne, err := one.Solve(buf)
|
|
||||||
if err != nil {
|
|
||||||
return 0, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
answerTwo, err := two.Solve(buf)
|
|
||||||
if err != nil {
|
|
||||||
return 0, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return answerOne, answerTwo, nil
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package daytwentytwo
|
|
||||||
|
|
||||||
import (
|
|
||||||
_ "embed"
|
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
//go:embed testdata/input.txt
|
|
||||||
var data []byte
|
|
||||||
|
|
||||||
func BenchmarkSolve(b *testing.B) {
|
|
||||||
os.Stdout, _ = os.Open(os.DevNull)
|
|
||||||
Solve(data)
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user