Dominoes on Acid Code
Brought to you by:
mbenkmann
#!/bin/sh
if [ $# != 1 ]; then
echo 'USAGE: solve_levels <infile>'
exit 1
fi
prove="java domino.logic.Prove"
convert_to_secs()
{
mins=${1%%m*}
secs=${1%%.*}
secs=${secs##*m}
echo $(($mins*60+$secs))
}
{
while read -r; do
formula="${REPLY##*:}"
comment="${REPLY%:*}"
if [ "$formula" == "$comment" ]; then comment=""; fi
formula_no_ws="$(echo ${formula}|tr -d $' \t')"
echo 1>&2 "Trying $REPLY"
if [ -z "$formula_no_ws" ]; then
echo "FAILED: $REPLY"
else
proof="$(sh -c "time $prove '$formula_no_ws'" 2>&1)"
dif="$(echo "$proof" | sed -n 's/^Difficulty: \([0-9]*\).*/\1/p' )"
time="$(echo "$proof" |sed -n $'s/^user[ \t]*\\([^ \t]*\\).*/\\1/p')"
time="$(convert_to_secs $time)"
if [ z${dif} != z ]; then
echo "SUCCESS(difficulty ${dif}, time ${time}): $REPLY"
else
echo "FAILED: $REPLY"
echo "$proof" | sed 's/^\(.\)/ \1/'
fi
fi
done
} <"$1"