Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anze3db/adventofcode
Helper utilities for solving Advent of Code puzzles
https://github.com/anze3db/adventofcode
Last synced: 12 days ago
JSON representation
Helper utilities for solving Advent of Code puzzles
- Host: GitHub
- URL: https://github.com/anze3db/adventofcode
- Owner: anze3db
- License: mit
- Created: 2023-12-07T10:23:23.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-04-08T21:58:37.000Z (7 months ago)
- Last Synced: 2024-04-14T13:17:56.682Z (7 months ago)
- Language: Python
- Size: 44.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# adventofcode
Helper utilities for solving Advent of Code puzzles.
* No copy-pasting puzzle inputs into files.
* No need to use low-level file APIs to read your inputs.
* Performance reports for example inputs and puzzle inputs.
* Submit the answer immediately when your code returns the result 🏎️## Usage
### Install the package
Install the package with pip:
```bash
pip install adventofcode
```### Set your session cookie
Add the [adventofcode.com](https://adventofcode.com) session cookie value to your env:
```bash
export AOC_SESSION="..."
```Alternatively, you can save your `AOC_SESSION="******"` value in a `.env` file.
> [!NOTE]
> Setting AOC_SESSION will allow you to get your personal puzzle output (`aoc.get_input()`) and submit your answers with `aoc.submit_p1()` and `aoc.submit_p2()`.### Use a template to solve puzzles
I use the following template to start solving puzzles, see my examples in [my repo for 2023](https://github.com/anze3db/adventofcode2023).
```python
from adventofcode import AoCdef part1(inp):
return Nonedef part2(inp):
return Noneaoc = AoC(part_1=part1, part_2=part2)
inp = """sample input"""
# Run your part1 function with sample input and assert the expected result:
aoc.assert_p1(inp, 42)
# Run your part1 function on puzzle input and submit the answer returned:
aoc.submit_p1()# Run your part2 function with sample input and assert the expected result:
aoc.assert_p2(inp, 6*7)
# Run your part2 function on puzzle input and submit the answer returned:
aoc.submit_p2()
```> [!NOTE]
> All submissions and fetched results are cached locally in the `.cache.db` file so that we don't spam the AoC servers or resubmit the same answer multiple times.### Or build your workflow using the AoC class
```python
from adventofcode import AoCaoc = AoC() # defaults to current year and parses the day from the filename (e.g. 01.py will be day 1)
aoc.print_p1() # prints the first part of the puzzle
inp = aoc.get_input() # returns the input as a string
# solve the puzzle here
...
aoc.submit_p1('part 1 answer') # submits the answer to the first part of the puzzle
aoc.print_p2() # prints the second part of the puzzle
# solve the puzzle here
...
aoc.submit_p2('part 2 answer') # submits the answer to the second part of the puzzle
```