Home

Awesome

Advent of Code Solutions

Advent of Code Made with Python Made with Docker Last commit


AoC 2024 AoC 2023 AoC 2022 AoC 2021 AoC 2020 AoC 2019 AoC 2018 AoC 2017 AoC 2016 AoC 2015


This project contains all my solutions for Advent of Code challenges.

[!WARNING] Note that this project can automatically download inputs from the Advent of Code server. Please use it moderately.

But what is Advent of Code? From the author, Eric Wastl:

Advent of Code is an Advent calendar of small programming puzzles for a variety of skill levels that can be solved in any programming language you like. People use them as interview prep, company training, university coursework, practice problems, a speed contest, or to challenge each other.

You don't need a computer science background to participate - just a little programming knowledge and some problem solving skills will get you pretty far. Nor do you need a fancy computer; every problem has a solution that completes in at most 15 seconds on ten-year-old hardware.

Table of Contents

Solutions

Year 2024

DayPartTask descriptionTask inputSolutionTime ComplexitySpace ComplexityNotes
1OneDescriptionInput$O(n*\log_2{n} + m*\log_2{m})$$O(n+m)$...
1TwoDescriptionInput$O(n+m)$$O(1)$...
2OneDescriptionInput$O(n*m)$$O(1)$...
2TwoDescriptionInput$O(n*m^2)$$O(m)$...
3OneDescriptionInput$O(n*m)$$O(k)$...
3TwoDescriptionInput$O(n*m)$$O(1)$...
4OneDescriptionInput$O((n+m)*(n+m)*k)$$O(n*m)$...
4TwoDescriptionInput$O(n * m * k)$$O(k)$...
5OneDescriptionInput$-$$-$Topological sort
5TwoDescriptionInput$-$$-$Topological sort
6OneDescriptionInput$O(n*m)$$O(n*m)$...
6TwoDescriptionInput$O(n^2*m^2)$$O(n*m)$...
7OneDescriptionInput$O(n*k^m)$$O(1)$Backtracking
7TwoDescriptionInput$O(n*k^m)$$O(m)$Backtracking
8OneDescriptionInput$O(n^2*m^2)$$O(n*m)$Linear Algebra
8TwoDescriptionInput$O(n^2 * m^2 * max(n,m))$$O(n*m)$Linear Algebra
9OneDescriptionInput$O(n*m)$$O(n*m)$...
9TwoDescriptionInput$O(n^2*m^2)$$O(n*m)$...
10OneDescriptionInput$O(n * m * k^{2})$$O(k)$DFS
10TwoDescriptionInput$O(n*m)$$O(n*m)$DFS
11OneDescriptionInput$O(n * 2^{m})$$O(n * 2^{m})$DP,Memoization
11TwoDescriptionInput$O(n * 2^{m})$$O(n * 2^{m})$DP,Memoization
12OneDescriptionInput$O(n * m)$$O(n * m)$DFS
12TwoDescriptionInput$O(n * m * min(n,m))$$O(n * m)$BFS
13OneDescriptionInput$O(n)$$O(1)$Algebra
13TwoDescriptionInput$O(n)$$O(1)$Algebra
14OneDescriptionInput$O(n)$$O(1)$...
14TwoDescriptionInput$O(∞)$$O(n)$...

Year 2023

DayPartTask descriptionTask inputSolutionTime ComplexitySpace ComplexityNotes
1OneDescriptionInput$O(n*m)$$O(1)$
1TwoDescriptionInput$O(n*m^2)$$O(m)$
2OneDescriptionInput$O(n*m)$$O(1)$
2TwoDescriptionInput$O(n*m)$$O(1)$

Year 2022

DayPartTask descriptionTask inputSolutionTime ComplexitySpace ComplexityNotes
1OneDescriptionInput$O(n*m)$$O(1)$
1TwoDescriptionInput$O(n*m)$$O(1)$

Year 2021

DayPartTask descriptionTask inputSolutionTime ComplexitySpace ComplexityNotes
1OneDescriptionInput$O(n)$$O(1)$...
1TwoDescriptionInput$O(n)$$O(1)$...
2OneDescriptionInput$O(n)$$O(1)$...
2TwoDescriptionInput$O(n)$$O(1)$...

