55 lines
1.1 KiB
Bash
Executable File
55 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euf -o pipefail
|
|
|
|
# functions
|
|
function template() {
|
|
cat <<EOF
|
|
package main
|
|
|
|
import (
|
|
"github.com/jpillora/puzzler/harness/aoc"
|
|
)
|
|
|
|
func main() {
|
|
aoc.Harness(run)
|
|
}
|
|
|
|
// on code change, run will be executed 4 times:
|
|
// 1. with: false (part1), and example input
|
|
// 2. with: true (part2), and example input
|
|
// 3. with: false (part1), and user input
|
|
// 4. with: true (part2), and user input
|
|
// the return value of each run is printed to stdout
|
|
func run(part2 bool, input string) any {
|
|
// when you're ready to do part 2, remove this "not implemented" block
|
|
if part2 {
|
|
return "not implemented"
|
|
}
|
|
// solve part 1 here
|
|
return 42
|
|
}
|
|
EOF
|
|
}
|
|
|
|
# two args YEAR and DAY
|
|
YEAR="${1:-}"
|
|
DAY="${2:-}"
|
|
if [ -z "$YEAR" ] || [ -z "$DAY" ]; then
|
|
echo "Usage: $0 <YEAR> <DAY>"
|
|
exit 1
|
|
fi
|
|
# pad DAY to 2 digits
|
|
DAY=$(printf "%02d" $DAY)
|
|
DIR="./$YEAR/$DAY"
|
|
# create missing files as needed
|
|
if [ ! -d "$DIR" ]; then
|
|
mkdir -p "$DIR"
|
|
echo "[run.sh] created $DIR"
|
|
fi
|
|
if [ ! -f "$DIR/code.go" ]; then
|
|
template >"$DIR/code.go"
|
|
echo "[run.sh] created $DIR/code.go"
|
|
fi
|
|
# go run
|
|
cd "$DIR" && go run code.go
|