2020-12-06 16:34:20 +01:00
|
|
|
#!/usr/bin/bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")/2020"
|
|
|
|
|
|
|
|
run_solution() {
|
|
|
|
if [ -d "$solution" ]; then
|
|
|
|
runfile=$solution/run.sh
|
2020-12-10 16:28:50 +01:00
|
|
|
[ -f "$runfile" ] || { echo "Error: $runfile not found" >&2; exit 1; }
|
2020-12-06 16:34:20 +01:00
|
|
|
"$runfile" "$input"
|
|
|
|
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-10 19:20:56 +01:00
|
|
|
shopt -s dotglob
|
|
|
|
|
2020-12-06 16:34:20 +01:00
|
|
|
for day in day*; do
|
|
|
|
input=data/$day.input
|
|
|
|
expected=data/$day.expected
|
|
|
|
for solution in "$day"/*; do
|
|
|
|
echo -n "$solution... "
|
2020-12-10 19:20:56 +01:00
|
|
|
|
|
|
|
case "${solution##*/}" in
|
|
|
|
example.txt|.*)
|
|
|
|
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
|