#!/usr/bin/env bash name=day-"$1" if [ -d day-"$name" ]; then echo "program $name already exists" exit 1 fi mkdir -p "$name"/cmd/cli/testdata \ "$name"/testdata "$name"/internal/one/testdata "$name"/internal/two/testdata touch "$name"/makefile cat <> "$name"/makefile program = $name GO = go SRC_DIR := src BIN_DIR := bin EXE := \$(BIN_DIR)/\$(program) .DEFAULT_GOAL := build .PHONY: fmt vet build bench clean fmt: \$(GO) fmt ./... vet: fmt \$(GO) vet ./... build: vet | \$(BIN_DIR) \$(GO) build -o \$(EXE) ./\$(SRC_DIR) bench: \$(GO) test ./internal/one/ -bench=. > internal/one/benchmark \$(GO) test ./internal/two/ -bench=. > internal/two/benchmark \$(GO) test . -count=10 -bench=. > benchmark \$(BIN_DIR): @mkdir -p \$@ clean: @rm -rv \$(BIN_DIR) EOT cat <> "$name"/cmd/cli/main.go /******************************************************************************** Advent of Code 2024 - $name ********************************************************************************/ package main func main() { } EOT touch "$name"/solve.go cat <> "$name"/solve.go package name import ( "github.com/onyx-and-iris/aoc2024/day-$1/internal/one" "github.com/onyx-and-iris/aoc2024/day-$1/internal/two" ) func Solve(buf []byte) (int, int, error) { answerOne, err := one.Solve(buf) if err != nil { return 0, 0, err } answerTwo, err := two.Solve(buf) if err != nil { return 0, 0, err } return answerOne, answerTwo, nil } EOT touch "$name"/internal/one/solve.go cat <> "$name"/internal/one/solve.go package one import ( "bufio" "bytes" "io" ) func Solve(buf []byte) (int, error) { r := bytes.NewReader(buf) err := parseLines(r) if err != nil { return 0, err } return 0, nil } func parseLines(r io.Reader) error { scanner := bufio.NewScanner(r) for scanner.Scan() { } if err := scanner.Err(); err != nil { return err } return nil } EOT touch "$name"/internal/one/solve_internal_test.go cat <> "$name"/internal/one/solve_internal_test.go package one import ( _ "embed" "os" "testing" ) //go:embed testdata/input.txt var data []byte func BenchmarkSolve(b *testing.B) { os.Stdout, _ = os.Open(os.DevNull) Solve(data) } EOT touch "$name"/internal/two/solve.go cat <> "$name"/internal/two/solve.go package two import ( "bufio" "bytes" "io" ) func Solve(buf []byte) (int, error) { r := bytes.NewReader(buf) err := parseLines(r) if err != nil { return 0, err } return 0, nil } func parseLines(r io.Reader) error { scanner := bufio.NewScanner(r) for scanner.Scan() { } if err := scanner.Err(); err != nil { return err } return nil } EOT touch "$name"/internal/two/solve_internal_test.go cat <> "$name"/internal/two/solve_internal_test.go package two import ( _ "embed" "os" "testing" ) //go:embed testdata/input.txt var data []byte func BenchmarkSolve(b *testing.B) { os.Stdout, _ = os.Open(os.DevNull) Solve(data) } EOT cd "$name" || exit go mod init github.com/onyx-and-iris/aoc2024/"$name" MKFILES=../mkfiles.sh [[ -f $MKFILES ]] && ln -s $MKFILES .