Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $ pipx install copier
$ python -m pip install advent-of-code-data
```

Once you have Copier on your system, you can create Advent of Code solution templates as follows:
Note that `advent-of-code-data` requires a small bit of [setup](https://github.com/wimglenn/advent-of-code-wim/issues/1) where you find and specify your personal Advent of Code session ID. Once you have Copier on your system, you can create Advent of Code solution templates as follows:

```console
$ copier gh:gahjelle/template-aoc-python advent_of_code/
Expand All @@ -29,14 +29,30 @@ You can also use Copier as part of a script. The [documentation](https://copier.
On the command line, you can use `-d` to provide answers to questions instead of answering them interactively. On Bash (and possibly other shells), the following will set up all directories for the 2021 event inside of your `aoc/` directory:

```console
$ for day in {1..25}; do
> copier gh:gahjelle/template-aoc-python -d year=2021 -d day=$day -d puzzle_name="" aoc/
$ for day in {01..25}; do
> copier gh:gahjelle/template-aoc-python -d year=2021 -d day=$day -d puzzle_name="" -d puzzle_dir=$day aoc/
> done
```

If you're using Powershell on Windows, you can use something like this instead:

```
for ($day = 1; $day -le 25; $day++) {
$day_str = "{0:00}" -f $day
copier gh:gahjelle/template-aoc-python -d year=2021 -d day=$day_str -d puzzle_name="" -d puzzle_dir=$day_str aoc/
}
```

After running this, you'll have 25 subdirectories within `aoc/2021/` with templates for solving each day of Advent of Code with Python.


## Examples

See https://github.com/gahjelle/advent_of_code/tree/main/python for examples using the template.
See https://github.com/gahjelle/advent_of_code/tree/main/python for examples using the template. My tutorial, [Advent of Code: Solving Your Puzzles With Python](https://realpython.com/python-advent-of-code/), explains the reasoning behind the template and shows a few examples of using it to solve puzzles.


## Credits

Thanks to [Matt Gregory](https://github.com/grovduck) for helping to [debug](https://github.com/gahjelle/template-aoc-python/issues/1) this recipe for Windows and creating the Powershell script to create a full year of templates.

And a huge thanks to [Eric Wastl](https://twitter.com/ericwastl/) for creating the wonderful [Advent of Code](https://adventofcode.com/).
70 changes: 35 additions & 35 deletions copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,49 @@ _tasks:

# Questions
year:
type: int
type: str
choices:
- 2015
- 2016
- 2017
- 2018
- 2019
- 2020
- 2021
- "2015"
- "2016"
- "2017"
- "2018"
- "2019"
- "2020"
- "2021"

day:
type: int
type: str
choices:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- "01"
- "02"
- "03"
- "04"
- "05"
- "06"
- "07"
- "08"
- "09"
- "10"
- "11"
- "12"
- "13"
- "14"
- "15"
- "16"
- "17"
- "18"
- "19"
- "20"
- "21"
- "22"
- "23"
- "24"
- "25"

puzzle_name:
type: str
default: ""

puzzle_dir:
type: str
default: "[['%02d'|format(day)]][% if puzzle_name %]_[[puzzle_name|lower|replace(' ','_')]][% endif %]"
default: "[[day]][% if puzzle_name %]_[[puzzle_name|lower|replace(' ','_')]][% endif %]"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""AoC [[day]], [[year]][% if puzzle_name %]: [[puzzle_name]][% endif %]"""
"""AoC [[day|int]], [[year]][% if puzzle_name %]: [[puzzle_name]][% endif %]"""

# Standard library imports
import pathlib
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Tests for AoC [[day]], [[year]][% if puzzle_name %]: [[puzzle_name]][% endif %]"""
"""Tests for AoC [[day|int]], [[year]][% if puzzle_name %]: [[puzzle_name]][% endif %]"""

# Standard library imports
import pathlib

# Third party imports
import aoc[[year]][['%02d'|format(day)]]
import aoc[[year]][[day]]
import pytest

PUZZLE_DIR = pathlib.Path(__file__).parent
Expand All @@ -13,13 +13,13 @@ PUZZLE_DIR = pathlib.Path(__file__).parent
@pytest.fixture
def example1():
puzzle_input = (PUZZLE_DIR / "example1.txt").read_text().strip()
return aoc[[year]][['%02d'|format(day)]].parse(puzzle_input)
return aoc[[year]][[day]].parse(puzzle_input)


@pytest.fixture
def example2():
puzzle_input = (PUZZLE_DIR / "example2.txt").read_text().strip()
return aoc[[year]][['%02d'|format(day)]].parse(puzzle_input)
return aoc[[year]][[day]].parse(puzzle_input)


@pytest.mark.skip(reason="Not implemented")
Expand All @@ -31,10 +31,10 @@ def test_parse_example1(example1):
@pytest.mark.skip(reason="Not implemented")
def test_part1_example1(example1):
"""Test part 1 on example input"""
assert aoc[[year]][['%02d'|format(day)]].part1(example1) == ...
assert aoc[[year]][[day]].part1(example1) == ...


@pytest.mark.skip(reason="Not implemented")
def test_part2_example2(example2):
"""Test part 2 on example input"""
assert aoc[[year]][['%02d'|format(day)]].part2(example2) == ...
assert aoc[[year]][[day]].part2(example2) == ...