This repository contains my solutions for the Advent of Code 2024 challenges.
- Python 3.11 or higher
- Pipenv for dependency management
- Clone the Repository:
git clone https://github.com/grabovszky/aoc2024.git
cd aoc2024
- Install Dependencies:
python scripts/setup.py
- Activate the Virtual Environment:
pipenv shell
The setup script will:
- Install all required dependencies
- Set up pre-commit hooks for:
- Code formatting with black
- Running tests before commits
- Checking Python syntax
inputs/
: Contains all the input files for each day's challenge, named as dayXX.txt, where XX is the day number (e.g., day01.txt).main.py
: The main script to run solutions for all days or a specific day.scripts/
:create_day.py
: A script to automate the creation of a new day's solution structure, including necessary files and directories.setup.py
: A script to setup the project and install dependencies.
lib/
:core/
: Contains core functionality, such asRunner
andTimer
classes.utils/
: Contains utility functions, such asargparser
andlogger
.
solutions/
:common.py
: Contains common utility functions, such asread_input()
for reading input files.dayXX/
: Each day's solution is in its own directory, where XX is the day number (e.g., day01, day02, etc.).part1.py
: Solution for Part 1 of the day's challenge.part2.py
: Solution for Part 2 of the day's challenge.utils.py
: Helper functions or classes specific to the day.
tests/
:test_dayXX.py
: Contains tests for Day XX's solutions.
Before running any script ensure you are in the project's root directory and have activated the virtual environment by runnin pipenv shell
.
You can run solutions for all days or a specific day using the main.py script.
To run the current day's solutions:
python main.py
To run all implemented days:
python main.py --all
To run with timing information:
python main.py --time
To run a specific day:
python main.py --day DAY_NUMBER
To run a specific part:
python main.py --day DAY_NUMBER --part PART_NUMBER
The main.py
script includes a timing feature to measure the execution time of each part and the total time for each day.
Enable Timing: Use the --time
flag when running the script.
Output: The script will display execution times for Part 1, Part 2, and the total time for the day.
Tests are located in the tests/
directory and use the pytest framework.
To run all tests:
pytest
To run tests for a specific day:
pytest tests/test_dayXX.py
If you'd like to add a new day's solution or improve existing ones, please follow these steps.
To streamline the process of adding a new day's solution, use the create_day.py script. This script automates the creation of the necessary files and directories for the next available day.
To create the structure for a new day's challenge:
python scripts/create_day.py
This script will:
- Determine the next available day number.
- Create the necessary directories and files, including:
solutions/dayXX/
:__init__.py
utils.py
part1.py
(with DAY_NUMBER pre-filled)part2.py
(with DAY_NUMBER pre-filled)
inputs/dayXX.txt
: Empty input file ready for your puzzle input.tests/test_dayXX.py
: Test file with placeholder functions.
- Populate files with template code.
- Handle errors gracefully, cleaning up any partially created files or directories if an error occurs.
- Use Python 3.11 or higher.
- Follow PEP 8 coding style guidelines.
The project uses pre-commit hooks to ensure code quality. These hooks run automatically on commit and include:
- Code formatting with black
- Python syntax checking
- Running tests
You can run the hooks manually without committing:
# Run all hooks on all files
pipenv run pre-commit run --all-files
# Run specific hook on all files
pipenv run pre-commit run black --all-files
# Run all hooks on staged files
pipenv run pre-commit run
The hooks will also run automatically when you try to commit changes. If any hook fails:
- The commit will be blocked
- The hooks may modify files (e.g., black formatting)
- You'll need to stage any changes and try to commit again
- Test Functions Individually: Write tests for both solve_part1 and solve_part2 functions.
- Use Clear Test Data: Include example inputs and expected outputs.
- Avoid Duplication: Use fixtures or module-level variables to share test data.
This project is open source and available under the MIT License.