Skip to content

Commit

Permalink
Add script to run puzzle
Browse files Browse the repository at this point in the history
  • Loading branch information
alexg-axis committed Nov 24, 2021
1 parent 0f0e3b1 commit 85ff612
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ login:
# initialize today's puzzle
init:
./scripts/init.sh

# run today's puzzle
run:
./scripts/run.sh
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
38 changes: 38 additions & 0 deletions scripts/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

set -e

export PATH="/usr/local/opt/[email protected]/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

0 comments on commit 85ff612

Please sign in to comment.