@@ -2,3 +2,4 @@ | |||
__pycache__/ | |||
.DS_Store | |||
venv/ | |||
.env |
@@ -1,12 +1,15 @@ | |||
include .env | |||
FILE = $(shell find . -path "./y????/p??.py" -type f | xargs ls -rt | tail -n 1) | |||
DATA = $(shell echo $(FILE) | sed -e s/\.py/\.dat/) | |||
PYTHONPATH = . | |||
export | |||
main: venv/ | |||
@touch $(DATA) | |||
main: venv/ $(DATA) | |||
@cat $(DATA) | venv/bin/python -u $(FILE) | |||
$(DATA): | |||
@echo $(DATA) | venv/bin/python -c "import toolkit; toolkit.get_dat()" $(DATA) | |||
venv/: requirements.txt | |||
rm -rf venv/ | |||
~/.pyenv/versions/3.8.0/bin/python -m venv venv |
@@ -1,2 +1,3 @@ | |||
requests | |||
flake8 | |||
flake8-import-order |
@@ -1,4 +1,10 @@ | |||
import collections | |||
import os | |||
import re | |||
import sys | |||
from pathlib import Path | |||
import requests | |||
def render(grid, brush=None): | |||
@@ -45,3 +51,13 @@ def shortest_path(start, end, move): | |||
path.append(end) | |||
end = seen[end] | |||
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) |
@@ -0,0 +1,11 @@ | |||
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) |
@@ -0,0 +1,15 @@ | |||
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) |
@@ -0,0 +1,4 @@ | |||
import sys | |||
sys.stdin.read().splitlines() |