Interactive problems in competitive programming often require manual interaction to test the correctness of the solution. While writing the checker program is usually straightforward, connecting the checker program with the solution program can be challenging. This blog post introduces a simple Linux terminal setup that makes this connection easy, eliminating the need for manual input during testing.↵
↵
↵
There are other solutions to this, the one over [here](https://codeforces.me/blog/entry/49490) uses croupier(a python program) to make the two interact. ↵
↵
Simplifying the Connection with Linux Terminal:↵
The Linux terminal provides powerful tools to simplify the testing process for interactive problems. By leveraging a bash script and named pipes, you can effortlessly connect the solution program with the checker program. Here's a script to do so:↵
↵
~~~~~↵
sol=$1↵
checker=$2↵
↵
mkfifo pipe_in pipe_out↵
↵
./$sol < pipe_in 2> error_sol.log | tee pipe_out &↵
./$checker < pipe_out 2> error_checker.log | tee pipe_in ↵
↵
echo "------------------- Error ------------------"↵
cat error_sol.log↵
echo "------------------- Error Checker ------------------"↵
cat error_checker.log↵
↵
rm error_sol.log↵
rm error_checker.log↵
rm pipe_in↵
rm pipe_out↵
~~~~~↵
↵
↵
↵
Save this by the name (say) run_checker.sh. Then run the following commands.↵
↵
Compile the solution and checker programs.↵
↵
`g++ -o E E.cpp`↵
↵
`g++ -o E_checker E_checker.cpp`↵
↵
Here E.cpp contains your solution program and E_checker.cpp contains your checker program.↵
↵
↵
Make the script executable↵
↵
`chmod +x run_checker.sh`↵
↵
Run the script with executable solution filename as first argument and executable checker filename as second argument.↵
`./run_checker.sh E E_checker`↵
↵
You should see an out as follows : ↵
↵
![ ](https://i.imgur.com/iIYkaMB.png)
↵
↵
There are other solutions to this, the one over [here](https://codeforces.me/blog/entry/49490) uses croupier(a python program) to make the two interact. ↵
↵
Simplifying the Connection with Linux Terminal:↵
The Linux terminal provides powerful tools to simplify the testing process for interactive problems. By leveraging a bash script and named pipes, you can effortlessly connect the solution program with the checker program. Here's a script to do so:↵
↵
~~~~~↵
sol=$1↵
checker=$2↵
↵
mkfifo pipe_in pipe_out↵
↵
./$sol < pipe_in 2> error_sol.log | tee pipe_out &↵
./$checker < pipe_out 2> error_checker.log | tee pipe_in ↵
↵
echo "------------------- Error ------------------"↵
cat error_sol.log↵
echo "------------------- Error Checker ------------------"↵
cat error_checker.log↵
↵
rm error_sol.log↵
rm error_checker.log↵
rm pipe_in↵
rm pipe_out↵
~~~~~↵
↵
↵
↵
Save this by the name (say) run_checker.sh. Then run the following commands.↵
↵
Compile the solution and checker programs.↵
↵
`g++ -o E E.cpp`↵
↵
`g++ -o E_checker E_checker.cpp`↵
↵
Here E.cpp contains your solution program and E_checker.cpp contains your checker program.↵
↵
↵
Make the script executable↵
↵
`chmod +x run_checker.sh`↵
↵
Run the script with executable solution filename as first argument and executable checker filename as second argument.↵
`./run_checker.sh E E_checker`↵
↵
You should see an out as follows : ↵
↵
![ ](https://i.imgur.com/iIYkaMB.png)