feat: add a script for running the solutions
This commit is contained in:
parent
86fd297d5b
commit
52bb3d64e1
2 changed files with 92 additions and 1 deletions
|
@ -1,8 +1,37 @@
|
|||
= Advent of Code
|
||||
|
||||
My solutions to the https://adventofcode.com[Advent of Code] challenges.
|
||||
My solutions to the https://adventofcode.com[Advent of Code] challenges in Go.
|
||||
|
||||
== Mirrors
|
||||
|
||||
- **Code Flow (Forgejo)**: https://codeflow.dananglin.me.uk/apollo/advent-of-code
|
||||
- **GitHub**: https://github.com/dananglin/advent-of-code
|
||||
|
||||
== How to run the solutions
|
||||
|
||||
1. Download and install Go if you don't have it installed already.
|
||||
|
||||
2. The provided bash script can be used to run the solution to an AoC challenge.
|
||||
+
|
||||
....
|
||||
$ ./solve --help
|
||||
USAGE:
|
||||
./solve [options]
|
||||
|
||||
SUMMARY:
|
||||
Run the solution for the specified Advent of Code challenge
|
||||
|
||||
OPTIONS:
|
||||
-h, --help:
|
||||
print this help message
|
||||
|
||||
-y, --year:
|
||||
specify the year
|
||||
|
||||
-d, --day:
|
||||
specify the day of the advent calendar
|
||||
....
|
||||
|
||||
3. Run the script specifying the year and the day of the advent calendar to view the result of that day's challenge.
|
||||
|
||||
./solve --year 2023 --day 1
|
||||
|
|
62
solve
Executable file
62
solve
Executable file
|
@ -0,0 +1,62 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
function usage {
|
||||
echo "USAGE:"
|
||||
echo " $0 [options]"
|
||||
echo ""
|
||||
echo "SUMMARY:"
|
||||
echo " Run the solution for the specified Advent of Code challenge"
|
||||
echo ""
|
||||
echo "OPTIONS:"
|
||||
echo " -h, --help:"
|
||||
echo " print this help message"
|
||||
echo ""
|
||||
echo " -y, --year:"
|
||||
echo " specify the year"
|
||||
echo ""
|
||||
echo " -d, --day:"
|
||||
echo " specify the day of the advent calendar"
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
arg="$1"
|
||||
case $arg in
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
-y|--year)
|
||||
YEAR=$2
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
-d|--day)
|
||||
DAY=$2
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "${YEAR+x}" ]]; then
|
||||
echo "ERROR: please specify the year."
|
||||
echo ""
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "${DAY+x}" ]]; then
|
||||
echo "ERROR: please specify the day."
|
||||
echo ""
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
go run "./${YEAR}/day-${DAY}"
|
Loading…
Reference in a new issue