#!/usr/bin/env bash
RES=$1
ITERS=$2
SEED=$RANDOM
echo "Using random seed $SEED"
# g++ -O2 -Wall output_validators/validator.cpp -o val
mkfifo pipe1 2>/dev/null
mkfifo pipe2 2>/dev/null
> lines
for (( A=1; A<=$ITERS; A++ ))
do
	./a.out >pipe1 <pipe2 &
	# python3 submissions/accepted/per_faster.py >pipe1 <pipe2 &
	./val <pipe1 >pipe2 <(echo $RES ${SEED}123$A) 2>>lines &
	wait 2>/dev/null
	tail -n1 lines
done
python3 -c '
import sys
errs = [float(line.split()[-1][:-2]) for line in sys.stdin]
errs = [e if e > 0 else 100*(1/(1+e/100)-1) for e in errs]
print("avg error {:.4}%, max error {:.4}%".format(sum(errs) / len(errs), max(errs)))' < lines
rm lines
