Browse Source

😅

master
Roderic Day 2 years ago
parent
commit
ea407c2562
3 changed files with 16 additions and 7 deletions
  1. +13
    -7
      makefile
  2. +3
    -0
      y2022/p01.py
  3. +0
    -0
      y2022/p02.py

+ 13
- 7
makefile View File

@@ -1,13 +1,19 @@
include .env
export

.SILENT:

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/)
CODE := $(shell find . -path "./y????/p??.py" -type f | xargs ls -rt | tail -n 1)
DATA := $(shell echo ${CODE} | sed s/.py/.dat/)
YEAR := $(shell echo ${CODE} | sed 's/[^0-9]/ /g' | cut -d' ' -f4)
DAY := $(shell echo ${CODE} | sed 's/[^0-9]/ /g' | cut -d' ' -f6)
URL := https://adventofcode.com/${YEAR}/day/`echo ${DAY} | bc`/input

main:
@test -f ${DATA} || curl -s -b "session=${SESSION}" ${URL} > ${DATA}
@cat $(DATA) | python3 -u $(FILE)
# avoid spam in the lead up to the event
test ${YEAR}${DAY} -le `date +%Y%d`
# only poll if data isn't yet stored locally
test -f ${DATA} || curl -s -b "session=${SESSION}" ${URL} > ${DATA}
# have fun! (access data through `open(0)`)
cat $(DATA) | python3 -u ${CODE}

+ 3
- 0
y2022/p01.py View File

@@ -0,0 +1,3 @@
packs = [sum(map(int, block.splitlines())) for block in open(0).read().split('\n\n')]
print(max(packs))
print(sum(sorted(packs)[-3:]))

+ 0
- 0
y2022/p02.py View File


Loading…
Cancel
Save