algorist
Cargo sub-command to manage the algorist crate.
Installation
Once installed, you can use it as cargo algorist or as algorist directly (within this document,
we will use algorist for brevity).
Usage
Create a new contest project
To create a new contest project:
# examples:
This will create a Rust project with all the necessary problem files and algorithm modules copied into it.
Problem files will be created in src/bin directory, and the library with algorithms and data
structures will be created in crates/algorist directory.
To ensure that everything works, run the problem file in src/bin/a.rs:
# run problem A (`src/bin/a.rs`)
# it expects input from stdin (type 1 2 3 and press Enter)
# expects input from `inputs/a.txt` file
# it is a normal Rust project, you can use all the usual commands
If you don't want to have initial problem files added to the contest project, you can create a new
contest project with --empty flag:
Later on, you can always add a problem file into src/bin directory, using:
# examples:
Work on a problem
The problem file src/bin/<problem_id>.rs will contain entry point main() function, which is
expected to read input from standard input and write output to standard output.
The starter code for the problem file will look something like this:
use ;
Note: see the Algorist documentation for details and
illustrative examples.
Normally, when working on a solution, you copy the tests cases from the contest system into the clipboard (or file), and then need to see the output of your program.
With the project created using cargo-algorist, you can do this easily:
# From standard input (default)
# From input file
# From clipboard (rarely used, but still useful)
# alias pbpaste=’xsel — clipboard — output’ on Linux
|
Once you are happy with the output, you can submit the solution back to the contest system (by bundling into a single file).
Bundle the project
Contest systems expect a single output file, where all the used modules are packed within the scope
of that file. At the very least io module is expected to be included in such an output file.
To bundle a given problem file, use the following command:
# examples:
This will create a single output file in bundled/src/bin/<problem_id>.rs file, which can be
submitted to the contest system.
You can test it by running:
# The code in `bundled` is a Rust project, with single-file
# binaries for each problem. So, you can also run:
Note: only the modules actually used in the problem file will be included in the output file.
The Algorist library
The Algorist library contains a lot of useful code that can be imported into your contest projects.
See algorist crate documentation for a complete list
of available algorithms and data structures, as well as their usage examples.
Using your own algorithms and data structures
By default, when creating projects with cargo algorist create the
algorist library will be added into crates/algorist
directory.
While the Algorist crate provides a lot of useful algorithms and data structures, the original plan was to allow users to rely on their own code, i.e. when working on contest problems, if you find something that can be abstracted into a reusable module, you can do it and expand your own library of algorithms. This way your library grows with your experience.
To use your own library, specify path to it with --manifest-path (or -p):
# Path to project (directory with `Cargo.toml`) will also work
# No need to specify `Cargo.toml` file explicitly
Your project will be created in the same way, but instead of copying the Algorist library, it will copy your own library.
It is recommended that you start by forking the algorist
repository, and then use it as a base for your own library (for instance, remove everything, but
io, and have fun). The io module is assumed by default problem files that are created if
--empty flag is not specified, or when cargo algorist add <problem_id> is used.
License
MIT