Skip to main content

hac - Helper for Algorithm Competitions

Project description

hac is highly extensible and configurable command-line tool intended to ease the boring part of solving algorithm problems:

  • preparing directory structure,

  • preparing source-code files,

  • preparing runner files (scripts used for testing solutions),

  • downloading test-cases.

hac can be extended very easily to work with:

  • any programming language usable from the command-line,

  • any runner usable from the command-line (examples: shell scripts, Makefiles, ant scripts),

  • any site that exposes information about contests/problems in an uniform and web-accessible form (examples: Codeforces, Codechef).

Support

If lack of support for particular programming language or site irks you, please check Contribute section. This section contains current up-to-date support info.

Sites supported:

Runner/language combinations supported:

POSIX shell

C++

sh.9 / cpp.9

Python

sh.9 / py.9

OS supported:

  • Linux (tested)

Python versions

  • 2.7

  • 3.3

  • 3.4

Installation

To install hac you need to have pip installed on your system. Since hac messes with the file-system it is strongly advisable to install it as regular user (to mitigate the responsibility that comes with power ;) ):

$ pip install --upgrade --user hac

Install as super-user at your own risk:

user$ # ... switch to super-user
root$ pip install --upgrade hac

Usage

Special commands that don’t fetch remote data:

$ hac --help         # show help
$ hac --version      # show version
$ hac --copy-config  # copy configuration (to ~/.config/hac by default)

Commands that fetch remote data and process it (more info in Examples):

$ hac [options...] (prep | show) (CONTEST | PROBLEM) [PROBLEM [PROBLEM ...]]

For up-to-date list of command-line arguments and switches check hac’s help message.

Examples

1) Display verbose information about:

  • hac’s configuration,

  • available sites, runner and language templates,

  • selected site, contest and problems,

  • problems’ information for Codeforces contest #527.

$ hac -v show http://codeforces.com/527

2a) For problems “B” and “C” from Codeforces contest #527 prepare:

  • source-file from cpp highest priority template (has lowest X among all cpp.X templates),

  • runner from sh.9 template (gets interpolated for cpp language template),

  • pre-tests downloaded from Codeforces.

$ mkdir ~/contests && cd ~/contests
$ hac -d2 -lcpp -rsh.9 prep http://codeforces.com/527 B C

With default configuration any of the following lines is equivalent to the one above:

$ hac -lcpp.9 -rsh.9 prep http://codeforces.com/527 b c
$ hac http://codeforces.com/527 B C
$ hac cf/527 2 3

2b) Write solution for problem “B” and test it on pre-tests:

$ cd 527/B
$ # ... modify B.cpp
$ ./B.cpp.sh -e  # test solution on pre-tests
$ ./B.cpp.sh -c  # clean generated outputs

2c) Debug solution for problem “B” on 2nd pre-test:

$ ./B.cpp.sh -d 2

Tutorial

To copy configuration to user’s local directory (~/.config/hac by default, modifiable with HAC_CONFIG_DIR environment variable) run:

$ hac --copy-config

Modify user specific configuration by changing files in ~/.config/hac. File hacrc is main settings file. Total hac settings are calculated in a cascaded manner (similar in concept to how CSS works) by:

  • taking settings from hacrc from default-configuration directory (not writable by user),

  • overriding above settings with those from ~/.config/hac/hacrc,

  • overriding above settings with those from command-line arguments.

Files in ~/.config/hac sub-directories (lang, runner, site) over-shadow files in default-configuration directory with the same name. For example file ~/.config/hac/lang/temp.9.cpp over-shadows temp.9.cpp in default-configuration directory.

Template-part ~/.config/hac/runner/cpp.exec_compile.9.sh over-shadows cpp.exec_compile.9.sh in default-configuration directory. This template-part gets interpolated in temp.9.sh when runner sh.9 is prepared for any cpp language template. Modifying ~/.config/hac/runner/cpp.exec_compile.9.sh allows us change compilation flags or compiler used for C++ source compilation.

It is best to remove un-customized files in ~/.config/hac/{lang,runner,site} subdirectories to prevent possible over-shadowing of updated files in default-configuration directory (when hac gets updated). To remove all files in those directories run (careful, destructive):

$ rm -r ~/.config/hac/*/*

If you want to use any of the default configuration/template files as a starting point for your customized files, you can:

  • copy all default-configuration files in a temporary directory,

  • modify and move to ~/.config/hac files of interest and throw away others.

$ HAC_CONFIG_DIR=~/temp_config hac --copy-config
$ # ... modify interesting files in ~/temp_config and move them to
$ # ... ~/.config/hac
$ rm -r ~/temp_config   # remove temporary directory

When hac is run to prepare the environment (prep command):

  • selected language templates are copied for each task to the destination directories unchanged,

  • selected runner templates are processed (interpolated) with corresponding template-parts. For example if cpp and sh.9 are selected, contents of cpp.dbg_run.9.sh are interpolated in temp.9.sh (appropriately indented) at the point of where label $dbg_run occurs alone in the line in temp.9.sh file.

Priority labels of runner templates and runner-parts are completely separate from the priority labels of language templates. This means that

  • cpp.dbg_run.9.sh is exclusively a runner-part for temp.9.sh runner template (and not for temp.3.sh or temp.4.sh for example),

  • on the other hand, cpp.dbg_run.9.sh gets interpolated in temp.9.sh when any cpp language template is selected (either cpp.3 or cpp.9 or even cpp.100) with sh.9 runner template.

Authors

Zoran Plesivčak created hac and these fine people have contributed.

Contribute

Contributions are more than welcome! Please see CONTRIBUTING.

Change Log

Please see CHANGELOG.

Licence

Please see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hac-1.0.3.tar.gz (29.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hac-1.0.3-py2.py3-none-any.whl (32.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file hac-1.0.3.tar.gz.

File metadata

  • Download URL: hac-1.0.3.tar.gz
  • Upload date:
  • Size: 29.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for hac-1.0.3.tar.gz
Algorithm Hash digest
SHA256 a9762e2c53010b3595f076767e7587807548d5e16bdc74d1632ccafc97438cf1
MD5 3e812ed8b6cf2bf99fa01f3f0b76b468
BLAKE2b-256 93f53106109caa45657b1d4c71228d46b5050a7f79fbb352d67a05389885d601

See more details on using hashes here.

File details

Details for the file hac-1.0.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for hac-1.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 45a0aa54c1e67540ec93eb7e71640de1b1a54f91f73b2d5da9c48f94ab503973
MD5 f356a6af3e70b3c59e0eb9bf2160858f
BLAKE2b-256 e5ed16fba89ea805aaade69a3034d0092835303cffe405e677824269ab983e76

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page