Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kalaspuff/advent-of-code
🎅 My solutions to some of the "Advent of Code" programming puzzles.
https://github.com/kalaspuff/advent-of-code
advent-of-code puzzle-solution python
Last synced: about 2 months ago
JSON representation
🎅 My solutions to some of the "Advent of Code" programming puzzles.
- Host: GitHub
- URL: https://github.com/kalaspuff/advent-of-code
- Owner: kalaspuff
- License: mit
- Created: 2020-12-06T13:13:04.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-01-06T15:34:01.000Z (12 months ago)
- Last Synced: 2024-05-01T22:09:22.011Z (8 months ago)
- Topics: advent-of-code, puzzle-solution, python
- Language: Python
- Homepage:
- Size: 705 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# `kalaspuff/advent-of-code`
*My solutions to some of the [Advent of Code](https://adventofcode.com/) programming puzzles.*
👆🧝💻 A custom shell for the device given by the Elves during [2022 - day 7](https://adventofcode.com/2022/day/7).
#### Writing solutions
Solutions go in the `yearYYYY/dayXX/part1.py` and `yearYYYY/dayXX/part2.py` files. The puzzle input goes into `yearYYYY/dayXX/input`. Additional example puzzle input could be put in the same folder with any arbitrary file name (`example` is a good name if there's only one type of example input).
The Python files `part1.py` and `part2.py` should have a function called `run` defined that will be called. The import `from values import values` is recommended to get easy access to the puzzle input.
Here's an example solution for the puzzle from [year 2020, day 3, part 2](https://adventofcode.com/2022/day/13).
```python
import functools
import operator
from typing import Listfrom values import values
def cmp(*args: List) -> int:
return functools.reduce(
lambda a, b: a or b,
[
cmp(*map(lambda v: [v, [v]][isinstance(v, int)], pair))
if list in map(type, pair)
else cmp(*map(lambda i: [[]] * i, pair))
for pair in zip(*args)
]
+ [0],
) or max(min(1, operator.sub(*map(len, args))), -1)async def run() -> int:
divider1 = [[2]]
divider2 = [[6]]rows = [eval(row) for row in values.rows if row] + [divider1, divider2]
sorted_rows = [[]] + sorted(rows, key=functools.cmp_to_key(cmp))
return (sorted_rows.index(divider1)) * (sorted_rows.index(divider2))# [values.year] (number) 2022
# [values.day] (number) 13
# [values.part] (number) 2
# [values.input_filename] (str) ./year2022/day13/input
#
# Result: 19570
```#### Running solutions
```
$ python aoc.py [puzzle input filename]
```If no puzzle input filename is specified, the default `input` file for the puzzle's day will be used as the puzzle input.
Example – to run the solution from the example above (year 2022, day 13, part 2).
```bash
$ python aoc.py 2022 13 2# [values.year] (number) 2022
# [values.day] (number) 13
# [values.part] (number) 2
# [values.input_filename] (str) ./year2022/day13/input
#
# Result: 19570
```