Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

39 lines
1.1KB

  1. include .env
  2. export
  3. .SILENT:
  4. FILE := $(shell find . -path "./y????/p??.*" -type f | xargs ls -rt | tail -n 1)
  5. YEAR := $(shell echo ${FILE} | sed -E 's/.+y([0-9]+).+/\1/')
  6. DAY := $(shell echo ${FILE} | sed -E 's/.+p([0-9]+).+/\1/' | bc)
  7. URL := https://adventofcode.com/${YEAR}/day/${DAY}
  8. BASE := $(shell echo ${FILE} | sed -E 's/\....?$$//')
  9. CODE := $(BASE).py
  10. DATA := $(BASE).dat
  11. TEST := $(BASE).dtt
  12. main: ${TEST}
  13. echo 'test':
  14. cat ${TEST} | docker compose run --rm advent python -u ${CODE}
  15. clean: ${DATA}
  16. echo 'real:'
  17. cat ${DATA} | docker compose run --rm advent python -u ${CODE}
  18. save:
  19. git add .
  20. test `git log -1 --format=%s` == `cat VERSION` \
  21. && git commit --amend --reuse-message=head \
  22. || git commit -m `cat VERSION`
  23. ${DATA} ${TEST}:
  24. # avoid spam in the lead up to the event
  25. test ${DAY} -le `date +%d` || test ${YEAR} -lt `date +%Y`
  26. # only poll if data isn't yet stored locally
  27. test -f ${DATA} || curl -s -b "session=${SESSION}" ${URL}/input > ${DATA}
  28. # try to get test data
  29. test -f ${TEST} || curl -s ${URL} | tr '\n' '@' | perl -pe 's|.+?<pre><code>(.+?)</code></pre>.+|\1|' | tr '@' '\n' > ${TEST}