2020-10-27 13:19:38 -06:00
|
|
|
#! /bin/sh
|
|
|
|
|
2020-10-27 14:13:05 -06:00
|
|
|
# This `mkcategory` merges subdirectories of puzzles together,
|
|
|
|
# in a dumb way that will break if you have the same point value in two directories.
|
|
|
|
# It also makes each puzzle show up a second time, worth 100 points more,
|
|
|
|
# to show off what `mkcategory` can do without me having to write more code.
|
|
|
|
|
2020-10-27 13:19:38 -06:00
|
|
|
fail () {
|
|
|
|
echo "ERROR: $*" 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
inventory)
|
|
|
|
printf '{"Puzzles":['
|
|
|
|
ls -d */[0-9]* | while read p; do
|
|
|
|
puzzle=${p##*/}
|
|
|
|
printf "%s%d,10%d" "$comma" "$puzzle" "$puzzle"
|
|
|
|
comma=,
|
|
|
|
done
|
|
|
|
printf ']}'
|
|
|
|
;;
|
|
|
|
puzzle)
|
|
|
|
points=$(($2 % 100))
|
|
|
|
transpile puzzle -dir */$points
|
|
|
|
;;
|
|
|
|
file)
|
|
|
|
points=$(($2 % 100))
|
|
|
|
transpile file -dir */$points "$3"
|
|
|
|
;;
|
|
|
|
answer)
|
|
|
|
points=$(($2 % 100))
|
|
|
|
transpile answer -dir */$points -answer="$3"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
fail "What is $1" 1>&2
|
|
|
|
;;
|
|
|
|
esac
|