Skip to content

Advent of Code solutions in Python as well as a tool to manage inputs and solutions infrastructure

License

Notifications You must be signed in to change notification settings

Kyrylo-Ktl/advent-of-code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
    • Solutions for year 2024 with 14/25 days solved;
    • Solutions for year 2023 with 2/25 days solved;
    • Solutions for year 2022 with 1/25 days solved;
    • Solutions for year 2021 with 2/25 days solved;
    • Solutions for year 2020 with 1/25 days solved;
    • Solutions for year 2019 with 1/25 days solved;
    • Solutions for year 2018 with 1/25 days solved;
    • Solutions for year 2017 with 1/25 days solved;
    • Solutions for year 2016 with 1/25 days solved;
    • Solutions for year 2015 with 7/25 days solved;
  • Usage
    • Project setup for personal usage;
    • Local run of project tools;
    • Docker run of project tools;

Solutions

Year 2024

Day Part Task description Task input Solution Time Complexity Space Complexity Notes
1 One Description Input $O(n*\log_2{n} + m*\log_2{m})$ $O(n+m)$ ...
1 Two Description Input $O(n+m)$ $O(1)$ ...
2 One Description Input $O(n*m)$ $O(1)$ ...
2 Two Description Input $O(n*m^2)$ $O(m)$ ...
3 One Description Input $O(n*m)$ $O(k)$ ...
3 Two Description Input $O(n*m)$ $O(1)$ ...
4 One Description Input $O((n+m)*(n+m)*k)$ $O(n*m)$ ...
4 Two Description Input $O(n * m * k)$ $O(k)$ ...
5 One Description Input $-$ $-$ Topological sort
5 Two Description Input $-$ $-$ Topological sort
6 One Description Input $O(n*m)$ $O(n*m)$ ...
6 Two Description Input $O(n^2*m^2)$ $O(n*m)$ ...
7 One Description Input $O(n*k^m)$ $O(1)$ Backtracking
7 Two Description Input $O(n*k^m)$ $O(m)$ Backtracking
8 One Description Input $O(n^2*m^2)$ $O(n*m)$ Linear Algebra
8 Two Description Input $O(n^2 * m^2 * max(n,m))$ $O(n*m)$ Linear Algebra
9 One Description Input $O(n*m)$ $O(n*m)$ ...
9 Two Description Input $O(n^2*m^2)$ $O(n*m)$ ...
10 One Description Input $O(n * m * k^{2})$ $O(k)$ DFS
10 Two Description Input $O(n*m)$ $O(n*m)$ DFS
11 One Description Input $O(n * 2^{m})$ $O(n * 2^{m})$ DP,Memoization
11 Two Description Input $O(n * 2^{m})$ $O(n * 2^{m})$ DP,Memoization
12 One Description Input $O(n * m)$ $O(n * m)$ DFS
12 Two Description Input $O(n * m * min(n,m))$ $O(n * m)$ BFS
13 One Description Input $O(n)$ $O(1)$ Algebra
13 Two Description Input $O(n)$ $O(1)$ Algebra
14 One Description Input $O(n)$ $O(1)$ ...
14 Two Description Input $O(∞)$ $O(n)$ ...

Year 2023

Day Part Task description Task input Solution Time Complexity Space Complexity Notes
1 One Description Input $O(n*m)$ $O(1)$
1 Two Description Input $O(n*m^2)$ $O(m)$
2 One Description Input $O(n*m)$ $O(1)$
2 Two Description Input $O(n*m)$ $O(1)$

Year 2022

Day Part Task description Task input Solution Time Complexity Space Complexity Notes
1 One Description Input $O(n*m)$ $O(1)$
1 Two Description Input $O(n*m)$ $O(1)$

Year 2021

Day Part Task description Task input Solution Time Complexity Space Complexity Notes
1 One Description Input $O(n)$ $O(1)$ ...
1 Two Description Input $O(n)$ $O(1)$ ...
2 One Description Input $O(n)$ $O(1)$ ...
2 Two Description Input $O(n)$ $O(1)$ ...

Year 2020

Day Part Task description Task input Solution Time Complexity Space Complexity Notes
1 One Description Input $O(n)$ $O(n)$
1 Two Description Input $O(n^2)$ $O(1)$

Year 2019

Day Part Task description Task input Solution Time Complexity Space Complexity Notes
1 One Description Input $O(n)$ $O(1)$
1 Two Description Input $O(n*log_{3}(m))$ $O(1)$

Year 2018

Day Part Task description Task input Solution Time Complexity Space Complexity Notes
1 One Description Input $O(n)$ $O(1)$
1 Two Description Input $O(n)$ $O(n)$

Year 2017

Day Part Task description Task input Solution Time Complexity Space Complexity Notes
1 One Description Input $O(n)$ $O(1)$
1 Two Description Input $O(n)$ $O(n)$
2 One Description Input $O(n*m)$ $O(1)$
2 Two Description Input $O(n*m^2)$ $O(1)$

Year 2016

Day Part Task description Task input Solution Time Complexity Space Complexity Notes
1 One Description Input $O(n)$ $O(1)$
1 Two Description Input $O(n*m)$ $O(n*m)$

Year 2015

Day Part Task description Task input Solution Time Complexity Space Complexity Notes
1 One Description Input $O(n)$ $O(1)$ ...
1 Two Description Input $O(n)$ $O(1)$ ...
4 One Description Input $O((n+m) * 16^{m})$ $O(n+m)$ ...
4 Two Description Input $O((n+m) * 16^{m})$ $O(n+m)$ ...
8 One Description Input $O(n*m)$ $O(1)$ ...
8 Two Description Input $O(n*m)$ $O(1)$ ...
9 One Description Input $O(n^3)$ $O(n)$ DFS
9 Two Description Input $O(n^3)$ $O(n)$ DFS
10 One Description Input $O(2^n)$ $O(2^n)$ ...
10 Two Description Input $O(2^n)$ $O(2^n)$ ...
12 One Description Input $O(n*m)$ $O(n*m)$ ...
12 Two Description Input $O(n*m)$ $O(n*m)$ ...
13 One Description Input $O(n!)$ $O(n^2)$ Salesman problem
13 Two Description Input $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:

  • SESSION - Advent of Code session cookie;

  • YEAR - task year for running commands;

  • DAY - task day for running commands;

  • PART - task part for running commands;

  • UID - in Linux a UID (User Identifier) is a unique number assigned to each user on a system. It identifies the user for system processes, permissions, and ownership of files or directories. The root user by default has an UID equal to 0, in case the application is run under a different user account it's possible to check current UID using the following command:

    id --user ${whoami}

    More about UID.

  • GID - In Linux, a GID (Group Identifier) is a unique number assigned to each group on the system. It is used to define the ownership of files, directories, and processes at the group level. The root user by default has an GID equal to 0, in case the application is run under a different user account it's possible to check current GID using the following command:

    id --group ${whoami}

    More about GID.

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! ⭐