Browse Source

Adding script templates

pull/2/head
Ryan Reed 3 years ago
parent
commit
ac18d66ad7
2 changed files with 93 additions and 0 deletions
  1. +47
    -0
      puzzles/TEMPLATE_dayXX.py
  2. +46
    -0
      puzzles/TEMPLATE_test_dayXX.py

+ 47
- 0
puzzles/TEMPLATE_dayXX.py View File

@ -0,0 +1,47 @@
"""
TEMPLATE FOR ADVENT OF CODE
REPLACE EXAMPLES:
* dayXX -> day01
* Day XX -> Day 01
Advent of Code 2021 - Day XX
Run with:
python puzzles/dayXX.py inputs/dayXX.txt
"""
import pathlib
import sys
from typing import List, Tuple
def part1(inputs: List[int]) -> int:
return False
def part2(inputs: List[int]) -> int:
return False
def parse(inputs: str) -> List[int]:
"""Parse the input string"""
return [int(line) for line in inputs.split()]
def solve(path: str) -> Tuple[int, int]:
"""Solve the puzzle"""
puzzle_input = parse(pathlib.Path(path).read_text().strip())
part1_result = part1(puzzle_input)
part2_result = part2(puzzle_input)
return part1_result, part2_result
def main() -> None:
for path in sys.argv[1:]:
print(f"Input File: {path}")
part1_result, part2_result = solve(path)
print(f"Part 1 Result: {part1_result}")
print(f"Part 2 Result: {part2_result}")

+ 46
- 0
puzzles/TEMPLATE_test_dayXX.py View File

@ -0,0 +1,46 @@
"""
Replace `dayXX` with the day number (e.g. `day01`)
Remove the 'Not implemented' marks when ready to run the test
"""
import pathlib
import pytest
import dayXX as aoc
INPUTS_DIR = f"{pathlib.Path(__file__).parent.parent}/inputs"
@pytest.fixture
def example_data1():
input_path = f"{INPUTS_DIR}/dayXX-example1.txt"
return aoc.parse(pathlib.Path(input_path).read_text().strip())
@pytest.fixture
def example_data2():
input_path = f"{INPUTS_DIR}/dayXX-example2.txt"
return aoc.parse(pathlib.Path(input_path).read_text().strip())
@pytest.fixture
def dayXX_data():
input_path = f"{INPUTS_DIR}/dayXX.txt"
return aoc.parse(pathlib.Path(input_path).read_text().strip())
@pytest.mark.skip(reason="Not implemented")
def test_example1(example_data1):
assert aoc.part1(example_data) == ...
@pytest.mark.skip(reason="Not implemented")
def test_example2(example_data2):
assert aoc.part2(example_data) == ...
@pytest.mark.skip(reason="Not implemented")
def test_part1(day02_data):
assert aoc.part1(day02_data) == ...
@pytest.mark.skip(reason="Not implemented")
def test_part2(day02_data):
assert aoc.part2(day02_data) == ...

Loading…
Cancel
Save