### 2 releases

0.1.1 | May 11, 2023 |
---|---|

0.1.0 | May 10, 2023 |

#**13** in #puzzle-solver

Used in aocrun

**MIT**license

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,

and `Puzzl`

traits are provided.`Solve`

To generate solvers for a puzzle using

,
add `solver`

feature flag in Cargo.toml`solvers`

If you wish to implement your own solver, and only require some
useful utilities, add

feature flag in Cargo.toml`toolcase`

# Examples

Two traits

and `Puzzl`

are provided to interface with the
solvers.`Solve`

`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`\n`2000`\n``\n`4000`\n``\n`5000`\n`6000`\n``\n`7000`\n`9000`"``;`
`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

~1–1.6MB

~33K SLoC