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 very easily be extended to work with:

  • any programming language usable from the command-line,

  • any runner (shell, Makefile, ant) usable from the command-line,

  • any site that exposes information about contests/problems in an uniform and web-accessible form.

Support

Following sites and runner/language combinations are currently supported. If this bothers you, please check Contribute section.

Sites supported:

Runners/languages supported:

C++

Python

POSIX shell

sh.9 / cpp.9

sh.9 / py.9

OS supported:

  • Linux (tested)

Installation

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

$ pip install --upgrade --user hac

Install as super-user at your own risk:

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

Usage

Special commands that don’t fetch remote data:

$ hac -h             # show help
$ hac --version      # show version
$ hac --copy-config  # copy configuration

Commands that fetch remote data and processes 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.

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 this manner:

  • defaults are taken from hacrc from default-configuration directory (un-modifiable by user),

  • settings are taken from ~/.config/hac/hacrc and those that are present there override settings from hacrc from default-configuration directory,

  • settings are taken from command-line arguments and those that are present there override settings from ~/.config/hac/hacrc and default hacrc.

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-modified files in ~/.config/hac subdirectories to prevent over-shadowing of updated files in default-configuration directory. To remove all files in those directories run (careful, destructive):

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

To copy all default-configuration files in a temporary directory (useful when you want to use any of the default files as a starting point for your custom file).

$ HAC_CONFIG_DIR=~/temp_config hac --copy-config
$ # ... change some files from ~/temp_config and copy them to ~/.config/hac
$ rm -r ~/temp_config   # remove temporary directory

When HAC is started, selected language templates are copied to the destination directories unchanged while selected runner templates are processed (interpolated) with corresponding template-parts. For example cpp.dbg_run.9.sh is interpolated in temp.9.sh at the point where $dbg_run label appears alone in the line in temp.9.sh file.

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 -d0 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 ~/CF527
$ hac -w~/CF527 -d1 -t1 prep http://codeforces.com/527 B C

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

$ cd ~/CF527/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:

$ cd ~/CF527/B
$ ./B.cpp.sh -d 2

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.1.tar.gz (28.8 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.1-py2.py3-none-any.whl (31.7 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

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

File hashes

Hashes for hac-1.0.1.tar.gz
Algorithm Hash digest
SHA256 8d224f3e4e233bb5522bea5343dcacdbd3822f88713178dfec927bf3e2ce1eb2
MD5 5bb9407daf8f976df20ac8c0f60c4a16
BLAKE2b-256 9b7bfac6e55ab6f523071c1af6e33eb535d36c0c608abf93acf49b8013827764

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hac-1.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fa76db0bfa936e74bc701ecb068f6a9cc234f7132a66c3ef98115f0c5af63fc5
MD5 c9a6f777ccc05cdd47e75bf864e4b989
BLAKE2b-256 3cdc51508b59d77980aebd766fdc0b1452db7ec8ca3cc97a04b968e46202d189

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