| __pycache__/ | __pycache__/ | ||||
| .DS_Store | .DS_Store | ||||
| venv/ | venv/ | ||||
| .env |
| include .env | |||||
| FILE = $(shell find . -path "./y????/p??.py" -type f | xargs ls -rt | tail -n 1) | FILE = $(shell find . -path "./y????/p??.py" -type f | xargs ls -rt | tail -n 1) | ||||
| DATA = $(shell echo $(FILE) | sed -e s/\.py/\.dat/) | DATA = $(shell echo $(FILE) | sed -e s/\.py/\.dat/) | ||||
| PYTHONPATH = . | PYTHONPATH = . | ||||
| export | export | ||||
| main: venv/ | |||||
| @touch $(DATA) | |||||
| main: venv/ $(DATA) | |||||
| @cat $(DATA) | venv/bin/python -u $(FILE) | @cat $(DATA) | venv/bin/python -u $(FILE) | ||||
| $(DATA): | |||||
| @echo $(DATA) | venv/bin/python -c "import toolkit; toolkit.get_dat()" $(DATA) | |||||
| venv/: requirements.txt | venv/: requirements.txt | ||||
| rm -rf venv/ | rm -rf venv/ | ||||
| ~/.pyenv/versions/3.8.0/bin/python -m venv venv | ~/.pyenv/versions/3.8.0/bin/python -m venv venv |
| requests | |||||
| flake8 | flake8 | ||||
| flake8-import-order | flake8-import-order |
| import collections | import collections | ||||
| import os | |||||
| import re | |||||
| import sys | |||||
| from pathlib import Path | |||||
| import requests | |||||
| def render(grid, brush=None): | def render(grid, brush=None): | ||||
| path.append(end) | path.append(end) | ||||
| end = seen[end] | end = seen[end] | ||||
| return path[::-1] | return path[::-1] | ||||
| def get_dat(): | |||||
| path = sys.argv[1] | |||||
| year, qn = map(int, re.findall(r'\d+', sys.argv[1])) | |||||
| url = f'https://adventofcode.com/{year}/day/{qn}/input' | |||||
| cookies = {'session': os.environ['SESSION']} | |||||
| response = requests.get(url, cookies=cookies) | |||||
| response.raise_for_status() | |||||
| Path(path).write_bytes(response.content) |
| import sys | |||||
| ans1 = 0 | |||||
| ans2 = None | |||||
| for i, char in enumerate(sys.stdin.read(), 1): | |||||
| ans1 += {'(': 1, ')': -1}[char] | |||||
| if ans1 == -1 and ans2 is None: | |||||
| ans2 = i | |||||
| print(ans1) | |||||
| print(ans2) |
| import sys | |||||
| from itertools import combinations | |||||
| ns = [int(n) for n in sys.stdin.read().splitlines()] | |||||
| for a, b in combinations(ns, 2): | |||||
| if a + b == 2020: | |||||
| print(a * b) | |||||
| for a, b, c in combinations(ns, 3): | |||||
| if a + b + c == 2020: | |||||
| print(a * b * c) |
| import sys | |||||
| sys.stdin.read().splitlines() |