Year 2020

DayPartTask descriptionTask inputSolutionTime ComplexitySpace ComplexityNotes
1OneDescriptionInput$O(n)$$O(n)$
1TwoDescriptionInput$O(n^2)$$O(1)$

Year 2019

DayPartTask descriptionTask inputSolutionTime ComplexitySpace ComplexityNotes
1OneDescriptionInput$O(n)$$O(1)$
1TwoDescriptionInput$O(n*log_{3}(m))$$O(1)$

Year 2018

DayPartTask descriptionTask inputSolutionTime ComplexitySpace ComplexityNotes
1OneDescriptionInput$O(n)$$O(1)$
1TwoDescriptionInput$O(n)$$O(n)$

Year 2017

DayPartTask descriptionTask inputSolutionTime ComplexitySpace ComplexityNotes
1OneDescriptionInput$O(n)$$O(1)$
1TwoDescriptionInput$O(n)$$O(n)$
2OneDescriptionInput$O(n*m)$$O(1)$
2TwoDescriptionInput$O(n*m^2)$$O(1)$

Year 2016

DayPartTask descriptionTask inputSolutionTime ComplexitySpace ComplexityNotes
1OneDescriptionInput$O(n)$$O(1)$
1TwoDescriptionInput$O(n*m)$$O(n*m)$

Year 2015

DayPartTask descriptionTask inputSolutionTime ComplexitySpace ComplexityNotes
1OneDescriptionInput$O(n)$$O(1)$...
1TwoDescriptionInput$O(n)$$O(1)$...
4OneDescriptionInput$O((n+m) * 16^{m})$$O(n+m)$...
4TwoDescriptionInput$O((n+m) * 16^{m})$$O(n+m)$...
8OneDescriptionInput$O(n*m)$$O(1)$...
8TwoDescriptionInput$O(n*m)$$O(1)$...
9OneDescriptionInput$O(n^3)$$O(n)$DFS
9TwoDescriptionInput$O(n^3)$$O(n)$DFS
10OneDescriptionInput$O(2^n)$$O(2^n)$...
10TwoDescriptionInput$O(2^n)$$O(2^n)$...
12OneDescriptionInput$O(n*m)$$O(n*m)$...
12TwoDescriptionInput$O(n*m)$$O(n*m)$...
13OneDescriptionInput$O(n!)$$O(n^2)$Salesman problem
13TwoDescriptionInput$O(n!)$$O(n^2)$Salesman problem

Usage

Setup

The application infrastructure code is cross-platform, so it works on Linux, macOS and Windows. To use it, make sure you have Python version 3.12 or newer or Docker and Docker Compose version 2 installed on your machine and clone the repository:

git clone https://github.com/Kyrylo-Ktl/advent-of-code

Move to project directory:

cd advent-of-code

Local usage

Install the required dependencies for local run:

pip install -r infrastructure/requirements.txt

Set necessary for downloading personalized inputs Advent of Code session cookie as environment variable:

export SESSION=<your-session-cookie>

[!NOTE] The SESSION is Advent of Code session cookie. It's possible to get it by search in browser console after pressing F12 and going into the Network tab in browser. To do this it's necessary to be logged in to the site.

Docker usage

To run application in container, it's necessary to create and populate .env file before launching. It's possible to use .env.example file to do this:

SESSION=<your-session-cookie>

YEAR=2024
DAY=1
PART=1

GID=0
UID=0

The .env file consists of several mandatory environment variables:

Local Run

To download personalized task input use:

python -m infrastructure.commands.downloader --year=2024 --day=1

To run task solution use:

python -m infrastructure.commands.runner --year=2024 --day=1 --part=1

To validate all tasks solutions:

python -m infrastructure.commands.validator --execute

Run in Docker

To download personalized task input use:

docker compose up advent-of-code-downloader --build

To run task solution use:

docker compose up advent-of-code-runner --build

To validate all tasks solutions:

docker compose up advent-of-code-validator --build

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

License

This project is licensed under the MIT License - see the license file for details.

Happy adventure! ⭐