https://github.com/tranzystorekk/aoc2019-python
Advent of Code 2019 solutions in Python
https://github.com/tranzystorekk/aoc2019-python
advent-of-code-2019 python
Last synced: 2 months ago
JSON representation
Advent of Code 2019 solutions in Python
- Host: GitHub
- URL: https://github.com/tranzystorekk/aoc2019-python
- Owner: tranzystorekk
- Created: 2019-11-17T18:51:10.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-05-15T11:49:56.000Z (over 4 years ago)
- Last Synced: 2025-03-27T00:06:29.667Z (7 months ago)
- Topics: advent-of-code-2019, python
- Language: Python
- Homepage:
- Size: 78.1 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AOC 2019 solutions
## About
This repo contains solutions to the [advent of code](https://adventofcode.com/) 2019 edition.
Now requires Python >= 3.8!
## How to use
The files under the [days](days) directory are most conveniently run as python modules:
```shell
python3 -m days.d01p1
```
The `input` directory is conveniently included to store your personal input and test files.
## [utils.parse](utils/parse.py)
This utility module provides code with a uniform way to get input,
including argument parsing.
That is, it provides an optional argument for specifying an input file.
If this argument is not specified, input is read from stdin.
```python
from utils.parse import Parser
# mimics the cat utility
parser = Parser(desc="Optional assignment description")
with parser.input as input:
stripped = (l.strip() for l in input)
print(*stripped, sep='\n')
```
## [misc.disic](misc/disic.py)
### Intcode
In this edition some tasks operate on a special Intcode language.
This module prettifies an Intcode program
by adding named operations, visual address modes and opcode positions.
### Example
For a comma-separated Intcode (wrapping added for readability):
```txt
3,52,
1001,52,-5,52,
3,53,
1,52,56,54,
1007,54,5,55,
1005,55,26,
1001,54,-5,54,
1105,1,12,
1,53,54,53,
1008,54,0,55,
1001,55,1,55,
2,53,55,53,
4,53,
1001,56,-1,56,
1005,56,6,
99,
0,
0,
0,
0,
10
```
`python3 -m misc.disic ` outputs:
```txt
00000000: INP 52
00000002: ADD 52 #-5 52
00000006: INP 53
00000008: ADD 52 56 54
00000012: TLT 54 #5 55
00000016: JNZ 55 #26
00000019: ADD 54 #-5 54
00000023: JNZ #1 #12
00000026: ADD 53 54 53
00000030: TEQ 54 #0 55
00000034: ADD 55 #1 55
00000038: MUL 53 55 53
00000042: OUT 53
00000044: ADD 56 #-1 56
00000048: JNZ 56 #6
00000051: HLT
00000052: ??? (0)
00000053: ??? (0)
00000054: ??? (0)
00000055: ??? (0)
00000056: ??? (10)
```