Skip to content

Tools for running, judging and submitting files for the Kattis system

License

Notifications You must be signed in to change notification settings

mateuszdrwal/kattis-tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kattis-tools

Tools for running, judging and submitting files for the Kattis system

Features

  • Creating directories for problems and downloading their samples automatically
  • Compiling and running code with a sample as input
  • Judging solutions based on the sample test data
  • Uploading submissions

Installation

  1. Download/clone this repository
  2. Install Python (kattis-tools supports both Python 2 & 3)
  3. Install dependencies by running python -m pip install -r requirements.txt

kattis-tools is a python script. Run it with python kattis-tools.py

Usage

To start working on a new project, run python kattis-tools.py start <URL> with the URL of the problem. As an example, I will be solving this problem.

$ python kattis-tools.py start https://open.kattis.com/problems/simpleaddition
A problem enviroment for problem simpleaddition has been created.

This creates the following problem directory and downloads all samples into it:

simpleaddition/
├── 1.ans
├── 1.in
├── 2.ans
├── 2.in
└── problem.json

Your solution code file should be located in that directory. Its name does not matter. When debugging your code, you can run python kattis-tools.py run <sample> to run your code with a specific sample input. (Since this is the first time we are running kattis-tools, we need to specify our language with -l. kattis-tools will remember this for the future)

$ python kattis-tools.py run 1 -l py
running...
1379
took 0.053s

If you want to test your solution with all test cases, run python kattis-tools.py judge:

$ python kattis-tools.py judge
Found 2 tests

testing with "1.in"...
Accepted
took 0.050s

testing with "2.in"...
Wrong Answer
got
12345
instead of
10000000000000

took 0.049s

1/2 passed
worst time: 0.050s

If you want to submit your solution you should run python kattis-tools.py submit. Once your solution has been submitted kattis-tools will open the submission in your web browser.

$ python kattis-tools.py submit
Before you can submit problems you need to register the token specific to this Kattis subdomain with kattis-tools. Your browser will open to the correct page.
Press Enter to continue...
From the webpage, Please copy paste the two lines with "username" and "token" here and press enter a few times:
username: *************
token: ****************************************************************

Submission received. Submission ID: 3544950.

Extra Features

Custom output validators

If the solution to a problem cannot be represented in a simple .ans file (for example if there are multiple solutions), a custom output validator can be provided. To use this feature, add the -v flag when running kattis-tools. The configuration for where the validator code is located, how it is compiled and ran is stored in problem.json in the problem directory. The two settings validator_compile and validator_run work exactly as the two settings before_run and run_command in language configuration files (documented below). By default the validator should be named validator.cpp and placed in the problem directory, and is compiled using g++ (standard c++ language config).

kattis-tools will pass the sample input file name (not the path, make sure the validator is running in the problem directory by using cd in validator_run like it is by default) as a command line argument when running the validator and feed the solution programs solution into stdin. The validator needs to return an exit code of 42 if the solution programs solution is valid, or exit code 43 to signal a Wrong Answer. kattis-tools will print the validators stdout if a solution recieves Wrong Answer, so the validator is able to send an explanation of what was wrong to stdout.

Configuration

Configuration files exist in the config-kattis-tools folder.

config.json:

{
    "last_language": "py", // The short name of the last used language (and the default language to use). Can be modified with the -l command line argument
    "last_problem": "hello" // The id of the last run problem (and the default problem to run). Can be modified with the -p command line argument
}

By default, kattis-tools comes configured with 4 languages: Python 2 (pypy), C++, JavaScript and Rust. If you use a different language you will have to create a new json file in the config-kattis-tools/languages folder. Feel free to submit a pull request with it so it can be added to kattis-tools. Here is an example file for C++ on windows:

{
    "name": "C++", // The Kattis name of the language. Must be one of the names in the codeblock below this one, otherwise Kattis will return "Invalid Language" when submitting.
    "extensions": [".cpp", ".c++", ".cc", ".cxx", ".h"], // File extensions for this language
    "short_names": ["cpp", "c++", "cxx"], // Short names for this language, they are what identifies the language when running -l.
    "before_run": "cd ${problemDir} && g++ -static ${fileName} -o ${fileNameNoExtension}.exe", // A command to run before running your program. Usually used for the compile command, can be left empty if your language does not require compilation. Only runs once before all tests when judging.
    "run_command": "${filePathNoExtension}.exe" // The command that runs your program.
}

valid Kattis language names:

C
C#
C++
Go
Haskell
Java
JavaScript (Node.js)
JavaScript (SpiderMonkey)
Kotlin
Objective-C
Pascal
PHP
Prolog
Python 2
Python 3
Ruby
Rust
Scala

You may have noticed variables in the language config. Here is a full list of them:

${filePath}
${filePathNoExtension}
${fileName}
${fileNameNoExtension}
${problemDir}
${workingDir}

About

Tools for running, judging and submitting files for the Kattis system

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages