├── .github └── workflows │ └── ci.yml ├── .gitignore ├── Makefile ├── README.md ├── cmd ├── root.go └── scaffold.go ├── go.mod ├── go.sum ├── helpers ├── doc.go ├── logging.go ├── numbers.go ├── numbers_test.go ├── priority_queue.go ├── priority_queue_test.go ├── solution.go ├── testdata │ ├── numbers │ │ ├── 10-large-integers.txt │ │ ├── 10-small-integers.txt │ │ ├── 25000-large-integers.txt │ │ ├── 25000-small-integers.txt │ │ ├── 500-large-integers.txt │ │ └── 500-small-integers.txt │ └── text │ │ └── go-proverbs.txt ├── testing.go ├── text.go └── text_test.go ├── main.go ├── scaffolding ├── generator.go └── templates │ ├── solution.go.tmpl │ └── solution_test.go.tmpl ├── y2015 ├── d01 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d02 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d03 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d04 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d05 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt └── d06 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ └── input.txt ├── y2019 ├── d01 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d02 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d05 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt └── intcode │ ├── errors.go │ ├── instructions.go │ ├── intcode.go │ ├── intcode_test.go │ └── state.go ├── y2020 ├── d01 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d02 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d03 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d04 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d05 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d06 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d07 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d08 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d09 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d10 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d11 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d12 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d13 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d14 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d15 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d16 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d17 │ ├── cubic.go │ ├── hypercubic.go │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d18 │ ├── solution.go │ ├── solution_test.go │ ├── stacks.go │ └── testdata │ │ └── input.txt ├── d19 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d20 │ ├── sea_monster.go │ ├── solution.go │ ├── solution_test.go │ ├── testdata │ │ └── input.txt │ ├── tile.go │ └── tile_test.go ├── d21 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d22 │ ├── game.go │ ├── ring_deck.go │ ├── slice_deck.go │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d23 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d24 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt └── d25 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ └── input.txt ├── y2021 ├── d01 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d02 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d03 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d04 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d05 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d06 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d07 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d08 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d09 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d10 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d11 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d12 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d13 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d14 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d15 │ ├── priority_queue.go │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d16 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d17 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d18 │ ├── decoder.go │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d19 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d20 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d21 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d22 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d23 │ ├── priority_queue.go │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d24 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt └── d25 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ └── input.txt ├── y2022 ├── d01 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d02 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d03 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d04 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d05 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d06 │ ├── solution.go │ ├── solution_test.go │ ├── solution_xor.go │ ├── solution_xor_test.go │ └── testdata │ │ └── input.txt ├── d07 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d08 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d09 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d10 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d11 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d12 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d13 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d14 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d15 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d16 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d17 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d18 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d19 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d20 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d21 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d22 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d23 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d24 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt └── d25 │ ├── slices │ └── slices.go │ ├── solution.go │ ├── solution_test.go │ └── testdata │ └── input.txt ├── y2023 ├── d01 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d02 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d03 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d04 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d05 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d06 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d07 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d08 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d09 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d10 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d11 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d12 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d13 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d14 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d15 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d16 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d17 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d18 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d19 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d20 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d21 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d22 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d23 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt ├── d24 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ │ └── input.txt └── d25 │ ├── solution.go │ ├── solution_test.go │ └── testdata │ └── input.txt └── y2024 ├── d01 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d02 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d03 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d04 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d05 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d06 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d07 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d08 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d09 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d10 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d11 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d12 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d13 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d14 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d15 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d16 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d17 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d18 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d19 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d20 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d21 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt ├── d22 ├── solution.go ├── solution_test.go └── testdata │ └── input.txt └── d23 ├── solution.go ├── solution_test.go └── testdata └── input.txt /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Unit tests 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build-and-unit-tests: 7 | name: Unit Tests 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v3 11 | - uses: actions/setup-go@v3 12 | with: 13 | go-version-file: ./go.mod 14 | - run: make build test 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | bin 8 | 9 | # Test binary, build with `go test -c` 10 | *.test 11 | 12 | # Output of the go coverage tool, specifically when used with LiteIDE 13 | *.out 14 | 15 | # editor and IDE paraphernalia 16 | .idea 17 | *.swp 18 | *.swo 19 | *~ 20 | 21 | # direnv source file 22 | .envrc 23 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .DEFAULT_TARGET = help 2 | 3 | ## help: Display list of commands 4 | .PHONY: help 5 | help: Makefile 6 | @sed -n 's|^##||p' $< | column -t -s ':' | sed -e 's|^| |' 7 | 8 | ## build: Build adventofcode binary 9 | build: fmt vet 10 | go build -o bin/adventofcode main.go 11 | 12 | ## test: Run tests 13 | test: fmt vet 14 | go test ./... -cover 15 | 16 | ## bench: Run tests & benchmarks 17 | bench: fmt vet 18 | go test ./... -cover -bench . -benchmem -cpu 1,2,4,8 19 | 20 | ## run: Run adventofcode CLI 21 | run: fmt vet 22 | go run ./main.go 23 | 24 | ## fmt: Run go fmt against code 25 | fmt: 26 | go fmt ./... 27 | 28 | ## vet: Run go vet against code 29 | vet: 30 | go vet ./... 31 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/busser/adventofcode 2 | 3 | go 1.23 4 | 5 | require ( 6 | github.com/google/go-cmp v0.5.9 7 | github.com/mitchellh/go-homedir v1.1.0 8 | github.com/spf13/cobra v1.6.1 9 | github.com/spf13/viper v1.14.0 10 | ) 11 | 12 | require ( 13 | github.com/fsnotify/fsnotify v1.6.0 // indirect 14 | github.com/hashicorp/hcl v1.0.0 // indirect 15 | github.com/inconshreveable/mousetrap v1.0.1 // indirect 16 | github.com/magiconair/properties v1.8.6 // indirect 17 | github.com/mitchellh/mapstructure v1.5.0 // indirect 18 | github.com/pelletier/go-toml v1.9.5 // indirect 19 | github.com/pelletier/go-toml/v2 v2.0.5 // indirect 20 | github.com/spf13/afero v1.9.2 // indirect 21 | github.com/spf13/cast v1.5.0 // indirect 22 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 23 | github.com/spf13/pflag v1.0.5 // indirect 24 | github.com/subosito/gotenv v1.4.1 // indirect 25 | golang.org/x/sys v0.0.0-20220908164124-27713097b956 // indirect 26 | golang.org/x/text v0.4.0 // indirect 27 | gopkg.in/ini.v1 v1.67.0 // indirect 28 | gopkg.in/yaml.v2 v2.4.0 // indirect 29 | gopkg.in/yaml.v3 v3.0.1 // indirect 30 | ) 31 | -------------------------------------------------------------------------------- /helpers/doc.go: -------------------------------------------------------------------------------- 1 | // Package helpers provides simple utilitary functions usable in solutions to 2 | // Advent of Code problems. 3 | package helpers 4 | -------------------------------------------------------------------------------- /helpers/logging.go: -------------------------------------------------------------------------------- 1 | package helpers 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | "path/filepath" 8 | "runtime" 9 | "strings" 10 | ) 11 | 12 | // Print logs values to standard error. 13 | func Print(v ...interface{}) { 14 | logger := log.New(os.Stderr, debugPrefix(), 0) 15 | logger.Print(v...) 16 | } 17 | 18 | // Printf logs values to standard error with the provided format. 19 | func Printf(format string, v ...interface{}) { 20 | logger := log.New(os.Stderr, debugPrefix(), 0) 21 | logger.Printf(format, v...) 22 | } 23 | 24 | // Println logs values to standard error, then starts a new line. 25 | func Println(v ...interface{}) { 26 | logger := log.New(os.Stderr, debugPrefix(), 0) 27 | logger.Println(v...) 28 | } 29 | 30 | func debugPrefix() string { 31 | programCounter, fileAbsolutePath, line, _ := runtime.Caller(2) 32 | 33 | packageName := packageFromFunc(runtime.FuncForPC(programCounter)) 34 | _, fileName := filepath.Split(fileAbsolutePath) 35 | fullFileName := filepath.Join(packageName, fileName) 36 | 37 | return fmt.Sprintf("[%s:%d] ", fullFileName, line) 38 | } 39 | 40 | func packageFromFunc(f *runtime.Func) string { 41 | splitName := strings.Split(f.Name(), ".") 42 | packageName := strings.Join(splitName[:len(splitName)-1], ".") 43 | packageName = strings.TrimPrefix(packageName, "github.com/busser/adventofcode/") 44 | return packageName 45 | } 46 | -------------------------------------------------------------------------------- /helpers/numbers.go: -------------------------------------------------------------------------------- 1 | package helpers 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | // IntsFromString returns a slice of integers in str, where these numbers are 9 | // separated by non-number runes. If a dash preceding a number is the only 10 | // non-number rune between two numbers, it is considered a separator; otherwise, 11 | // it is considered part of the number, which is consequently negative. 12 | func IntsFromString(str string) []int { 13 | words := splitStringIntoIntStrings(str) 14 | 15 | ints := make([]int, len(words)) 16 | 17 | for i, w := range words { 18 | n, err := strconv.Atoi(w) 19 | if err != nil { 20 | panic(fmt.Sprintf("could not parse int %q: %v", w, err)) 21 | } 22 | 23 | ints[i] = n 24 | } 25 | 26 | return ints 27 | } 28 | 29 | func splitStringIntoIntStrings(str string) []string { 30 | var ( 31 | words []string 32 | wordBuf []byte 33 | ) 34 | 35 | for i := range str { 36 | b := str[i] 37 | 38 | if b >= '0' && b <= '9' { 39 | wordBuf = append(wordBuf, b) 40 | continue 41 | } 42 | 43 | if b == '-' && len(wordBuf) == 0 { 44 | wordBuf = append(wordBuf, b) 45 | continue 46 | } 47 | 48 | if len(wordBuf) > 0 { 49 | words = append(words, string(wordBuf)) 50 | wordBuf = wordBuf[:0] // reuse underlying array 51 | } 52 | } 53 | 54 | if len(wordBuf) > 0 { 55 | words = append(words, string(wordBuf)) 56 | } 57 | 58 | return words 59 | } 60 | -------------------------------------------------------------------------------- /helpers/priority_queue.go: -------------------------------------------------------------------------------- 1 | package helpers 2 | 3 | type PriorityQueue[T any] struct { 4 | items []T 5 | less func(a, b T) bool 6 | } 7 | 8 | func NewPriorityQueue[T any](less func(a, b T) bool) *PriorityQueue[T] { 9 | return &PriorityQueue[T]{ 10 | items: make([]T, 0), 11 | less: less, 12 | } 13 | } 14 | 15 | func (pq PriorityQueue[T]) Len() int { 16 | return len(pq.items) 17 | } 18 | 19 | func (pq *PriorityQueue[T]) Push(x T) { 20 | pq.items = append(pq.items, x) 21 | pq.up(len(pq.items) - 1) 22 | } 23 | 24 | func (pq *PriorityQueue[T]) Pop() T { 25 | n := len(pq.items) 26 | pq.swap(0, n-1) 27 | popped := pq.items[n-1] 28 | pq.items[n-1] = *new(T) 29 | pq.items = pq.items[0 : n-1] 30 | pq.down(0) 31 | return popped 32 | } 33 | 34 | func (pq *PriorityQueue[T]) up(j int) { 35 | for { 36 | i := (j - 1) / 2 // parent 37 | if i == j || !pq.less(pq.items[j], pq.items[i]) { 38 | break 39 | } 40 | pq.swap(i, j) 41 | j = i 42 | } 43 | } 44 | 45 | func (pq *PriorityQueue[T]) down(i0 int) { 46 | n := len(pq.items) 47 | i := i0 48 | for { 49 | left := 2*i + 1 50 | if left >= n || left < 0 { // left < 0 after int overflow 51 | break 52 | } 53 | j := left // left child 54 | if right := left + 1; right < n && pq.less(pq.items[right], pq.items[left]) { 55 | j = right // = 2*i + 2 // right child 56 | } 57 | if !pq.less(pq.items[j], pq.items[i]) { 58 | break 59 | } 60 | pq.swap(i, j) 61 | i = j 62 | } 63 | } 64 | 65 | func (pq *PriorityQueue[T]) swap(i, j int) { 66 | pq.items[i], pq.items[j] = pq.items[j], pq.items[i] 67 | } 68 | -------------------------------------------------------------------------------- /helpers/solution.go: -------------------------------------------------------------------------------- 1 | package helpers 2 | 3 | import "io" 4 | 5 | // A Solution solves an Advent of Code problem. 6 | type Solution interface { 7 | // Solve reads the problem input and writes the answer. If something goes 8 | // wrong, Solve returns an error. 9 | Solve(input io.Reader, answer io.Writer) error 10 | } 11 | 12 | // The SolutionFunc type is an adapter to allow the use of ordinary functions as 13 | // solutions. If f is a function with the appropriate signature, SolutionFunc(f) 14 | // is a Solution that calls f. 15 | type SolutionFunc func(input io.Reader, answer io.Writer) error 16 | 17 | // Solve calls f(answer, input). 18 | func (f SolutionFunc) Solve(input io.Reader, answer io.Writer) error { 19 | return f(input, answer) 20 | } 21 | -------------------------------------------------------------------------------- /helpers/testdata/numbers/10-large-integers.txt: -------------------------------------------------------------------------------- 1 | 936317175 -1278554853 -867900152 -704812329 -1344148881 -864248091 -1121464256 776579163 620037548 -1908410724 2 | -------------------------------------------------------------------------------- /helpers/testdata/numbers/10-small-integers.txt: -------------------------------------------------------------------------------- 1 | 95 50 -31 22 -1 -17 32 52 -32 26 2 | -------------------------------------------------------------------------------- /helpers/testdata/text/go-proverbs.txt: -------------------------------------------------------------------------------- 1 | Don't communicate by sharing memory, share memory by communicating. 2 | Concurrency is not parallelism. 3 | Channels orchestrate; mutexes serialize. 4 | The bigger the interface, the weaker the abstraction. 5 | Make the zero value useful. 6 | interface{} says nothing. 7 | Gofmt's style is no one's favorite, yet gofmt is everyone's favorite. 8 | A little copying is better than a little dependency. 9 | Syscall must always be guarded with build tags. 10 | Cgo must always be guarded with build tags. 11 | Cgo is not Go. 12 | With the unsafe package there are no guarantees. 13 | Clear is better than clever. 14 | Reflection is never clear. 15 | Errors are values. 16 | Don't just check errors, handle them gracefully. 17 | Design the architecture, name the components, document the details. 18 | Documentation is for users. 19 | Don't panic. -------------------------------------------------------------------------------- /helpers/testing.go: -------------------------------------------------------------------------------- 1 | package helpers 2 | 3 | import ( 4 | "bytes" 5 | "io/ioutil" 6 | "testing" 7 | ) 8 | 9 | // TestSolution tests whether s, when provided with input, provides the expected 10 | // answer. 11 | func TestSolution(t *testing.T, s Solution, inputFile, answerFile string) { 12 | t.Helper() 13 | 14 | input, err := ioutil.ReadFile(inputFile) 15 | if err != nil { 16 | t.Fatalf("could not read input file: %v", err) 17 | } 18 | 19 | answer, err := ioutil.ReadFile(answerFile) 20 | if err != nil { 21 | t.Fatalf("could not read answer file: %v", err) 22 | } 23 | if len(answer) == 0 { 24 | t.Fatalf("\n👉 Write the answer to %s\n", answerFile) 25 | } 26 | 27 | r := bytes.NewReader(input) 28 | w := &bytes.Buffer{} 29 | 30 | if err := s.Solve(r, w); err != nil { 31 | t.Fatalf("error running solution: %v", err) 32 | } 33 | 34 | actual := w.Bytes() 35 | if !bytes.Equal(answer, actual) { 36 | t.Fatalf("did not get expected answer:\n\texpected: %q\n\tgot: %q", answer, actual) 37 | } 38 | } 39 | 40 | // BenchmarkSolution runs a benchmark of s with the provided input. 41 | func BenchmarkSolution(b *testing.B, s Solution, inputFile string) { 42 | b.Helper() 43 | 44 | input, err := ioutil.ReadFile(inputFile) 45 | if err != nil { 46 | b.Fatalf("could not read input file: %v", err) 47 | } 48 | 49 | r := bytes.NewReader(input) 50 | w := ioutil.Discard 51 | 52 | for n := 0; n < b.N; n++ { 53 | r.Reset(input) 54 | _ = s.Solve(r, w) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /helpers/text.go: -------------------------------------------------------------------------------- 1 | package helpers 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "io" 7 | ) 8 | 9 | // LinesFromReader returns a slice of all lines in r. 10 | func LinesFromReader(r io.Reader) ([]string, error) { 11 | var lines []string 12 | 13 | s := bufio.NewScanner(r) 14 | for s.Scan() { 15 | lines = append(lines, s.Text()) 16 | } 17 | if s.Err() != nil { 18 | return nil, fmt.Errorf("failed to scan reader: %w", s.Err()) 19 | } 20 | 21 | return lines, nil 22 | } 23 | -------------------------------------------------------------------------------- /helpers/text_test.go: -------------------------------------------------------------------------------- 1 | package helpers 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io/ioutil" 7 | "log" 8 | "os" 9 | "testing" 10 | ) 11 | 12 | func ExampleLinesFromReader() { 13 | f, err := os.Open("testdata/text/go-proverbs.txt") 14 | if err != nil { 15 | log.Fatal(err) 16 | } 17 | 18 | lines, err := LinesFromReader(f) 19 | if err != nil { 20 | log.Fatal(err) 21 | } 22 | 23 | fmt.Printf("Number of lines: %d\n", len(lines)) 24 | fmt.Printf("The first one is: %q\n", lines[0]) 25 | // Output: 26 | // Number of lines: 19 27 | // The first one is: "Don't communicate by sharing memory, share memory by communicating." 28 | } 29 | 30 | func BenchmarkLinesFromReader(b *testing.B) { 31 | benchmarks := []struct { 32 | name string 33 | dataFile string 34 | }{ 35 | { 36 | name: "go-proverbs", 37 | dataFile: "testdata/text/go-proverbs.txt", 38 | }, 39 | } 40 | 41 | for _, bench := range benchmarks { 42 | b.Run(bench.name, func(b *testing.B) { 43 | data, err := ioutil.ReadFile(bench.dataFile) 44 | if err != nil { 45 | b.Fatalf("could not read test data file: %v", err) 46 | } 47 | 48 | r := bytes.NewReader(data) 49 | 50 | b.ResetTimer() 51 | 52 | for n := 0; n < b.N; n++ { 53 | b.StopTimer() 54 | r.Reset(data) 55 | b.StartTimer() 56 | 57 | _, _ = LinesFromReader(r) 58 | } 59 | }) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/busser/adventofcode/cmd" 4 | 5 | func main() { 6 | cmd.Execute() 7 | } 8 | -------------------------------------------------------------------------------- /scaffolding/templates/solution.go.tmpl: -------------------------------------------------------------------------------- 1 | package d{{ printf "%02d" .Day }} 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | 7 | "github.com/busser/adventofcode/helpers" 8 | ) 9 | 10 | // PartOne solves the first problem of day {{ .Day }} of Advent of Code {{ .Year }}. 11 | func PartOne(r io.Reader, w io.Writer) error { 12 | // TODO: Read the input. For example: 13 | lines, err := helpers.LinesFromReader(r) 14 | if err != nil { 15 | return fmt.Errorf("could not read input: %w", err) 16 | } 17 | 18 | // TODO: Write the answer. For example: 19 | _, err = fmt.Fprintf(w, "%d", len(lines)) 20 | if err != nil { 21 | return fmt.Errorf("could not write answer: %w", err) 22 | } 23 | 24 | return nil 25 | } 26 | 27 | // PartTwo solves the second problem of day {{ .Day }} of Advent of Code {{ .Year }}. 28 | func PartTwo(r io.Reader, w io.Writer) error { 29 | // TODO: Read the input. For example: 30 | lines, err := helpers.LinesFromReader(r) 31 | if err != nil { 32 | return fmt.Errorf("could not read input: %w", err) 33 | } 34 | 35 | // TODO: Write the answer. For example: 36 | _, err = fmt.Fprintf(w, "%d", len(lines)) 37 | if err != nil { 38 | return fmt.Errorf("could not write answer: %w", err) 39 | } 40 | 41 | return nil 42 | } 43 | -------------------------------------------------------------------------------- /scaffolding/templates/solution_test.go.tmpl: -------------------------------------------------------------------------------- 1 | package d{{ printf "%02d" .Day }} 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 👉 Write the answer here 👈 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 👉 Write the answer here 👈 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } -------------------------------------------------------------------------------- /y2015/d01/solution_test.go: -------------------------------------------------------------------------------- 1 | package d01 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 280 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 1797 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2015/d02/solution_test.go: -------------------------------------------------------------------------------- 1 | package d02 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 1588178 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 3783758 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2015/d03/solution_test.go: -------------------------------------------------------------------------------- 1 | package d03 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 2081 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 2341 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2015/d04/solution_test.go: -------------------------------------------------------------------------------- 1 | package d04 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 346386 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 9958218 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2015/d04/testdata/input.txt: -------------------------------------------------------------------------------- 1 | iwrupvqb 2 | -------------------------------------------------------------------------------- /y2015/d05/solution_test.go: -------------------------------------------------------------------------------- 1 | package d05 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 255 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 55 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2015/d06/solution_test.go: -------------------------------------------------------------------------------- 1 | package d06 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 400410 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 15343601 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2019/d01/solution_test.go: -------------------------------------------------------------------------------- 1 | package d01 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 3443395 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 5162216 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2019/d01/testdata/input.txt: -------------------------------------------------------------------------------- 1 | 119606 2 | 94066 3 | 80497 4 | 136413 5 | 83710 6 | 136098 7 | 113785 8 | 100655 9 | 148973 10 | 78186 11 | 75572 12 | 68954 13 | 140581 14 | 76963 15 | 123969 16 | 111620 17 | 106957 18 | 80469 19 | 140605 20 | 119650 21 | 112495 22 | 124851 23 | 119725 24 | 93118 25 | 123105 26 | 92952 27 | 131053 28 | 74500 29 | 135647 30 | 107536 31 | 56501 32 | 64458 33 | 115542 34 | 111894 35 | 51608 36 | 85570 37 | 133474 38 | 118513 39 | 109296 40 | 128000 41 | 87127 42 | 146391 43 | 149508 44 | 107219 45 | 70461 46 | 85261 47 | 137378 48 | 138297 49 | 106834 50 | 112664 51 | 53841 52 | 124055 53 | 96992 54 | 91394 55 | 135390 56 | 119457 57 | 84966 58 | 110652 59 | 138798 60 | 65060 61 | 108499 62 | 126384 63 | 116976 64 | 135353 65 | 52801 66 | 53139 67 | 54144 68 | 69494 69 | 52068 70 | 61600 71 | 62762 72 | 102578 73 | 100023 74 | 119232 75 | 97153 76 | 94554 77 | 114131 78 | 54643 79 | 65729 80 | 124430 81 | 106513 82 | 133856 83 | 96803 84 | 132140 85 | 113994 86 | 65320 87 | 123970 88 | 115693 89 | 129066 90 | 132805 91 | 143283 92 | 132702 93 | 109683 94 | 126041 95 | 63310 96 | 82628 97 | 68097 98 | 58927 99 | 123635 100 | 117809 101 | -------------------------------------------------------------------------------- /y2019/d02/solution_test.go: -------------------------------------------------------------------------------- 1 | package d02 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 3716250 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 6472 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2019/d02/testdata/input.txt: -------------------------------------------------------------------------------- 1 | 1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,1,10,19,2,9,19,23,2,23,10,27,1,6,27,31,1,31,6,35,2,35,10,39,1,39,5,43,2,6,43,47,2,47,10,51,1,51,6,55,1,55,6,59,1,9,59,63,1,63,9,67,1,67,6,71,2,71,13,75,1,75,5,79,1,79,9,83,2,6,83,87,1,87,5,91,2,6,91,95,1,95,9,99,2,6,99,103,1,5,103,107,1,6,107,111,1,111,10,115,2,115,13,119,1,119,6,123,1,123,2,127,1,127,5,0,99,2,14,0,0 2 | -------------------------------------------------------------------------------- /y2019/d05/solution.go: -------------------------------------------------------------------------------- 1 | package d05 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | 7 | "github.com/busser/adventofcode/y2019/intcode" 8 | ) 9 | 10 | // PartOne solves the first problem of day 5 of Advent of Code 2019. 11 | func PartOne(r io.Reader, w io.Writer) error { 12 | program, err := intcode.ProgramFromReader(r) 13 | if err != nil { 14 | return fmt.Errorf("could not read input: %w", err) 15 | } 16 | 17 | outputs, err := intcode.Run(program, []int{1}) 18 | if err != nil { 19 | return err 20 | } 21 | 22 | _, err = fmt.Fprintf(w, "%d", outputs[len(outputs)-1]) 23 | if err != nil { 24 | return fmt.Errorf("could not write answer: %w", err) 25 | } 26 | 27 | return nil 28 | } 29 | 30 | // PartTwo solves the second problem of day 5 of Advent of Code 2019. 31 | func PartTwo(r io.Reader, w io.Writer) error { 32 | program, err := intcode.ProgramFromReader(r) 33 | if err != nil { 34 | return fmt.Errorf("could not read input: %w", err) 35 | } 36 | 37 | outputs, err := intcode.Run(program, []int{5}) 38 | if err != nil { 39 | return err 40 | } 41 | 42 | _, err = fmt.Fprintf(w, "%d", outputs[len(outputs)-1]) 43 | if err != nil { 44 | return fmt.Errorf("could not write answer: %w", err) 45 | } 46 | 47 | return nil 48 | } 49 | -------------------------------------------------------------------------------- /y2019/d05/solution_test.go: -------------------------------------------------------------------------------- 1 | package d05 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 3122865 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 773660 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2019/intcode/errors.go: -------------------------------------------------------------------------------- 1 | package intcode 2 | 3 | import "fmt" 4 | 5 | type unknownOpcodeError struct { 6 | s *state 7 | opcode int 8 | } 9 | 10 | func (err *unknownOpcodeError) Error() string { 11 | return fmt.Sprintf("unknown opcode %d at position %d", err.s.read(err.s.pointer), err.s.pointer) 12 | } 13 | 14 | type outOfBoundsError struct { 15 | s *state 16 | } 17 | 18 | func (err *outOfBoundsError) Error() string { 19 | return fmt.Sprintf("position %d is out of bounds", err.s.pointer) 20 | } 21 | -------------------------------------------------------------------------------- /y2019/intcode/intcode.go: -------------------------------------------------------------------------------- 1 | package intcode 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | 7 | "github.com/busser/adventofcode/helpers" 8 | ) 9 | 10 | var Debug = true 11 | 12 | func ProgramFromReader(r io.Reader) ([]int, error) { 13 | lines, err := helpers.LinesFromReader(r) 14 | if err != nil { 15 | return nil, err 16 | } 17 | if len(lines) != 1 { 18 | return nil, fmt.Errorf("expected 1 line of input, got %d", len(lines)) 19 | } 20 | 21 | return helpers.IntsFromString(lines[0]), nil 22 | } 23 | 24 | func Run(program, inputs []int) ([]int, error) { 25 | var outputs []int 26 | 27 | s := state{ 28 | program: program, 29 | inputFn: func() int { 30 | v := inputs[0] 31 | inputs = inputs[1:] 32 | return v 33 | }, 34 | outputFn: func(v int) { 35 | outputs = append(outputs, v) 36 | }, 37 | } 38 | 39 | if err := s.run(); err != nil { 40 | return nil, err 41 | } 42 | 43 | return outputs, nil 44 | } 45 | -------------------------------------------------------------------------------- /y2020/d01/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 41979 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 193416912 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d02/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 556 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 605 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d05/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 953 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 615 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d06/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 6530 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 3323 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d07/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 235 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 158493 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d08/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 1610 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 1703 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d09/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 556543474 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 76096372 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d10/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 1656 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 56693912375296 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d10/testdata/input.txt: -------------------------------------------------------------------------------- 1 | 76 2 | 51 3 | 117 4 | 97 5 | 7 6 | 77 7 | 63 8 | 18 9 | 137 10 | 10 11 | 23 12 | 14 13 | 130 14 | 131 15 | 8 16 | 91 17 | 17 18 | 29 19 | 2 20 | 36 21 | 110 22 | 35 23 | 113 24 | 30 25 | 112 26 | 61 27 | 83 28 | 122 29 | 28 30 | 75 31 | 124 32 | 82 33 | 101 34 | 135 35 | 42 36 | 44 37 | 128 38 | 32 39 | 55 40 | 85 41 | 119 42 | 114 43 | 72 44 | 111 45 | 107 46 | 123 47 | 54 48 | 3 49 | 98 50 | 96 51 | 11 52 | 62 53 | 22 54 | 49 55 | 37 56 | 1 57 | 104 58 | 43 59 | 24 60 | 31 61 | 129 62 | 69 63 | 4 64 | 21 65 | 48 66 | 39 67 | 9 68 | 38 69 | 58 70 | 125 71 | 81 72 | 89 73 | 65 74 | 90 75 | 118 76 | 64 77 | 25 78 | 138 79 | 16 80 | 78 81 | 92 82 | 102 83 | 88 84 | 95 85 | 132 86 | 47 87 | 50 88 | 15 89 | 68 90 | 84 91 | 136 92 | 103 93 | -------------------------------------------------------------------------------- /y2020/d11/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 2359 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 2131 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d12/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 2297 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 89984 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d13/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 2238 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 560214575859998 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d13/testdata/input.txt: -------------------------------------------------------------------------------- 1 | 1002618 2 | 19,x,x,x,x,x,x,x,x,41,x,x,x,37,x,x,x,x,x,367,x,x,x,x,x,x,x,x,x,x,x,x,13,x,x,x,17,x,x,x,x,x,x,x,x,x,x,x,29,x,373,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,23 3 | -------------------------------------------------------------------------------- /y2020/d14/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 8332632930672 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 4753238784664 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d15/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 700 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 51358 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d15/testdata/input.txt: -------------------------------------------------------------------------------- 1 | 6,3,15,13,1,0 2 | -------------------------------------------------------------------------------- /y2020/d16/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 23044 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 3765150732757 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d17/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 322 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 2000 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d17/testdata/input.txt: -------------------------------------------------------------------------------- 1 | #....#.# 2 | ..##.##. 3 | #..#..#. 4 | .#..#..# 5 | .#..#... 6 | ##.##### 7 | #..#..#. 8 | ##.##..# 9 | -------------------------------------------------------------------------------- /y2020/d18/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 53660285675207 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 141993988282687 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d18/stacks.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | type numberStack []int 4 | 5 | func (s numberStack) len() int { 6 | return len(s) 7 | } 8 | 9 | func (s *numberStack) push(n int) { 10 | *s = append(*s, n) 11 | } 12 | 13 | func (s numberStack) peek() int { 14 | if len(s) == 0 { 15 | panic("cannot peek into empty stack") 16 | } 17 | 18 | return s[len(s)-1] 19 | } 20 | 21 | func (s *numberStack) pop() int { 22 | if len(*s) == 0 { 23 | panic("cannot pop from empty stack") 24 | } 25 | 26 | n := (*s)[len(*s)-1] 27 | *s = (*s)[:len(*s)-1] 28 | 29 | return n 30 | } 31 | 32 | type operatorStack []rune 33 | 34 | func (s operatorStack) len() int { 35 | return len(s) 36 | } 37 | 38 | func (s *operatorStack) push(op rune) { 39 | *s = append(*s, op) 40 | } 41 | 42 | func (s operatorStack) peek() rune { 43 | if len(s) == 0 { 44 | panic("cannot peek into empty stack") 45 | } 46 | 47 | return s[len(s)-1] 48 | } 49 | 50 | func (s *operatorStack) pop() rune { 51 | if len(*s) == 0 { 52 | panic("cannot pop from empty stack") 53 | } 54 | 55 | op := (*s)[len(*s)-1] 56 | *s = (*s)[:len(*s)-1] 57 | 58 | return op 59 | } 60 | -------------------------------------------------------------------------------- /y2020/d19/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 176 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 352 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d20/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 20913499394191 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 2209 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d21/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 2410 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: tmp,pdpgm,cdslv,zrvtg,ttkn,mkpmkx,vxzpfp,flnhl 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d22/ring_deck.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | const ringDeckMaxSize = MaxDeckSize + 1 8 | 9 | type ringDeck struct { 10 | cards [ringDeckMaxSize]uint8 11 | top, bottom uint8 12 | } 13 | 14 | func newRingDeck() deck { 15 | return new(ringDeck) 16 | } 17 | 18 | func (d *ringDeck) drawFromTop() uint8 { 19 | v := d.cards[d.top] 20 | d.top = (d.top + 1) % ringDeckMaxSize 21 | return v 22 | } 23 | 24 | func (d *ringDeck) insertAtBottom(v uint8) { 25 | d.cards[d.bottom] = v 26 | d.bottom = (d.bottom + 1) % ringDeckMaxSize 27 | } 28 | 29 | func (d ringDeck) size() uint8 { 30 | return (d.bottom - d.top + ringDeckMaxSize) % ringDeckMaxSize 31 | } 32 | 33 | func (d ringDeck) score() uint16 { 34 | total, factor := uint16(0), uint16(d.size()) 35 | for i := d.top; i != d.bottom; i = (i + 1) % ringDeckMaxSize { 36 | total += uint16(d.cards[i]) * factor 37 | factor-- 38 | } 39 | return total 40 | } 41 | 42 | func (d ringDeck) copyTopCards(n uint8) deck { 43 | if d.size() < n { 44 | panic(fmt.Sprintf("cannot copy %d cards from deck containing only %d cards", n, d.size())) 45 | } 46 | 47 | dd := new(ringDeck) 48 | 49 | i := d.top 50 | for ; n > 0; n-- { 51 | dd.insertAtBottom(d.cards[i]) 52 | i = (i + 1) % ringDeckMaxSize 53 | } 54 | 55 | return dd 56 | } 57 | 58 | func (d ringDeck) hash() [MaxDeckSize]uint8 { 59 | var h [MaxDeckSize]uint8 60 | 61 | i := 0 62 | for j := d.top; j != d.bottom; j = (j + 1) % ringDeckMaxSize { 63 | h[i] = d.cards[j] 64 | i++ 65 | } 66 | 67 | return h 68 | } 69 | -------------------------------------------------------------------------------- /y2020/d22/slice_deck.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type sliceDeck []uint8 8 | 9 | func newSliceDeck() deck { 10 | return &sliceDeck{} 11 | } 12 | 13 | func (d *sliceDeck) drawFromTop() uint8 { 14 | v := (*d)[0] 15 | *d = (*d)[1:] 16 | return v 17 | } 18 | 19 | func (d *sliceDeck) insertAtBottom(v uint8) { 20 | *d = append(*d, v) 21 | } 22 | 23 | func (d sliceDeck) size() uint8 { 24 | return uint8(len(d)) 25 | } 26 | 27 | func (d sliceDeck) score() uint16 { 28 | total, factor := uint16(0), uint16(len(d)) 29 | for _, v := range d { 30 | total += uint16(v) * factor 31 | factor-- 32 | } 33 | return total 34 | } 35 | 36 | func (d sliceDeck) copyTopCards(n uint8) deck { 37 | if d.size() < n { 38 | panic(fmt.Sprintf("cannot copy %d cards from deck containing only %d cards", n, d.size())) 39 | } 40 | 41 | dd := make(sliceDeck, n) 42 | copy(dd[:n], d[:n]) 43 | return &dd 44 | } 45 | 46 | func (d sliceDeck) hash() [MaxDeckSize]uint8 { 47 | var dd [MaxDeckSize]uint8 48 | for i, v := range d { 49 | dd[i] = v 50 | } 51 | return dd 52 | } 53 | -------------------------------------------------------------------------------- /y2020/d22/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 31957 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 33212 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d22/testdata/input.txt: -------------------------------------------------------------------------------- 1 | Player 1: 2 | 26 3 | 16 4 | 33 5 | 8 6 | 5 7 | 46 8 | 12 9 | 47 10 | 39 11 | 27 12 | 50 13 | 10 14 | 34 15 | 20 16 | 23 17 | 11 18 | 43 19 | 14 20 | 18 21 | 1 22 | 48 23 | 28 24 | 31 25 | 38 26 | 41 27 | 28 | Player 2: 29 | 45 30 | 7 31 | 9 32 | 4 33 | 15 34 | 19 35 | 49 36 | 3 37 | 36 38 | 25 39 | 24 40 | 2 41 | 21 42 | 37 43 | 35 44 | 44 45 | 29 46 | 13 47 | 32 48 | 22 49 | 17 50 | 30 51 | 42 52 | 40 53 | 6 54 | -------------------------------------------------------------------------------- /y2020/d23/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 46978532 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 163035127721 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d23/testdata/input.txt: -------------------------------------------------------------------------------- 1 | 215694783 2 | -------------------------------------------------------------------------------- /y2020/d24/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 320 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 3777 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2020/d25/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 1478097 22 | } 23 | 24 | func Benchmark(b *testing.B) { 25 | testCases := map[string]struct { 26 | solution helpers.Solution 27 | inputFile string 28 | }{ 29 | "PartOne": { 30 | solution: helpers.SolutionFunc(PartOne), 31 | inputFile: "testdata/input.txt", 32 | }, 33 | } 34 | 35 | for name, test := range testCases { 36 | b.Run(name, func(b *testing.B) { 37 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 38 | }) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /y2020/d25/testdata/input.txt: -------------------------------------------------------------------------------- 1 | 9232416 2 | 14144084 3 | -------------------------------------------------------------------------------- /y2021/d01/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 1400 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 1429 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2021/d02/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 2150351 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 1842742223 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2021/d03/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 3633500 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 4550283 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2021/d04/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 11774 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 4495 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d05/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 7414 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 19676 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d06/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 360610 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 1631629590423 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d06/testdata/input.txt: -------------------------------------------------------------------------------- 1 | 1,1,3,5,1,3,2,1,5,3,1,4,4,4,1,1,1,3,1,4,3,1,2,2,2,4,1,1,5,5,4,3,1,1,1,1,1,1,3,4,1,2,2,5,1,3,5,1,3,2,5,2,2,4,1,1,1,4,3,3,3,1,1,1,1,3,1,3,3,4,4,1,1,5,4,2,2,5,4,5,2,5,1,4,2,1,5,5,5,4,3,1,1,4,1,1,3,1,3,4,1,1,2,4,2,1,1,2,3,1,1,1,4,1,3,5,5,5,5,1,2,2,1,3,1,2,5,1,4,4,5,5,4,1,1,3,3,1,5,1,1,4,1,3,3,2,4,2,4,1,5,5,1,2,5,1,5,4,3,1,1,1,5,4,1,1,4,1,2,3,1,3,5,1,1,1,2,4,5,5,5,4,1,4,1,4,1,1,1,1,1,5,2,1,1,1,1,2,3,1,4,5,5,2,4,1,5,1,3,1,4,1,1,1,4,2,3,2,3,1,5,2,1,1,4,2,1,1,5,1,4,1,1,5,5,4,3,5,1,4,3,4,4,5,1,1,1,2,1,1,2,1,1,3,2,4,5,3,5,1,2,2,2,5,1,2,5,3,5,1,1,4,5,2,1,4,1,5,2,1,1,2,5,4,1,3,5,3,1,1,3,1,4,4,2,2,4,3,1,1 2 | -------------------------------------------------------------------------------- /y2021/d07/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 340987 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 96987874 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d08/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 409 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 1024649 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d09/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 452 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 1263735 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d10/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 367227 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 3583341858 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d11/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 1603 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 222 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d11/testdata/input.txt: -------------------------------------------------------------------------------- 1 | 4112256372 2 | 3143253712 3 | 4516848631 4 | 3783477137 5 | 3746723582 6 | 5861358884 7 | 4843351774 8 | 2316447621 9 | 6643817745 10 | 6366815868 11 | -------------------------------------------------------------------------------- /y2021/d12/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 3576 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 84271 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d12/testdata/input.txt: -------------------------------------------------------------------------------- 1 | ax-end 2 | xq-GF 3 | end-xq 4 | im-wg 5 | ax-ie 6 | start-ws 7 | ie-ws 8 | CV-start 9 | ng-wg 10 | ng-ie 11 | GF-ng 12 | ng-av 13 | CV-end 14 | ie-GF 15 | CV-ie 16 | im-xq 17 | start-GF 18 | GF-ws 19 | wg-LY 20 | CV-ws 21 | im-CV 22 | CV-wg 23 | -------------------------------------------------------------------------------- /y2021/d14/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 2891 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 4607749009683 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d14/testdata/input.txt: -------------------------------------------------------------------------------- 1 | OKSBBKHFBPVNOBKHBPCO 2 | 3 | CB -> P 4 | VH -> S 5 | CF -> P 6 | OV -> B 7 | CH -> N 8 | PB -> F 9 | KF -> O 10 | BC -> K 11 | FB -> F 12 | SN -> F 13 | FV -> B 14 | PN -> K 15 | SF -> V 16 | FN -> F 17 | SS -> K 18 | VP -> F 19 | VB -> B 20 | OS -> N 21 | HP -> O 22 | NF -> S 23 | SK -> H 24 | OO -> S 25 | PF -> C 26 | CC -> P 27 | BP -> F 28 | OB -> C 29 | CS -> N 30 | BV -> F 31 | VV -> B 32 | HO -> F 33 | KN -> P 34 | VC -> K 35 | KK -> N 36 | BO -> V 37 | NH -> O 38 | HC -> S 39 | SB -> F 40 | NN -> V 41 | OF -> V 42 | FK -> S 43 | OP -> S 44 | NS -> C 45 | HV -> O 46 | PC -> C 47 | FO -> H 48 | OH -> F 49 | BF -> S 50 | SO -> O 51 | HB -> P 52 | NK -> H 53 | NV -> C 54 | NB -> B 55 | FF -> B 56 | BH -> C 57 | SV -> B 58 | BK -> K 59 | NO -> C 60 | VN -> P 61 | FC -> B 62 | PH -> V 63 | HH -> C 64 | VO -> O 65 | SP -> P 66 | VK -> N 67 | CP -> H 68 | SC -> C 69 | KV -> H 70 | CO -> C 71 | OK -> V 72 | ON -> C 73 | KS -> S 74 | NP -> O 75 | CK -> C 76 | BS -> F 77 | VS -> B 78 | KH -> O 79 | KC -> C 80 | KB -> N 81 | OC -> F 82 | PP -> S 83 | HK -> H 84 | BN -> S 85 | KO -> K 86 | NC -> B 87 | PK -> K 88 | CV -> H 89 | PO -> O 90 | BB -> C 91 | HS -> F 92 | SH -> K 93 | CN -> S 94 | HN -> S 95 | KP -> O 96 | FP -> H 97 | HF -> F 98 | PS -> B 99 | FH -> K 100 | PV -> O 101 | FS -> N 102 | VF -> V 103 | -------------------------------------------------------------------------------- /y2021/d15/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 673 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 2893 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d16/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 847 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 333794664059 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d16/testdata/input.txt: -------------------------------------------------------------------------------- 1 | 005473C9244483004B001F79A9CE75FF9065446725685F1223600542661B7A9F4D001428C01D8C30C61210021F0663043A20042616C75868800BAC9CB59F4BC3A40232680220008542D89B114401886F1EA2DCF16CFE3BE6281060104B00C9994B83C13200AD3C0169B85FA7D3BE0A91356004824A32E6C94803A1D005E6701B2B49D76A1257EC7310C2015E7C0151006E0843F8D000086C4284910A47518CF7DD04380553C2F2D4BFEE67350DE2C9331FEFAFAD24CB282004F328C73F4E8B49C34AF094802B2B004E76762F9D9D8BA500653EEA4016CD802126B72D8F004C5F9975200C924B5065C00686467E58919F960C017F00466BB3B6B4B135D9DB5A5A93C2210050B32A9400A9497D524BEA660084EEA8EF600849E21EFB7C9F07E5C34C014C009067794BCC527794BCC424F12A67DCBC905C01B97BF8DE5ED9F7C865A4051F50024F9B9EAFA93ECE1A49A2C2E20128E4CA30037100042612C6F8B600084C1C8850BC400B8DAA01547197D6370BC8422C4A72051291E2A0803B0E2094D4BB5FDBEF6A0094F3CCC9A0002FD38E1350E7500C01A1006E3CC24884200C46389312C401F8551C63D4CC9D08035293FD6FCAFF1468B0056780A45D0C01498FBED0039925B82CCDCA7F4E20021A692CC012B00440010B8691761E0002190E21244C98EE0B0C0139297660B401A80002150E20A43C1006A0E44582A400C04A81CD994B9A1004BB1625D0648CE440E49DC402D8612BB6C9F5E97A5AC193F589A100505800ABCF5205138BD2EB527EA130008611167331AEA9B8BDCC4752B78165B39DAA1004C906740139EB0148D3CEC80662B801E60041015EE6006801364E007B801C003F1A801880350100BEC002A3000920E0079801CA00500046A800C0A001A73DFE9830059D29B5E8A51865777DCA1A2820040E4C7A49F88028B9F92DF80292E592B6B840 2 | -------------------------------------------------------------------------------- /y2021/d17/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 14535 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 2270 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d17/testdata/input.txt: -------------------------------------------------------------------------------- 1 | target area: x=60..94, y=-171..-136 2 | -------------------------------------------------------------------------------- /y2021/d18/decoder.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | ) 7 | 8 | type snailfishNumberDecoder struct { 9 | data []rune 10 | index int 11 | err error 12 | } 13 | 14 | func (decoder *snailfishNumberDecoder) read() rune { 15 | if decoder.err != nil { 16 | return 0 17 | } 18 | 19 | if decoder.index >= len(decoder.data) { 20 | decoder.err = errors.New("no more data to read") 21 | return 0 22 | } 23 | 24 | r := decoder.data[decoder.index] 25 | decoder.index++ 26 | 27 | return r 28 | } 29 | 30 | func (decoder *snailfishNumberDecoder) mustRead(r rune) { 31 | actual := decoder.read() 32 | if r != actual { 33 | decoder.err = fmt.Errorf("expected to read %q, got %q", r, actual) 34 | } 35 | } 36 | 37 | func (decoder *snailfishNumberDecoder) parse(number *snailfishNumber) { 38 | if decoder.err != nil { 39 | return 40 | } 41 | 42 | r := decoder.read() 43 | switch { 44 | case r == '[': 45 | number.leftChild = new(snailfishNumber) 46 | number.leftChild.parent = number 47 | decoder.parse(number.leftChild) 48 | 49 | decoder.mustRead(',') 50 | 51 | number.rightChild = new(snailfishNumber) 52 | number.rightChild.parent = number 53 | decoder.parse(number.rightChild) 54 | 55 | decoder.mustRead(']') 56 | case r >= '0' && r <= '9': 57 | number.value = int(r - '0') 58 | default: 59 | decoder.err = fmt.Errorf("unexpected character %q", r) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /y2021/d19/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 385 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 10707 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d20/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 5437 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 19340 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d21/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 855624 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 187451244607486 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d21/testdata/input.txt: -------------------------------------------------------------------------------- 1 | Player 1 starting position: 4 2 | Player 2 starting position: 10 3 | -------------------------------------------------------------------------------- /y2021/d22/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 652209 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 1217808640648260 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d23/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 14627 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 41591 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d23/testdata/input.txt: -------------------------------------------------------------------------------- 1 | ############# 2 | #...........# 3 | ###D#B#D#B### 4 | #C#A#A#C# 5 | ######### 6 | -------------------------------------------------------------------------------- /y2021/d24/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 96299896449997 25 | } 26 | 27 | func ExamplePartTwo() { 28 | file, err := os.Open("testdata/input.txt") 29 | if err != nil { 30 | log.Fatalf("could open input file: %v", err) 31 | } 32 | defer file.Close() 33 | 34 | if err := PartTwo(file, os.Stdout); err != nil { 35 | log.Fatalf("could not solve: %v", err) 36 | } 37 | // This function is a unit test. It makes sure that your solution produces 38 | // the answer written below, after "Output: ". 39 | 40 | // Output: 31162141116841 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2021/d25/solution_test.go: -------------------------------------------------------------------------------- 1 | package busser 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // This function is a unit test. It makes sure that your solution produces 22 | // the answer written below, after "Output: ". 23 | 24 | // Output: 426 25 | } 26 | 27 | func Benchmark(b *testing.B) { 28 | testCases := map[string]struct { 29 | solution helpers.Solution 30 | inputFile string 31 | }{ 32 | "PartOne": { 33 | solution: helpers.SolutionFunc(PartOne), 34 | inputFile: "testdata/input.txt", 35 | }, 36 | } 37 | 38 | for name, test := range testCases { 39 | b.Run(name, func(b *testing.B) { 40 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 41 | }) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /y2022/d01/solution_test.go: -------------------------------------------------------------------------------- 1 | package d01 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 67027 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 197291 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d02/solution_test.go: -------------------------------------------------------------------------------- 1 | package d02 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 12740 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 11980 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d03/solution_test.go: -------------------------------------------------------------------------------- 1 | package d03 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 7793 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 2499 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d04/solution_test.go: -------------------------------------------------------------------------------- 1 | package d04 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 582 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 893 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d05/solution_test.go: -------------------------------------------------------------------------------- 1 | package d05 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: FCVRLMVQP 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: RWLWGJGFD 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d06/solution_test.go: -------------------------------------------------------------------------------- 1 | package d06 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 1640 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 3613 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d06/solution_xor_test.go: -------------------------------------------------------------------------------- 1 | package d06 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOneXOR() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOneXOR(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 1640 22 | } 23 | 24 | func ExamplePartTwoXOR() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwoXOR(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 3613 35 | } 36 | 37 | func BenchmarkXOR(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOneXOR), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwoXOR), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d07/solution_test.go: -------------------------------------------------------------------------------- 1 | package d07 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 1844187 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 4978279 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d08/solution_test.go: -------------------------------------------------------------------------------- 1 | package d08 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 1690 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 535680 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d09/solution_test.go: -------------------------------------------------------------------------------- 1 | package d09 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 5902 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 2445 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d10/solution_test.go: -------------------------------------------------------------------------------- 1 | package d10 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 15140 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 35 | // ###..###....##..##..####..##...##..###.. 36 | // #..#.#..#....#.#..#....#.#..#.#..#.#..#. 37 | // ###..#..#....#.#..#...#..#....#..#.#..#. 38 | // #..#.###.....#.####..#...#.##.####.###.. 39 | // #..#.#....#..#.#..#.#....#..#.#..#.#.... 40 | // ###..#.....##..#..#.####..###.#..#.#.... 41 | } 42 | 43 | func Benchmark(b *testing.B) { 44 | testCases := map[string]struct { 45 | solution helpers.Solution 46 | inputFile string 47 | }{ 48 | "PartOne": { 49 | solution: helpers.SolutionFunc(PartOne), 50 | inputFile: "testdata/input.txt", 51 | }, 52 | 53 | "PartTwo": { 54 | solution: helpers.SolutionFunc(PartTwo), 55 | inputFile: "testdata/input.txt", 56 | }, 57 | } 58 | 59 | for name, test := range testCases { 60 | b.Run(name, func(b *testing.B) { 61 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2022/d11/solution_test.go: -------------------------------------------------------------------------------- 1 | package d11 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 182293 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 54832778815 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d11/testdata/input.txt: -------------------------------------------------------------------------------- 1 | Monkey 0: 2 | Starting items: 76, 88, 96, 97, 58, 61, 67 3 | Operation: new = old * 19 4 | Test: divisible by 3 5 | If true: throw to monkey 2 6 | If false: throw to monkey 3 7 | 8 | Monkey 1: 9 | Starting items: 93, 71, 79, 83, 69, 70, 94, 98 10 | Operation: new = old + 8 11 | Test: divisible by 11 12 | If true: throw to monkey 5 13 | If false: throw to monkey 6 14 | 15 | Monkey 2: 16 | Starting items: 50, 74, 67, 92, 61, 76 17 | Operation: new = old * 13 18 | Test: divisible by 19 19 | If true: throw to monkey 3 20 | If false: throw to monkey 1 21 | 22 | Monkey 3: 23 | Starting items: 76, 92 24 | Operation: new = old + 6 25 | Test: divisible by 5 26 | If true: throw to monkey 1 27 | If false: throw to monkey 6 28 | 29 | Monkey 4: 30 | Starting items: 74, 94, 55, 87, 62 31 | Operation: new = old + 5 32 | Test: divisible by 2 33 | If true: throw to monkey 2 34 | If false: throw to monkey 0 35 | 36 | Monkey 5: 37 | Starting items: 59, 62, 53, 62 38 | Operation: new = old * old 39 | Test: divisible by 7 40 | If true: throw to monkey 4 41 | If false: throw to monkey 7 42 | 43 | Monkey 6: 44 | Starting items: 62 45 | Operation: new = old + 2 46 | Test: divisible by 17 47 | If true: throw to monkey 5 48 | If false: throw to monkey 7 49 | 50 | Monkey 7: 51 | Starting items: 85, 54, 53 52 | Operation: new = old + 3 53 | Test: divisible by 13 54 | If true: throw to monkey 4 55 | If false: throw to monkey 0 56 | -------------------------------------------------------------------------------- /y2022/d12/solution_test.go: -------------------------------------------------------------------------------- 1 | package d12 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 534 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 525 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d13/solution_test.go: -------------------------------------------------------------------------------- 1 | package d13 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 5623 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 20570 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d14/solution_test.go: -------------------------------------------------------------------------------- 1 | package d14 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 692 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 31706 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d15/solution_test.go: -------------------------------------------------------------------------------- 1 | package d15 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 6425133 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 10996191429555 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d16/solution_test.go: -------------------------------------------------------------------------------- 1 | package d16 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 1617 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 2171 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d17/solution_test.go: -------------------------------------------------------------------------------- 1 | package d17 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 3215 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 1575811209487 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d18/solution_test.go: -------------------------------------------------------------------------------- 1 | package d18 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 3522 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 2074 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d19/solution_test.go: -------------------------------------------------------------------------------- 1 | package d19 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 1766 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 30780 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/example.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d20/solution_test.go: -------------------------------------------------------------------------------- 1 | package d20 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 4914 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 7973051839072 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d21/solution_test.go: -------------------------------------------------------------------------------- 1 | package d21 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 379578518396784 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 3353687996514 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d23/solution_test.go: -------------------------------------------------------------------------------- 1 | package d23 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 3862 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 913 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d24/solution_test.go: -------------------------------------------------------------------------------- 1 | package d24 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 262 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 785 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/d25/slices/slices.go: -------------------------------------------------------------------------------- 1 | package slices 2 | 3 | // Contains reports whether v is within s. 4 | func Contains[T comparable](s []T, v T) bool { 5 | return Index(s, v) >= 0 6 | } 7 | 8 | // Index returns the index of the first instance of v in s, or -1 if v is not 9 | // present in s. 10 | func Index[T comparable](s []T, v T) int { 11 | for i := range s { 12 | if s[i] == v { 13 | return i 14 | } 15 | } 16 | return -1 17 | } 18 | 19 | // Reverse reorders the elements of s in place so that any two elements of s 20 | // that were previously in a certain order are now in the opposite order. 21 | func Reverse[T any](s []T) { 22 | for i := 0; i < len(s)/2; i++ { 23 | s[i], s[len(s)-1-i] = s[len(s)-1-i], s[i] 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /y2022/d25/solution_test.go: -------------------------------------------------------------------------------- 1 | package d25 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 2-21=02=1-121-2-11-0 22 | } 23 | 24 | func Benchmark(b *testing.B) { 25 | testCases := map[string]struct { 26 | solution helpers.Solution 27 | inputFile string 28 | }{ 29 | "PartOne": { 30 | solution: helpers.SolutionFunc(PartOne), 31 | inputFile: "testdata/input.txt", 32 | }, 33 | } 34 | 35 | for name, test := range testCases { 36 | b.Run(name, func(b *testing.B) { 37 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 38 | }) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /y2023/d01/solution_test.go: -------------------------------------------------------------------------------- 1 | package d01 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 54338 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 53389 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d02/solution_test.go: -------------------------------------------------------------------------------- 1 | package d02 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 3059 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 65371 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d03/solution_test.go: -------------------------------------------------------------------------------- 1 | package d03 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 532445 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 79842967 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d04/solution_test.go: -------------------------------------------------------------------------------- 1 | package d04 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 27845 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 9496801 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d06/testdata/input.txt: -------------------------------------------------------------------------------- 1 | Time: 35 69 68 87 2 | Distance: 213 1168 1086 1248 3 | -------------------------------------------------------------------------------- /y2023/d07/solution_test.go: -------------------------------------------------------------------------------- 1 | package d07 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 250347426 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 251224870 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d08/solution_test.go: -------------------------------------------------------------------------------- 1 | package d08 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 21251 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 11678319315857 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d09/solution_test.go: -------------------------------------------------------------------------------- 1 | package d09 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 2175229206 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 942 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d10/solution_test.go: -------------------------------------------------------------------------------- 1 | package d10 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 6757 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 523 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d11/solution_test.go: -------------------------------------------------------------------------------- 1 | package d11 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 10494813 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 840988812853 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d12/solution_test.go: -------------------------------------------------------------------------------- 1 | package d12 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 7843 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 10153896718999 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d13/solution_test.go: -------------------------------------------------------------------------------- 1 | package d13 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 35521 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 34795 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d14/solution_test.go: -------------------------------------------------------------------------------- 1 | package d14 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 105623 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 98029 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d15/solution_test.go: -------------------------------------------------------------------------------- 1 | package d15 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 512950 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 247153 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d16/solution_test.go: -------------------------------------------------------------------------------- 1 | package d16 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 6361 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 6701 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d17/solution_test.go: -------------------------------------------------------------------------------- 1 | package d17 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 1076 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 1219 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d18/solution_test.go: -------------------------------------------------------------------------------- 1 | package d18 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 47139 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 173152345887206 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d19/solution_test.go: -------------------------------------------------------------------------------- 1 | package d19 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 374873 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 122112157518711 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d20/solution_test.go: -------------------------------------------------------------------------------- 1 | package d20 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 898731036 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 229414480926893 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d20/testdata/input.txt: -------------------------------------------------------------------------------- 1 | %vh -> qc, rr 2 | &pb -> gf, gv, vp, qb, vr, hq, zj 3 | %zj -> kn, pb 4 | %mm -> dj 5 | %gp -> cp 6 | &dc -> ns 7 | %qc -> gp 8 | %dx -> fq, dj 9 | %tg -> nl, ks 10 | %pr -> nl 11 | %gx -> xf 12 | %hd -> lt, nl 13 | %dq -> dj, jc 14 | %ht -> jv 15 | %bs -> pb, rd 16 | &nl -> ks, cq, tc, xf, gx, hd, lt 17 | &dj -> dc, fq, jz, ht, zs, jc 18 | &rr -> gp, rv, jt, qc, sq 19 | %vr -> qb 20 | %jz -> dj, ht 21 | %hq -> nx 22 | %cf -> jg, rr 23 | %hj -> cf, rr 24 | %mt -> rr 25 | %sq -> rr, vh 26 | %jg -> rr, pd 27 | %gf -> gv 28 | %xv -> dj, dx 29 | %rh -> nl, gx 30 | broadcaster -> hd, zj, sq, jz 31 | %jv -> dj, zs 32 | %rd -> vs, pb 33 | %pd -> rr, mt 34 | &rv -> ns 35 | &vp -> ns 36 | %vs -> pb 37 | %nx -> pb, bs 38 | %zp -> mm, dj 39 | &ns -> rx 40 | %lt -> rh 41 | %pf -> pr, nl 42 | %tc -> qz 43 | %xz -> dj, zp 44 | %qb -> hq 45 | %rl -> pf, nl 46 | %fq -> xz 47 | %kn -> pb, xn 48 | %xf -> tg 49 | %qz -> nl, rl 50 | %ks -> tc 51 | %jt -> kb 52 | %jc -> xv 53 | %kb -> hj, rr 54 | %zs -> dq 55 | %gv -> vr 56 | &cq -> ns 57 | %cp -> rr, jt 58 | %xn -> pb, gf 59 | -------------------------------------------------------------------------------- /y2023/d21/solution_test.go: -------------------------------------------------------------------------------- 1 | package d21 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 3709 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 617361073602319 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d22/solution_test.go: -------------------------------------------------------------------------------- 1 | package d22 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 437 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 42561 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d23/solution_test.go: -------------------------------------------------------------------------------- 1 | package d23 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 2186 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 6802 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d24/solution_test.go: -------------------------------------------------------------------------------- 1 | package d24 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 24627 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 527310134398221 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/d25/solution_test.go: -------------------------------------------------------------------------------- 1 | package d25 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 554064 22 | } 23 | 24 | func Benchmark(b *testing.B) { 25 | testCases := map[string]struct { 26 | solution helpers.Solution 27 | inputFile string 28 | }{ 29 | "PartOne": { 30 | solution: helpers.SolutionFunc(PartOne), 31 | inputFile: "testdata/input.txt", 32 | }, 33 | } 34 | 35 | for name, test := range testCases { 36 | b.Run(name, func(b *testing.B) { 37 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 38 | }) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /y2024/d01/solution_test.go: -------------------------------------------------------------------------------- 1 | package d01 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 1506483 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 23126924 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d02/solution_test.go: -------------------------------------------------------------------------------- 1 | package d02 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 334 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 400 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d03/solution_test.go: -------------------------------------------------------------------------------- 1 | package d03 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 178538786 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 102467299 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d04/solution_test.go: -------------------------------------------------------------------------------- 1 | package d04 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 2500 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 1933 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d05/solution_test.go: -------------------------------------------------------------------------------- 1 | package d05 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 5955 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 4030 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d06/solution_test.go: -------------------------------------------------------------------------------- 1 | package d06 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 4663 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 1530 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d07/solution_test.go: -------------------------------------------------------------------------------- 1 | package d07 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 20281182715321 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 👉 Write the answer here 👈 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d08/solution_test.go: -------------------------------------------------------------------------------- 1 | package d08 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 318 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 1126 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d09/solution_test.go: -------------------------------------------------------------------------------- 1 | package d09 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 6301895872542 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 6323761685944 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d10/solution_test.go: -------------------------------------------------------------------------------- 1 | package d10 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 548 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 1252 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d11/solution_test.go: -------------------------------------------------------------------------------- 1 | package d11 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 186175 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 220566831337810 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d11/testdata/input.txt: -------------------------------------------------------------------------------- 1 | 5688 62084 2 3248809 179 79 0 172169 2 | -------------------------------------------------------------------------------- /y2024/d12/solution_test.go: -------------------------------------------------------------------------------- 1 | package d12 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 1488414 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 911750 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d13/solution_test.go: -------------------------------------------------------------------------------- 1 | package d13 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 39290 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 73458657399094 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d14/solution_test.go: -------------------------------------------------------------------------------- 1 | package d14 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 225648864 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 7847 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d15/solution_test.go: -------------------------------------------------------------------------------- 1 | package d15 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 1476771 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 1468005 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d16/solution_test.go: -------------------------------------------------------------------------------- 1 | package d16 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 123540 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 665 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d17/solution_test.go: -------------------------------------------------------------------------------- 1 | package d17 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 1,0,2,0,5,7,2,1,3 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 265652340990875 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d17/testdata/input.txt: -------------------------------------------------------------------------------- 1 | Register A: 64012472 2 | Register B: 0 3 | Register C: 0 4 | 5 | Program: 2,4,1,7,7,5,0,3,1,7,4,1,5,5,3,0 6 | -------------------------------------------------------------------------------- /y2024/d18/solution_test.go: -------------------------------------------------------------------------------- 1 | package d18 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 252 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 5,60 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d19/solution_test.go: -------------------------------------------------------------------------------- 1 | package d19 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 369 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 761826581538190 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d20/solution_test.go: -------------------------------------------------------------------------------- 1 | package d20 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 1351 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 966130 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d21/solution_test.go: -------------------------------------------------------------------------------- 1 | package d21 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 132532 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 165644591859332 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d21/testdata/input.txt: -------------------------------------------------------------------------------- 1 | 341A 2 | 480A 3 | 286A 4 | 579A 5 | 149A 6 | -------------------------------------------------------------------------------- /y2024/d22/solution_test.go: -------------------------------------------------------------------------------- 1 | package d22 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 14119253575 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: 1600 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2024/d23/solution_test.go: -------------------------------------------------------------------------------- 1 | package d23 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | 8 | "github.com/busser/adventofcode/helpers" 9 | ) 10 | 11 | func ExamplePartOne() { 12 | file, err := os.Open("testdata/input.txt") 13 | if err != nil { 14 | log.Fatalf("could not open input file: %v", err) 15 | } 16 | defer file.Close() 17 | 18 | if err := PartOne(file, os.Stdout); err != nil { 19 | log.Fatalf("could not solve: %v", err) 20 | } 21 | // Output: 1248 22 | } 23 | 24 | func ExamplePartTwo() { 25 | file, err := os.Open("testdata/input.txt") 26 | if err != nil { 27 | log.Fatalf("could open input file: %v", err) 28 | } 29 | defer file.Close() 30 | 31 | if err := PartTwo(file, os.Stdout); err != nil { 32 | log.Fatalf("could not solve: %v", err) 33 | } 34 | // Output: aa,cf,cj,cv,dr,gj,iu,jh,oy,qr,xr,xy,zb 35 | } 36 | 37 | func Benchmark(b *testing.B) { 38 | testCases := map[string]struct { 39 | solution helpers.Solution 40 | inputFile string 41 | }{ 42 | "PartOne": { 43 | solution: helpers.SolutionFunc(PartOne), 44 | inputFile: "testdata/input.txt", 45 | }, 46 | 47 | "PartTwo": { 48 | solution: helpers.SolutionFunc(PartTwo), 49 | inputFile: "testdata/input.txt", 50 | }, 51 | } 52 | 53 | for name, test := range testCases { 54 | b.Run(name, func(b *testing.B) { 55 | helpers.BenchmarkSolution(b, test.solution, test.inputFile) 56 | }) 57 | } 58 | } 59 | --------------------------------------------------------------------------------