1 unstable release
0.1.0 | Nov 17, 2024 |
---|
#17 in #aoc
120 downloads per month
21KB
276 lines
AOC Framework
This crate provides a framework for easily running Advent of Code challenges.
Basic Usage
use aoc_runner::{AOCRunner, Challenge, ChallengePart};
use aoc_runner::input::from_file;
fn main() {
AOCRunner::new(ExampleChallenge::new())
.add_example(from_file("example.txt"), 42, ChallengePart::Part1)
.add_example(from_file("example.txt"), 233, ChallengePart::Part2)
.add_example(from_file("example_2.txt"), 402, ChallengePart::Part2)
.run(from_file("input.txt"));
}
Features
The DataLoader Trait
The DataLoader
trait is used to provide the input data to the challenge.
It consists of one function, load
, which returns a Vec<String>
.
The create provides a few functions for loading the input data from different sources such as files, string and via https.
The Challenge Trait
The Challenge<T>
trait is used to provide the solution to the challenge.
The trait is generic over T
which is the type of the result.
So this trait can be implemented for challenges with different result types (eg. Integers or Strings).
It consists of two functions, part1
and part2
, which are used to provide the solution to the respective part of the challenge.
The functions take a Vec<String>
as input and return an Option<T>
.
Examples
The struct AOCRunner
provides a function add_example
which is used to add examples to the challenge.
This way the user can provide examples for the challenge and check their solution.
The function takes a DataLoader
, the expected result and the corresponding part of the Challenge as input.
This way the user can provide examples for both parts of the challenge.
Feedback
After showing the result to the user, the framework will ask the user for feedback. The feedback will be saved and used in the next run. It will warn the user if a result is calculated that is too low or too high and therefore prevent the user from entering known incorrect reults again.
Goals
There are a few goals this crate aims to achieve:
1. Provide a simple interface for running challenges
The interface of the framework is very simple.
It consists of a struct, AOCRunner
, which is used to run challenges and add examples.
It also consists of a trait, Challenge
, which is implemented by the user to provide the solution to the challenge.
2. Provide a flexible and easy way to load the input data
The framework provides a few functions for loading the input data from different sources such as files, string and via https.
The user can also implement the DataLoader
trait to provide a custom way of loading the input data.
3. Save the result of the challenge for feedback to user
After showing the result to the user, the framework will ask the user for feedback. The feedback can be obtained from entering the result into the AoC website. If the result is incorrect, the website will provide a hint to the user wether the result is too low or too high. The framework will save the result and provide the user with additional information in the next run. It will warn the user if a result is calculated that is too low or too high and therefore prevent the user from entering known incorrect reults again.
Links
Dependencies
~6–17MB
~249K SLoC