Roderic Day 4 vuotta sitten
vanhempi
commit
0b0dd60b81
7 muutettua tiedostoa jossa 53 lisäystä ja 2 poistoa
  1. +1
    -0
      .gitignore
  2. +5
    -2
      makefile
  3. +1
    -0
      requirements.txt
  4. +16
    -0
      toolkit.py
  5. +11
    -0
      y2015/p01.py
  6. +15
    -0
      y2020/p01.py
  7. +4
    -0
      y2020/p02.py

+ 1
- 0
.gitignore Näytä tiedosto

@@ -2,3 +2,4 @@
__pycache__/
.DS_Store
venv/
.env

+ 5
- 2
makefile Näytä tiedosto

@@ -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
- 0
requirements.txt Näytä tiedosto

@@ -1,2 +1,3 @@
requests
flake8
flake8-import-order

+ 16
- 0
toolkit.py Näytä tiedosto

@@ -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)

+ 11
- 0
y2015/p01.py Näytä tiedosto

@@ -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)

+ 15
- 0
y2020/p01.py Näytä tiedosto

@@ -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)

+ 4
- 0
y2020/p02.py Näytä tiedosto

@@ -0,0 +1,4 @@
import sys


sys.stdin.read().splitlines()

Loading…
Peruuta
Tallenna