2 releases
0.1.1 | May 11, 2023 |
---|---|
0.1.0 | May 10, 2023 |
#15 in #puzzle-solver
Used in aocrun
22KB
471 lines
Aocsol
This repository holds solutions to Advent Of Code puzzles year and day wise.
How to use
Use this library crate to get solvers for the puzzles. See documentation
lib.rs
:
A crate that holds solutions to Advent of Code(AoC) puzzles.
The solutions are implemented in async rust, thus need an async runtime such as tokio
.
Feature-flags
By default, Puzzl
and Solve
traits are provided.
To generate solvers for a puzzle using solver
,
add solvers
feature flag in Cargo.toml
If you wish to implement your own solver, and only require some
useful utilities, add toolcase
feature flag in Cargo.toml
Examples
Two traits Puzzl
and Solve
are provided to interface with the
solvers.
use std::{error, sync::Arc};
use aocsol::{puzzle::Puzzl, solver};
#[tokio::main]
async fn main() -> Result<(), Box<dyn error::Error + Send + Sync>> {
let data = "1000\n2000\n\n4000\n\n5000\n6000\n\n7000\n9000";
let puzzle = AocPuzzle(Arc::from(data));
let solver = solver::solver(puzzle)?; // solver generated
let answer_part_one: u32 = solver.part_one().await?.to_string().parse()?;
let answer_part_two: u32 = solver.part_two().await?.to_string().parse()?;
assert_eq!(16000, answer_part_one);
assert_eq!(31000, answer_part_two);
Ok(())
}
// Sturct to hold data.
struct AocPuzzle(Arc<str>);
// Implement Puzzl<InputType = Arc<str>> to generate solver using aocsol::solver::solver().
impl<'input> Puzzl for AocPuzzle {
type InputType = Arc<str>;
fn year(&self) -> u32 {
2022
}
fn day(&self) -> u32 {
1
}
fn data(&self) -> Self::InputType {
Arc::clone(&self.0)
}
}
Dependencies
~0.9–1.5MB
~31K SLoC