2020-12-06 16:34:20 +01:00
|
|
|
#!/usr/bin/bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
|
|
|
|
|
|
|
YEAR=2020
|
|
|
|
|
|
|
|
run_solution() {
|
|
|
|
if [ -d "$solution" ]; then
|
2021-12-01 09:18:38 +01:00
|
|
|
if [ -f "$solution/Cargo.toml" ]; then
|
|
|
|
cargo run --quiet --manifest-path "$solution/Cargo.toml" < "$input"
|
|
|
|
else
|
|
|
|
runfile=$solution/run.sh
|
|
|
|
[ -f "$runfile" ] || { echo "Error: $runfile not found" >&2; exit 1; }
|
|
|
|
"$runfile" "$input"
|
|
|
|
fi
|
2020-12-06 16:34:20 +01:00
|
|
|
else
|
|
|
|
case "$(basename "$solution")" in
|
|
|
|
*.hs)
|
|
|
|
runhaskell -icommon "$solution" < "$input"
|
|
|
|
;;
|
|
|
|
*.py)
|
|
|
|
python "$solution" < "$input"
|
|
|
|
;;
|
|
|
|
*)
|
2020-12-10 16:28:50 +01:00
|
|
|
echo "Error: Unknown solution type: $solution" >&2
|
2020-12-06 16:34:20 +01:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-12-11 21:20:23 +01:00
|
|
|
shopt -s dotglob nullglob
|
2020-12-10 19:20:56 +01:00
|
|
|
|
2020-12-06 16:34:20 +01:00
|
|
|
for n in $(seq 1 25); do
|
|
|
|
input=$YEAR/data/day$n.input
|
|
|
|
expected=$YEAR/data/day$n.expected
|
|
|
|
|
|
|
|
for solution in "$YEAR/day$n"/*; do
|
|
|
|
echo -n "$solution... "
|
|
|
|
|
2020-12-10 19:20:56 +01:00
|
|
|
case "${solution##*/}" in
|
2020-12-13 18:15:17 +01:00
|
|
|
example*)
|
2020-12-10 19:20:56 +01:00
|
|
|
echo SKIP
|
|
|
|
continue
|
|
|
|
esac
|
|
|
|
|
2020-12-06 16:34:20 +01:00
|
|
|
solution_output=$(mktemp)
|
2020-12-10 19:20:41 +01:00
|
|
|
trap "rm -f '$solution_output'" EXIT
|
2020-12-06 16:34:20 +01:00
|
|
|
|
|
|
|
run_solution "$solution" > "$solution_output"
|
|
|
|
|
|
|
|
if ! diff -u "$expected" "$solution_output"; then
|
|
|
|
echo FAIL
|
|
|
|
rv=$?
|
|
|
|
case "$rv" in
|
|
|
|
1)
|
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
echo ok
|
|
|
|
fi
|
2020-12-10 19:20:41 +01:00
|
|
|
|
|
|
|
rm "$solution_output"
|
2020-12-06 16:34:20 +01:00
|
|
|
done
|
|
|
|
done
|