Roderic Day před 2 roky
rodič
revize
a76f7b4feb
4 změnil soubory, kde provedl 12 přidání a 35 odebrání
  1. +9
    -17
      makefile
  2. +0
    -17
      toolkit.py
  3. +3
    -1
      y2015/p01.py
  4. +0
    -0
      y2022/p01.py

+ 9
- 17
makefile Zobrazit soubor

@@ -1,21 +1,13 @@
include .env
FILE = $(shell find . -path "./y????/p??.py" -type f | xargs ls -rt | tail -n 1)
DATA = $(shell echo $(FILE) | sed s/.py/.dat/)
PYTHONPATH = .
export

main: venv/
@venv/bin/python -u toolkit.py $(FILE)
@cat $(DATA) | venv/bin/python -u $(FILE)
PYTHONPATH := .
FILE := $(shell find . -path "./y????/p??.py" -type f | xargs ls -rt | tail -n 1)
YEAR := $(shell echo ${FILE} | sed 's/[^0-9]/ /g' | cut -d' ' -f4)
DAY := $(shell echo ${FILE} | sed 's/[^0-9]/ /g' | cut -d' ' -f6 | bc)
URL := https://adventofcode.com/${YEAR}/day/${DAY}/input
DATA := $(shell echo ${FILE} | sed s/.py/.dat/)

flake: venv/
venv/bin/flake8 --exclude=venv/

venv/: requirements.txt
rm -rf venv/
~/.pyenv/versions/3.8.0/bin/python -m venv venv
venv/bin/pip install -r requirements.txt
touch requirements.txt venv/
# install flake8 git hook
# echo 'venv/bin/flake8 --exclude=venv/' > .git/hooks/pre-commit
# chmod +x .git/hooks/pre-commit
main:
@test -f ${DATA} || curl -s -b "session=${SESSION}" ${URL} > ${DATA}
@cat $(DATA) | python3 -u $(FILE)

+ 0
- 17
toolkit.py Zobrazit soubor

@@ -12,8 +12,6 @@ import string
import sys
from pathlib import Path

import requests


product = functools.partial(functools.reduce, operator.mul)

@@ -68,16 +66,6 @@ def shortest_path(start, end, move):
return path[::-1]


def ensure_data(path):
if not path.exists():
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.write_bytes(response.content)


def batch(iterable, size):
count = itertools.count()
for _, sub in itertools.groupby(iterable, lambda _: next(count) // size):
@@ -101,8 +89,3 @@ def loop_consume(lines, handler):
count += 1
else:
raise RuntimeError('Reached steady state')


if __name__ == '__main__':
data_file = Path(sys.argv[1]).with_suffix('.dat')
ensure_data(data_file)

+ 3
- 1
y2015/p01.py Zobrazit soubor

@@ -1,6 +1,8 @@
ans1 = 0
ans2 = None
for i, char in enumerate(data_file.read_text(), 1):
for i, char in enumerate(open(0).read(), 1):
ans1 += {'(': 1, ')': -1}[char]
if ans1 == -1 and ans2 is None:
ans2 = i
print(ans1)
print(ans2)

+ 0
- 0
y2022/p01.py Zobrazit soubor


Načítá se…
Zrušit
Uložit