Browse Source

y2020

master
Roderic Day 4 years ago
parent
commit
0b0dd60b81
7 changed files with 53 additions and 2 deletions
  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 View File

__pycache__/ __pycache__/
.DS_Store .DS_Store
venv/ venv/
.env

+ 5
- 2
makefile View File

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

+ 1
- 0
requirements.txt View File

requests
flake8 flake8
flake8-import-order flake8-import-order

+ 16
- 0
toolkit.py View File

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)

+ 11
- 0
y2015/p01.py View File

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 View File

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 View File

import sys


sys.stdin.read().splitlines()

Loading…
Cancel
Save