An open API service indexing awesome lists of open source software.

https://github.com/cak/advent-of-code

Python solutions for Advent of Code challenges, organized by year.
https://github.com/cak/advent-of-code

Last synced: 4 months ago
JSON representation

Python solutions for Advent of Code challenges, organized by year.

Awesome Lists containing this project

README

          

# ๐ŸŽ„ Advent of Code ๐ŸŽ„

Welcome to my festive repository, where code meets Christmas cheer! This collection holds my solutions for the [Advent of Code](https://adventofcode.com/) puzzles across multiple years. Join me as we unwrap new challenges each day of December, guided by the merry elves and sprinkled with holiday magic! โœจ

## ๐Ÿ“… Advent of Code 2024 Progress (Goal: 20 Stars โญโญโญโญโญโญโญโญโญโญโญโญโญโญโญโญ)

### โญ Progress: 4/50 โญ

| Day | Stars | Solution |
| ------------------------------------------ | ----- | ---------------------------------------------------------------------------------- |
| [01](https://adventofcode.com/2024/day/1) | โญโญ | [Solution](https://github.com/cak/advent-of-code/blob/main/2024/day01/solution.py) |
| [02](https://adventofcode.com/2024/day/2) | โญโญ | [Solution](https://github.com/cak/advent-of-code/blob/main/2024/day02/solution.py) |
| [03](https://adventofcode.com/2024/day/3) | | |
| [04](https://adventofcode.com/2024/day/4) | | |
| [05](https://adventofcode.com/2024/day/5) | | |
| [06](https://adventofcode.com/2024/day/6) | | |
| [07](https://adventofcode.com/2024/day/7) | | |
| [08](https://adventofcode.com/2024/day/8) | | |
| [09](https://adventofcode.com/2024/day/9) | | |
| [10](https://adventofcode.com/2024/day/10) | | |
| [11](https://adventofcode.com/2024/day/11) | | |
| [12](https://adventofcode.com/2024/day/12) | | |
| [13](https://adventofcode.com/2024/day/13) | | |
| [14](https://adventofcode.com/2024/day/14) | | |
| [15](https://adventofcode.com/2024/day/15) | | |
| [16](https://adventofcode.com/2024/day/16) | | |
| [17](https://adventofcode.com/2024/day/17) | | |
| [18](https://adventofcode.com/2024/day/18) | | |
| [19](https://adventofcode.com/2024/day/19) | | |
| [20](https://adventofcode.com/2024/day/20) | | |
| [21](https://adventofcode.com/2024/day/21) | | |
| [22](https://adventofcode.com/2024/day/22) | | |
| [23](https://adventofcode.com/2024/day/23) | | |
| [24](https://adventofcode.com/2024/day/24) | | |
| [25](https://adventofcode.com/2024/day/25) | | |

---

### ๐ŸŽฏ Goal Tracker: Earn 20 Stars

| Milestone | Stars Earned | Status |
| --------------- | ------------ | -------------- |
| 1-10 Stars | 4/10 | ๐ŸŸฉ On Track |
| 11-20 Stars | 0/10 | ๐ŸŸฆ Not Started |
| Full Completion | 4/50 | โฌœ |

## ๐ŸŽ„ Folder Structure

Our repository is structured like a well-organized Christmas workshop! Each year contains folders for individual days, and the `elf` package houses utilities for puzzle-solving and automation:

```bash
advent-of-code/
โ”œโ”€โ”€ 2016/
โ”‚ โ”œโ”€โ”€ day01/
โ”‚ โ”œโ”€โ”€ solution.py # ๐ŸŽ Your main solution script for the day
โ”‚ โ”œโ”€โ”€ input.txt # ๐Ÿ“œ The puzzle input for the day
โ”‚ โ”œโ”€โ”€ test_input.txt # ๐Ÿงช Example input for testing your solution
โ”‚ โ”œโ”€โ”€ expected_output.txt # โœ… The expected output for test input
โ”œโ”€โ”€ elf/ # ๐Ÿงโ€โ™‚๏ธ The elves' magical helpers!
โ”‚ โ”œโ”€โ”€ cli/ # ๐ŸŽ… Command-line interface for automation
โ”‚ โ”œโ”€โ”€ create_day.py # ๐Ÿ—๏ธ Script to create new day folders
โ”‚ โ”œโ”€โ”€ fetch_input.py # ๐Ÿ”„ Script to fetch puzzle inputs
โ”‚ โ”œโ”€โ”€ run.py # ๐Ÿš€ Script to run a day's solution
โ”‚ โ”œโ”€โ”€ submit.py # ๐ŸŽฏ Script to submit answers to Advent of Code
โ”‚ โ”œโ”€โ”€ test.py # ๐Ÿงช Script to test solutions for correctness
โ”‚ โ”œโ”€โ”€ templates/ # โœจ Templates for new solution files
โ”‚ โ”œโ”€โ”€ args.py # โš™๏ธ Argument parsing template for solutions
โ”‚ โ”œโ”€โ”€ solution_template.py # ๐Ÿ“ Template for daily solution scripts
โ”‚ โ”œโ”€โ”€ utils.py # ๐Ÿงฐ General utility functions for helpers
โ”‚ โ”œโ”€โ”€ input.py # ๐Ÿ”„ Functions to fetch and cache puzzle inputs
โ”‚ โ”œโ”€โ”€ config.py # โš™๏ธ Configuration settings for the project
โ”‚ โ”œโ”€โ”€ testing.py # ๐Ÿงช Tools for testing solutions
โ”‚ โ”œโ”€โ”€ answer.py # ๐ŸŽฏ Helpers for answer validation and submission
โ”‚ โ””โ”€โ”€ exceptions.py # ๐Ÿšจ Custom exception handling for the CLI
โ”œโ”€โ”€ README.md # ๐Ÿ“– Documentation (you're here!)
โ”œโ”€โ”€ LICENSE # ๐Ÿ“œ Open source license
โ”œโ”€โ”€ pyproject.toml # ๐Ÿ“ฆ Project dependencies and settings
โ”œโ”€โ”€ uv.lock # ๐Ÿ”’ Dependency lockfile
```

## ๐Ÿ› ๏ธ Automating Tasks with the Elf CLI

The `elf` CLI is your all-in-one tool to manage Advent of Code puzzles. From creating folders to running tests, it makes solving puzzles joyful!

### Installing Dependencies

Before you start, install the required dependencies:

```bash
pip install -r requirements.txt
```

### Commands Overview

Run the CLI by executing:

```bash
python -m elf.cli.main [options]
```

Available commands:

- **`create-day`**: Create a new folder for a specific day.
- **`fetch-input`**: Fetch puzzle input for a specific day.
- **`run`**: Run the solution for a specific day and part.
- **`test`**: Test the solution using provided test inputs.
- **`submit`**: Submit your solution to Advent of Code.

### Command Details

#### 1. Create a New Day Folder

Set up a new folder for a day, complete with templates and input files:

```bash
python -m elf.cli.main create-day --output-dir
```

Example:

```bash
python -m elf.cli.main create-day 2016 5
```

#### 2. Fetch Puzzle Input

Fetch your personalized input for a day:

```bash
python -m elf.cli.main fetch-input
```

Example:

```bash
python -m elf.cli.main fetch-input 2016 5
```

#### 3. Run a Solution

Run your solution for a specific day and part:

```bash
python -m elf.cli.main run --part <1|2|both>
```

Examples:

```bash
python -m elf.cli.main run 2016 4 --part 1
python -m elf.cli.main run 2016 4 --part both
```

#### 4. Test Your Solution

Run tests using `test_input.txt` and `expected_output.txt`:

```bash
python -m elf.cli.main test
```

Example:

```bash
python -m elf.cli.main test 2016 4
```

#### 5. Submit Your Answer

Submit your solution directly to Advent of Code:

```bash
python -m elf.cli.main submit
```

Example:

```bash
python -m elf.cli.main submit 2016 4 1 12345
```

### Setting Up Your Session Token

To fetch inputs and submit answers, you'll need your Advent of Code session token:

1. Log in to [Advent of Code](https://adventofcode.com/) and copy your session token from the browser cookies.
2. Save it as an environment variable:
```bash
export AOC_SESSION_COOKIE='your_session_token_here'
```

**Note**: Keep your token secret to prevent unauthorized access.

## โœจ Features of the `elf` Package

The `elf` package simplifies common tasks:

- **Input Handling**: Automatically fetch and cache puzzle inputs.
- **Testing Utilities**: Compare your output with expected results.
- **Template Management**: Quickly create new solution files.
- **Error Handling**: Gracefully manage exceptions.

Example usage in a solution:

```python
from elf import input, utils

def part1(data):
return sum(map(int, data.split()))

if __name__ == "__main__":
data = input.read_input_file("input.txt")
print("Part 1:", part1(data))
```

---

**May your Advent of Code journey be merry and bright! Happy coding! ๐ŸŽ…**