WrongAnswer
online judge clients
Quick Start
Clone this repository
$ git clone git://github.com/bhuztez/wronganswer.git
$ cd wronganswer
Test solution locally
$ python3 -m wronganswer test 'http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A' \
> -- echo 'Hello World'
Submit solution to online judge
$ python3 -m wronganswer submit 'http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A' \
> C solutions/judge.u-aizu.ac.jp/ITP1_1_A.c
Submit solution via vjudge.net
$ python3 -m wronganswer submit --agent=vjudge.net \
> 'http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A' \
> C solutions/judge.u-aizu.ac.jp/ITP1_1_A.c
Installation
Install (Python 3.7 or above is required)
$ pip3 install --user wronganswer
Now wa could be used, instead of python3 -m wronganswer. For example, test solution locally
$ wa test 'http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A' \
> -- echo 'Hello World'
Project
WrongAnswer comes with project support.
Test solution locally
$ ./c.py test solutions/judge.u-aizu.ac.jp/ITP1_1_A.c
And submit the solution
$ ./c.py submit solutions/judge.u-aizu.ac.jp/ITP1_1_A.c
Now, take a look at c.py to see how it works
First is the boilerplate code, to inform WrongAnswer that this is a project configuration, and make this a script
#!/usr/bin/env python3
if __name__ == '__main__':
from wronganswer.project import main
main("Wrong Answer Project")
quit()
Then is the regular expression to extract domain name of online judge and problem ID from filename of solution
SOLUTION_PATTERN = r'^(?:[^/]+)/(?P<oj>[\w\-.]+)(?:/.*)?/(?P<pid>[A-Za-z0-9_\-]+)\.c$'
or you may define a function get_solution_info
, which should return a tuple if the file is a solution, and None
if not. The first element of the tuple should be the domain name of online judge and the second element should be the problem ID.
Finally, get_compile_argv
is the function called by WrongAnswer to get command line arguments to call the compiler. WrongAnswer would pass the source code of the solution to stdin.
def get_compile_argv(filename):
dest = dest_filename(filename)
return dest, ['gcc','-Wall','-Wextra','-Werror','-x','c','-o',dest,'-']
For scripts, get_compile_argv
should return filename, None
.
Advanced
Moreover, WrongAnswer can help you to compile your code locally and submit the assembly to the online judge. Run the following to see what is going to be submitted.
$ ./a.py preview solutions/judge.u-aizu.ac.jp/ITP1_1_A.c
Local judge protocol (experimental)
For example, You may output "\x1bXf.3\x1b\\"
just before a floating point number, WrongAnswer would ignore absolute error smaller than 0.001
.
Supported Online Judges
Online Judge | Submit | Fetch test cases | vjudge.net | Example |
---|---|---|---|---|
AOJ | Y | Y | Y | ITP1_1_A: Hello World |
LeetCode | Y | N | N | 50. Pow(x, n) |
POJ | Y | N | Y | 1000 A+B Problem |