diff --git a/Makefile b/Makefile index 584174b..07070e8 100644 --- a/Makefile +++ b/Makefile @@ -7,3 +7,7 @@ login: # initialize today's puzzle init: ./scripts/init.sh + +# run today's puzzle +run: + ./scripts/run.sh diff --git a/README.md b/README.md index 57eeb02..aa7771b 100644 --- a/README.md +++ b/README.md @@ -26,3 +26,5 @@ The structure is generic enough, but built for macOS (although that specific log 2. To login using a session cookie from the Advent of Code website, run `make login` 3. To initialize today's puzzle run `make init` * To initialize a specific puzzle, run `AOC_YEAR=2020 AOC_MONTH=12 AOC_DAY=24 make init` +4. To run today's puzzle run `make run` + * To run a specific puzzle, run `AOC_YEAR=2020 AOC_MONTH=12 AOC_DAY=24 make run` diff --git a/scripts/run.sh b/scripts/run.sh new file mode 100755 index 0000000..e55098e --- /dev/null +++ b/scripts/run.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +set -e + +export PATH="/usr/local/opt/python@3.10/bin:$PATH" + +year="${AOC_YEAR:-$(date +%Y)}" +month="${AOC_MONTH:-$(date +%m)}" +day="${AOC_DAY:-$(date +%d)}" + +if [[ ! "$month" -eq 12 ]]; then + echo "It's not december quite yet. If you wish to run a previous puzzle" + echo "specify AOC_YEAR, AOC_MONTH and AOC_DAY" + exit 1 +fi + +if [[ ! -d "$year/$day" ]]; then + echo "Cannot find a puzzle in $year/$day. Have you forgot to initialize it?" + exit 1 +fi + +main_files="$(find "$year/$day" -depth 1 -iname "main*")" +for file in $main_files; do + name="$(basename "$file")" + case "${name##*.}" in + "go") + go run "$file" + ;; + "ts") + NO_COLOR=1 deno run --quiet --allow-read "$file" + ;; + "py") + python3 "$file" + ;; + *) + echo "unsupported $file" + esac +done