Here is the Code Jam Interactive problem that I'm trying to test locally. My solution is in C , my IDE is Visual Studio 2019, and I'm on Windows 10. I have little to no experience with Linux, Bash, Python and I'm stuck.
Reading an answer from How to debug Google Code Jam interactive problems on VSCode using python? was not helpful because I'm using a different language and IDE.
First thing I did was to download the local_testing_tool.py
which is given at the bottom of the problem statement.
Then I read the interactive problem section of the CodeJam FAQ which does not go into enough details on how to set up the interactive tool.
To test your solution locally, use our interactive_runner script in conjunction with the judge. Instructions are included in the comments
I'm stuck on this part. Where do I use the script and how to I use both at the same time? The instructions in the comments do not specify where to run the code.(command prompt? terminal?)
Moreover, I watched a video on Youtube where the person runs both python script and C script (at around 15 minute mark) in the same IDE. But unfortunately, the person was using Linux instead of Windows.
Attempt using Spyder3 to run script
I tried running the interactive_runner.py script on Spyder IDE but got this error :
AssertionError: There should be exactly one instance of '--' in the command line.
Attempt using Ubuntu
Following a comment from Codeforces, I installed WSL from the official Microsoft docs. I tried this command python3 interactive_runner.py python3 testing_tool.py 0 -- cpp.exe
on Ubuntu Bash, where cpp.exe is the executable file of my solution, but got this error : python3: can't open file 'interactive_runner.py': [Errno 2] No such file or directory
Any help is much appreciated. Thank you.
CodePudding user response:
I figured it out. I'll try to explain everything from start.
First make sure that you have the compiled your solution and that you have the executable file somewhere.
There's an interactive_runner Python script which can be found in the FAQ of CodeJam. Create a Python file named interactive_runner
in the same folder as your executable file . The file extension should be .py
. Paste the script given on the website in your newly created interactive_runner
file then save it.
Then download the respective local_testing_tool
of the interactive problem you have solved. The link for this file is found at the bottom of problem statement. Fortunately this file is already a python script so you can simply move this file to the previous folder containing the interactive_runner
and solution.exe
(your executable file)
Now you will need to run the following 3 files together : interactive_runner
, solution.exe
,local_testing_tool
.
I used Ubuntu to do this. Follow the instructions from the official Microsoft Docs to setup WSL.
Open your Ubuntu terminal.
Navigate to directory containing the 3 files
The path to my folder was C:\Users\user\source\repos\CP\Debug.
For Ubuntu, this translates to /mnt/c/Users/user/source/repos/CP/Debug
. It will be different for you.
I then ran this :
cd /mnt/c/Users/user/source/repos/CP/Debug
If you need more help on how to change directories, try reading this
Running each test set
Replace my file path with yours.
1st test set
python3 interactive_runner.py python3 local_testing_tool.py 0 -- /nnn/c/Users/user/source/repos/CP/Debug/my_solution.exe
2nd test set
python3 interactive_runner.py python3 local_testing_tool.py 1 -- /nnn/c/Users/user/source/repos/CP/Debug/my_solution.exe
Notice how there's a single number changing when changing test sets. The number of test sets varies from problem to problem.
Remarks
All interactive problems uses the same
interactive_runner
but differentlocal_testing_tool
. So you have to download a newlocal_testing_tool
for each interactive problem but there's no need to redownload the interactive runner.Each time you make a change to your source code, you have to recompile your code to update your executable file.
Remember that you have to flush the output in your program each time you output something.